Bug 2171 – errors involving anonymous class literals expose compiler internals

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2008-06-25T09:20:55Z
Last change time
2024-12-13T17:48:35Z
Keywords
bootcamp, diagnostic
Assigned to
No Owner
Creator
david
Moved to GitHub: dmd#17737 →

Comments

Comment #0 by davidl — 2008-06-25T09:20:55Z
// $HeadURL: svn://svn.berlios.de/dstress/trunk/run/t/this_13_C.d $ // $Date: 2007-01-01 03:59:08 +0800 (Mon, 01 Jan 2007) $ // $Author: thomask $ // @author@ Frank Benoit <[email protected]> // @date@ 2006-10-09 // @uri@ http://d.puremagic.com/issues/show_bug.cgi?id=419 // @desc@ [Issue 419] New: Anonymous classes are not working. module dstress.run.t.this_13_C; interface I { void get( char[] s ); } class C{ void init(){ I i = new class(){ void get( char[] s ){ func(); } }; } void func( ){ } } int main(){ C c = new C(); c.init(); return 0; } compile result with: bug.d(18): Error: cannot implicitly convert expression ((class __anonclass1 : Object { void get(char[] s) { assert(this,"null this"); // this line is quite unreadable this.this.func(); // also this.this.func is dummy } C this; } ) , new __anonclass1) of type dstress.run.t.this_13_C.C.init.__anonclass1 to dstress.run.t.this_13_C.I
Comment #1 by clugdbug — 2012-09-27T01:27:29Z
Original title: bizzare toCBuffer result when emit error message for bad source code Applies to both D1 and D2. Reduced test case: void f() { int k = new class(){}; } ----- bug.d(3): Error: cannot implicitly convert expression (class __anonclass1 : Object { void* this; } , new __anonclass1) of type bug.f.__anonclass1 to int ----- Another example, not involving an error: void f() { pragma(msg, (new class(){ void get(char[] s){} }).stringof); } which prints invalid D code: ---------------------------------- class __anonclass1 : Object { void get(char[] s) { assert(this,"null this"); } void* this; } , new __anonclass1 ---------------------------------- When printing the expression I don't think it should be printing the class contents. Would be enough to display: bug.d(3): Error: cannot implicitly convert expression `new __anonclass1` of type bug.f.__anonclass1 to int
Comment #2 by robert.schadek — 2024-12-13T17:48:35Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17737 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB