www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2152] New: Parentheses usage inconsistency.

reply d-bugmail puremagic.com writes:

           Summary: Parentheses usage inconsistency.
           Product: D
           Version: 1.027
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: rejects-valid, spec
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: gim913 gmail.com

I'm not sure if this is a bug, and I don't know if this can be fixed.
I was playing with h3r3tic's Singleton template.
I have overloaded opIndex, and opIndexAssign in a class, and made the class
wrapped the class with singleton (it doesn't have a meaning probably any
function returning class will do the effect).

When getting value, I can skip brackets after function call, like:
foo = bar["something"];
but when setting value (calling opIndexAssign) I am forced to use
brackets around function call, otherwise I get compiler error:
bar()["something"] = foo;

Please take a look at following two testcases:


Sorry, if this issue is a duplicate.

Jun 18 2008
next sibling parent d-bugmail puremagic.com writes:

------- Comment #1 from shro8822 vandals.uidaho.edu  2008-06-18 11:53 -------
(Added to issues to make sure the code is not lost by codepad)
first example:

/* Michal 'GiM' Spadlinski
import tango.io.Stdout;

T Singleton(T)()
    static T singletonInstance;
    if (singletonInstance is null) {
        synchronized (T.classinfo) {
            if (singletonInstance is null) {
                singletonInstance = new T;
                static if (is (typeof (singletonInstance.initialize))) {
    return singletonInstance;

class Klasa
    int opIndex(char[] ind)
        Stdout ("oh hai! : ", ind).newline;
        return 666;
    int opIndexAssign(int val, char[] ind)
        Stdout ("oh hai! : ") (ind) (" = ") (val).newline;
        return 0;

alias Singleton!(Klasa) klasa;

void main()
    auto temp = klasa["blah"];
    Stdout ("in main: ") (temp).newline;
    klasa["blah"] = temp;
    //klasa()["blah"] = temp;

Line 41: Error: Singleton()["blah"] is not an lvalue

second example switches comments at line 41 & 42

oh hai! : , blah
in main: 666
oh hai! : blah = 666

Jun 18 2008
prev sibling parent d-bugmail puremagic.com writes:

Rob Jacques <sandford jhu.edu> changed:

           What    |Removed                     |Added
                 CC|                            |sandford jhu.edu

--- Comment #2 from Rob Jacques <sandford jhu.edu>  2009-08-04 05:48:49 PDT ---
This seems releated to Issue 2409. Also another use case:

void delegate(int) func();

void main() {

Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 04 2009