Bug 14629 – Type system breaking and wrong code bugs in casting reference types to typeof(null)

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2015-05-29T03:33:00Z
Last change time
2015-06-17T21:05:29Z
Keywords
accepts-invalid, diagnostic, pull
Assigned to
nobody
Creator
k.hara.pg

Comments

Comment #0 by k.hara.pg — 2015-05-29T03:33:18Z
A cast from non-nullable reference to typeof(null) should be disallowed in type system. extern(C) int printf(const char*, ...); void main()//test14093() { // reference types class C {} C c; alias P = int*; P p; alias N = typeof(null); N n; alias DA = int[]; DA da; alias AA = int[int]; AA aa; alias FP = int function(); FP fp; alias DG = int delegate(); DG dg; c = new C(); n = cast(N)c; // problematic cast printf("c = %p\n", c); printf("n = %p\n", n); assert(n is null); // fails, wrong p = new int(1); n = cast(N)p; // problematic cast printf("p = %p\n", p); printf("n = %p\n", n); assert(n is null); // fails, wrong //da = [1,2,3]; //n = cast(N)da; // e2ir: cannot cast da of type int[] to type typeof(null) //printf("da = %p\n", da.ptr); //printf("n = %p\n", n); //assert(n is null); aa = [1:2, 3:4]; n = cast(N)aa; // problematic cast printf("aa = %p\n", aa); printf("n = %p\n", n); assert(n is null); // fails, wrong fp = () => 1; n = cast(N)fp; // problematic cast printf("fp = %p\n", fp); printf("n = %p\n", n); assert(n is null); // fails, wrong //dg = () => 1; //n = cast(N)dg; // e2ir: cannot cast dg of type int delegate() to type typeof(null) //printf("dg = %p\n", dg); //printf("n = %p\n", n); //assert(n is null); } Also, the "e2ir: ..." error messages should be improved.
Comment #1 by k.hara.pg — 2015-05-30T13:53:15Z
Comment #2 by github-bugzilla — 2015-05-31T17:56:44Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/aefeb3fb7e1b4ba36ca7afc788a74109190e9711 fix Issue 14629 - Type system breaking and wrong code bugs in casting reference types to typeof(null)
Comment #3 by github-bugzilla — 2015-06-17T21:05:29Z
Commit pushed to stable at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/aefeb3fb7e1b4ba36ca7afc788a74109190e9711 fix Issue 14629 - Type system breaking and wrong code bugs in casting reference types to typeof(null)