-
-
Notifications
You must be signed in to change notification settings - Fork 601
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6262 from MartinNowak/fix16574
fix Issue 16574 - forward reference issue with with speculative test
- Loading branch information
Showing
2 changed files
with
41 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// https://issues.dlang.org/show_bug.cgi?id=16574 | ||
template Recursive(T) if (is(T == class)) | ||
{ | ||
// fails because T is still forward referenced | ||
// speculative determineSize must not set type to error | ||
static assert (!__traits(compiles, { new T; })); | ||
// known size of class | ||
static assert (is(typeof(T.init) == T)); | ||
|
||
alias Recursive = T; | ||
} | ||
|
||
// must be resolvable | ||
class C | ||
{ | ||
Recursive!C r; | ||
} | ||
|
||
template Recursive(T) if (is(T == struct)) | ||
{ | ||
// fails because T is still forward referenced | ||
// speculative determineSize must not set type to error | ||
static assert (!__traits(compiles, { T t; })); | ||
// no size yet for struct | ||
static assert (!is(typeof(T.init))); | ||
|
||
alias Recursive = T*; | ||
} | ||
|
||
// must be resolvable | ||
struct S | ||
{ | ||
Recursive!S r; | ||
} |