Thread overview
[Issue 9040] Assertion `precedence[e->op] != PREC_zero' failed instantiating anonymous class at compile time
Nov 22, 2013
Kenji Hara
Nov 22, 2013
Andrej Mitrovic
Nov 22, 2013
yebblies
Nov 22, 2013
Andrej Mitrovic
Nov 22, 2013
yebblies
November 22, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=9040


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
         Resolution|                            |WORKSFORME


--- Comment #7 from Kenji Hara <k.hara.pg@gmail.com> 2013-11-21 22:42:18 PST ---
(In reply to comment #6)
> (In reply to comment #5)
> I do not longer observe the compiler failure. In v2.063.2, I am hitting Issue
> 11126 instead when running:
> -----
> class BaseClass {}
> 
> void main()
> {
>     static BaseClass staticAnonInstance = new class BaseClass {};
> }
> -----

From 2.064, the code prints following error.

test.d(5): Error: variable test.main.staticAnonInstance is mutable. Only const or immutable class thread local variable are allowed, not test.BaseClass

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 22, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=9040



--- Comment #8 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-11-22 00:47:11 PST ---
(In reply to comment #7)
> test.d(5): Error: variable test.main.staticAnonInstance is mutable. Only const or immutable class thread local variable are allowed, not test.BaseClass

Btw, can we do something about this diagnostic? It makes absolutely no sense at all. Here's a mutable class thread-local variable:

auto a = new Class();

So the diagnostic makes no sense..

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 22, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=9040


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies@gmail.com


--- Comment #9 from yebblies <yebblies@gmail.com> 2013-11-22 23:47:07 EST ---
(In reply to comment #8)
> (In reply to comment #7)
> > test.d(5): Error: variable test.main.staticAnonInstance is mutable. Only const or immutable class thread local variable are allowed, not test.BaseClass
> 
> Btw, can we do something about this diagnostic? It makes absolutely no sense at all. Here's a mutable class thread-local variable:
> 
> auto a = new Class();
> 
> So the diagnostic makes no sense..

class Class {}
auto a = new Class();

testx.d(136): Error: variable testx.a is mutable. Only const or immutable class thread local variable are allowed, not testx.Class

Why doesn't it make sense?

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 22, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=9040



--- Comment #10 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2013-11-22 05:15:35 PST ---
(In reply to comment #9)
> (In reply to comment #8)
> > (In reply to comment #7)
> > > test.d(5): Error: variable test.main.staticAnonInstance is mutable. Only const or immutable class thread local variable are allowed, not test.BaseClass
> > 
> > Btw, can we do something about this diagnostic? It makes absolutely no sense at all. Here's a mutable class thread-local variable:
> > 
> > auto a = new Class();
> > 
> > So the diagnostic makes no sense..
> 
> class Class {}
> auto a = new Class();
> 
> testx.d(136): Error: variable testx.a is mutable. Only const or immutable class thread local variable are allowed, not testx.Class
> 
> Why doesn't it make sense?

I thought this had something to do with not allowing 'new'ing a class at compile-time. I don't quite understand where the limitation for TLS specifically came from, e.g.:

-----
class Class { }
static tls = new Class();  // NG
__gshared glob = new Class();  // ok

void main() { }
-----

Why is one allowed but not the other? And is this documented somewhere?

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
November 22, 2013
https://d.puremagic.com/issues/show_bug.cgi?id=9040



--- Comment #11 from yebblies <yebblies@gmail.com> 2013-11-23 01:07:27 EST ---
(In reply to comment #10)
> 
> I thought this had something to do with not allowing 'new'ing a class at compile-time. I don't quite understand where the limitation for TLS specifically came from, e.g.:
> 
> -----
> class Class { }
> static tls = new Class();  // NG
> __gshared glob = new Class();  // ok
> 
> void main() { }
> -----
> 
> Why is one allowed but not the other? And is this documented somewhere?

IIRC because all threads get the same tls init data, and end up referencing the same class.  This could be fixed, but it doesn't currently work.

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