digitalmars.D.bugs - [Issue 14629] New: Type system breaking and wrong code bugs in
- via Digitalmars-d-bugs (63/63) May 28 2015 https://issues.dlang.org/show_bug.cgi?id=14629
https://issues.dlang.org/show_bug.cgi?id=14629 Issue ID: 14629 Summary: Type system breaking and wrong code bugs in casting reference types to typeof(null) Product: D Version: D2 Hardware: All OS: All Status: NEW Keywords: accepts-invalid, diagnostic Severity: normal Priority: P1 Component: DMD Assignee: nobody puremagic.com Reporter: k.hara.pg gmail.com 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. --
May 28 2015