Skip to content

Commit

Permalink
Fix issue 15428 - Properly detach the temporary scope for compiles()
Browse files Browse the repository at this point in the history
  • Loading branch information
LemonBoy committed Jan 17, 2017
1 parent ece1cf5 commit d23913c
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/traits.d
Expand Up @@ -1060,6 +1060,11 @@ extern (C++) Expression semanticTraits(TraitsExp e, Scope* sc)
err = true;
}

// Carefully detach the scope from the parent and throw it away as
// we only need it to evaluate the expression
// https://issues.dlang.org/show_bug.cgi?id=15428
sc2.freeFieldinit();
sc2.enclosing = null;
sc2.pop();

if (global.endGagging(errors) || err)
Expand Down
13 changes: 13 additions & 0 deletions test/compilable/b15428.d
@@ -0,0 +1,13 @@
class A
{
this() {}
}

class B : A
{
this()
{
static if (__traits(compiles, super()))
super();
}
}
5 changes: 3 additions & 2 deletions test/fail_compilation/fail9665a.d
Expand Up @@ -150,7 +150,7 @@ struct S3
/+
TEST_OUTPUT:
---
fail_compilation/fail9665a.d(162): Error: immutable field 'v' initialized multiple times
fail_compilation/fail9665a.d(163): Error: static assert (__traits(compiles, this.v = 1)) is false
---
+/
struct S4
Expand All @@ -159,7 +159,8 @@ struct S4
this(int)
{
static assert(__traits(compiles, v = 1));
v = 1; // multiple initialization
v = 1;
static assert(__traits(compiles, v = 1)); // multiple initialization
}
}

0 comments on commit d23913c

Please sign in to comment.