Bug 19520 – assert(TypeExp is TypeExp): compiles with empty structs
Status
RESOLVED
Resolution
FIXED
Severity
blocker
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-12-27T21:54:16Z
Last change time
2018-12-29T11:36:23Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
Iain Buclaw
Comments
Comment #0 by ibuclaw — 2018-12-27T21:54:16Z
https://github.com/dlang/dmd/pull/8945 introduced a funny little test.
---
struct Foo { alias MyInt = int; }
assert(attribs[0] is Foo); // TypeExp is TypeExp.
---
This errors in gdc's codegen, because we build the back-end expression before checking the type, but it succeeds with dmd because it checks the type and doesn't evaluate the expression as it's empty.
We can easily break dmd though...
---
struct Empty { }
struct WithSym { int i; }
void test()
{
// error: cannot interpret Empty at compile time
static assert(Empty is Empty);
// error: cannot interpret WithSym at compile time
static assert(WithSym is WithSym);
// This compiles !!!
assert(Empty is Empty);
// error: type WithSym is not an expression
assert(WithSym is WithSym);
}
---
It's quite clear that either all should succeed, or the third test should fail.
I don't think its outside the scope of CTFE to evaluate `assert(type is type)` as either true or false, so that should be addressed.
Comment #1 by ibuclaw — 2018-12-27T22:36:47Z
> I don't think its outside the scope of CTFE to evaluate `assert(type is type)` as either true or false, so that should be addressed.
Actually, I change my mind, it should be an error.
Comment #2 by github-bugzilla — 2018-12-29T11:36:23Z