Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix Issue 11169 - __traits(isAbstractClass) prematurely sets a class …
…to be abstract __traits(isAbstractClass) should resolve forward references of all class member functions, in order to return stable result.
- Loading branch information
Showing
5 changed files
with
119 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// REQUIRED_ARGS: -o- | ||
/* | ||
TEST_OUTPUT: | ||
--- | ||
1: false | ||
2: true | ||
3: true | ||
--- | ||
*/ | ||
|
||
class A | ||
{ | ||
abstract void foo(); | ||
} | ||
|
||
template MixinAbstractBar() { abstract void bar(); } | ||
|
||
class B1 : A | ||
{ | ||
// Use pragma instead of static assert, in order to evaluate | ||
// __traits during ClassDeclaration.semantic(). | ||
pragma(msg, "1: ", __traits(isAbstractClass, typeof(this))); | ||
override void foo() {} | ||
} | ||
|
||
class B2 : A | ||
{ | ||
pragma(msg, "2: ", __traits(isAbstractClass, typeof(this))); | ||
override void foo() {} | ||
abstract void bar(); | ||
} | ||
|
||
class B3 : A | ||
{ | ||
pragma(msg, "3: ", __traits(isAbstractClass, typeof(this))); | ||
override void foo() {} | ||
mixin MixinAbstractBar!(); | ||
} | ||
|
||
void main() | ||
{ | ||
static assert( __traits(compiles, { auto b = new B1(); })); | ||
static assert(!__traits(compiles, { auto b = new B2(); })); | ||
static assert(!__traits(compiles, { auto b = new B3(); })); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
TEST_OUTPUT: | ||
--- | ||
fail_compilation/fail11169.d(16): Error: error evaluating static if expression | ||
--- | ||
*/ | ||
|
||
class A | ||
{ | ||
abstract void foo(); | ||
} | ||
|
||
class B : A | ||
{ | ||
// __traits(isAbstractClass) is not usable in static if condition. | ||
static if (__traits(isAbstractClass, typeof(this))) | ||
{ | ||
} | ||
|
||
override void foo() | ||
{ | ||
} | ||
} | ||
|
||
void main() | ||
{ | ||
B b = new B(); | ||
} |