← Back to index
|
Original Bugzilla link
Bug 15623 – is(M!N) evaluates to true for M!N that fails to instantiate.
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-01-29T17:00:00Z
Last change time
2016-03-01T12:24:05Z
Keywords
accepts-invalid, pull
Assigned to
nobody
Creator
adrian
Comments
Comment #0
by adrian — 2016-01-29T17:00:24Z
struct HasFoo { void foo() {} } struct NoFoo {} struct CallsFoo(T) { T t; void bar() { t.foo(); } } static assert(is(CallsFoo!HasFoo)); static assert(is(typeof({ alias Baz = CallsFoo!HasFoo; return Baz.init; }()))); static assert(__traits(compiles, { alias Baz = CallsFoo!HasFoo; return Baz.init; }())); alias Bar = CallsFoo!HasFoo; // this should fail: static assert(is(CallsFoo!NoFoo)); // this should fail too: static assert(is(typeof({ alias Baz = CallsFoo!NoFoo; return Baz.init; }()))); // this too: static assert(__traits(compiles, { alias Baz = CallsFoo!NoFoo; return Baz.init; }())); // only this fails: //alias Baz = CallsFoo!NoFoo; // (1)
Comment #1
by acehreli — 2016-01-30T00:15:00Z
Interestingly, they all fail when moved inside a function. So, they seem to be broken only at module scope.
Comment #2
by adrian — 2016-01-30T12:27:38Z
It's not only module scope - it's broken also inside templates, e.g.: --- template canBeInstantiated(alias StructTemplate, Parameters...) { static if (is(StructTemplate!Parameters)) enum canBeInstantiated = true; else enum canBeInstantiated = false; } static assert( canBeInstantiated!(CallsFoo, HasFoo)); //static assert(!canBeInstantiated!(CallsFoo, NoFoo)); //fails --- or: --- template canBeInstantiated(alias StructTemplate, Parameters...) { enum canBeInstantiated = is(StructTemplate!Parameters); } static assert( canBeInstantiated!(CallsFoo, HasFoo)); //static assert(!canBeInstantiated!(CallsFoo, NoFoo)); //fails --- However, the function trick indeed works: --- bool canBeInstantiated(alias StructTemplate, Parameters...)() { return is(StructTemplate!Parameters); } static assert( canBeInstantiated!(CallsFoo, HasFoo)); static assert(!canBeInstantiated!(CallsFoo, NoFoo)); // hooray! ---
Comment #3
by adrian — 2016-02-21T20:51:54Z
*** Issue 15600 has been marked as a duplicate of this issue. ***
Comment #4
by k.hara.pg — 2016-02-25T15:47:03Z
https://github.com/D-Programming-Language/dmd/pull/5477
Comment #5
by github-bugzilla — 2016-03-01T12:24:05Z
Commits pushed to master at
https://github.com/D-Programming-Language/dmd
https://github.com/D-Programming-Language/dmd/commit/87c7837a859216be29400874f9528a9f36c6d2cc
fix Issue 15623 - is(M!N) evaluates to true for M!N that fails to instantiate Add a new scope flag, and check it to see whether full template instantiation is necessary.
https://github.com/D-Programming-Language/dmd/commit/f87e138bb998c19c2a1fa4ecdbc1fca63bf7051d
Merge pull request #5477 from 9rnsr/fix15623 Issue 15623 - is(M!N) evaluates to true for M!N that fails to instantiate