Bug 5890 – ICE and wrong scope problem for 2nd argument in static assert with DMD on git master

Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Mac OS X
Creation time
2011-04-26T04:18:00Z
Last change time
2011-05-05T00:03:12Z
Keywords
ice-on-valid-code, patch, rejects-valid
Assigned to
nobody
Creator
kennytm
See also
http://d.puremagic.com/issues/show_bug.cgi?id=4097

Comments

Comment #0 by kennytm — 2011-04-26T04:18:40Z
This is a problem on the git master. This does not affect 2.052. The program below causes an ICE on the git master version: ------------------------------------------------- class K { void f() { static assert(0, typeof(this).stringof); } } void main() { (new K).f; } ------------------------------------------------- $ dmd2.052/osx/bin/dmd x # correct x.d(6): Error: static assert "K"c $ dmd x # incorrect Assertion failed: (this != enclosing), function Scope, file scope.c, line 132. Abort trap ------------------------------------------------- And the program below thinks the template parameter U does not exist: ------------------------------------------------- class K { static void f(U)() { static assert(0, U.stringof); } } void main() { K.f!int(); } ------------------------------------------------- $ dmd2.052/osx/bin/dmd x # correct x.d(6): Error: static assert "int"c x.d(11): instantiated from here: f!(int) $ dmd x # incorrect x.d(6): Error: undefined identifier U x.d(6): Error: static assert __error x.d(11): instantiated from here: f!(int) -------------------------------------------------
Comment #1 by kennytm — 2011-04-26T05:02:03Z
Both problems were introduced in commit 7588ca35c5e723a8fccfbfc1db684114aa1e29aa when fixing issue 4097. (https://github.com/D-Programming-Language/dmd/commit/7588ca35c5e723a8fccfbfc1db684114aa1e29aa)
Comment #2 by kennytm — 2011-04-26T05:17:35Z
The fix should be trivial: diff --git a/src/staticassert.c b/src/staticassert.c index 67a1e48..82aad9c 100644 --- a/src/staticassert.c +++ b/src/staticassert.c @@ -57,7 +57,7 @@ void StaticAssert::semantic2(Scope *sc) sc = sc->push(sd); sc->flags |= SCOPEstaticassert; Expression *e = exp->semantic(sc); - sc->pop(); + sc = sc->pop(); if (e->op == TOKerror) return; e = e->optimize(WANTvalue | WANTinterpret);
Comment #3 by bugzilla — 2011-05-05T00:03:12Z