[Issue 671] Weird class reference declaration compiles

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sun Dec 10 17:10:02 PST 2006


http://d.puremagic.com/issues/show_bug.cgi?id=671





------- Comment #4 from maxter at i.com.ua  2006-12-10 19:09 -------
Actually, I discovered this bug while playing with dynamic struct
initialization (having opCall and opAssign with the same signature in the test
struct). I just replaced struct with class and wondered if the compiler choke.

One of the following could fix the issue:

1. Disallow the syntax (Test t = (new Test) = 20; instead?); 
2. Implicitly create a Test instance passing 20 to the ctor.
class Test
{
int a;
this(int v)
{
a = v;
}
}

Test t = 20; // creates a Test and initializes a to 20; (bad idea)

3. Call 'static Test opCall(int);' on the class and assign the returned
reference to t (similar to structs, bad idea)


-- 



More information about the Digitalmars-d-bugs mailing list