This is wrong D2 code, it contains a common mistake (f is a Foo instead of the correct Foo*): struct Foo { int x; this(int x_) { this.x = x_; } } void main() { Foo f = new Foo(0); } DMD 2.050 gives the error messages that don't look correct: test.d(8): Error: constructor test3.Foo.this (int x_) is not callable using argument types (Foo*) test.d(8): Error: cannot implicitly convert expression (new Foo(0)) of type Foo* to int But I was expecting a single error message similar to: test.d(8): Error: cannot implicitly convert expression (new Foo(0)) of type Foo* to Foo
It's not a wrong diagnostic, but maybe it can be improved somehow. The issue is that after construction the compiler will attempt another construction. E.g.: ----- struct Foo { this(Foo* x_) { } this(int x_) { } } void main() { // calls two ctors Foo f = new Foo(0); } ----- Maybe this can be considered dangerous behavior. I'll CC Kenji for thoughts.
PR : https://github.com/dlang/dmd/pull/8203/files
Commits pushed to master at https://github.com/dlang/dmd https://github.com/dlang/dmd/commit/14dfe15bf5aad2c6638f1552b6250416b6b7c2b4 Fix Issue 5153 - Struct pointer to struct variable assign error message https://github.com/dlang/dmd/commit/b61d1c8989bed54489c9c7eb5acc2e1f4312b8c6 Merge pull request #8203 from RazvanN7/Issue_5153 Fix Issue 5153 - Struct pointer to struct variable assign error message merged-on-behalf-of: Mike Franklin <JinShil@users.noreply.github.com>