Bug 2152 – Parentheses usage inconsistency.

Status
RESOLVED
Resolution
WORKSFORME
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2008-06-18T05:48:00Z
Last change time
2014-02-24T15:30:41Z
Keywords
rejects-valid
Assigned to
nobody
Creator
gim913
Blocks
3107

Comments

Comment #0 by gim913 — 2008-06-18T05:48:33Z
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: http://ncu.codepad.org/7pBqIx25 http://ncu.codepad.org/JjGFdmsO Sorry, if this issue is a duplicate.
Comment #1 by shro8822 — 2008-06-18T11:53:27Z
(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))) { 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; } Error: Line 41: Error: Singleton()["blah"] is not an lvalue second example switches comments at line 41 & 42 Output: oh hai! : , blah in main: 666 oh hai! : blah = 666
Comment #2 by sandford — 2009-08-04T05:48:49Z
This seems releated to Issue 2409. Also another use case: void delegate(int) func(); void main() { func(1); }
Comment #3 by bugzilla — 2012-01-21T20:53:50Z
Not a spec issue.
Comment #4 by dlang-bugzilla — 2014-02-03T14:14:35Z
After porting to D2 and adding "static" to Klasa methods (I assume that was a reduction error), problem does not manifest under 2.065 git.
Comment #5 by dlang-bugzilla — 2014-02-03T14:16:30Z
Oops, never mind about the "static" bit. Everything else stands.