Bug 5153 – Struct pointer to struct variable assign error message

Status
RESOLVED
Resolution
FIXED
Severity
minor
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-11-01T13:24:03Z
Last change time
2018-05-18T07:50:54Z
Keywords
bootcamp, diagnostic
Assigned to
No Owner
Creator
bearophile_hugs

Comments

Comment #0 by bearophile_hugs — 2010-11-01T13:24:03Z
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
Comment #1 by andrej.mitrovich — 2014-04-28T12:01:08Z
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.
Comment #2 by razvan.nitu1305 — 2018-04-23T12:20:26Z
Comment #3 by github-bugzilla — 2018-05-18T07:50:53Z
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 <[email protected]>