Bug 5010 – Error messages for properties could be improved

Status
NEW
Severity
minor
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-10-07T07:22:52Z
Last change time
2024-12-13T17:53:49Z
Keywords
diagnostic
Assigned to
No Owner
Creator
Don
Moved to GitHub: dmd#18308 →

Comments

Comment #0 by clugdbug — 2010-10-07T07:22:52Z
The problem with the error messages is that they refer to the property in the syntax it has AFTER conversion to a function call. ---- CASE 1: Assignments cannot be chained through properties @property void prop(int x) {} void main() { int a = prop = 6; } ---- bug.d(7): Error: expression prop(6) is void and has no value ---- The error message is quite difficult to understand. I do think it is quite reasonable that it fails to compile, though, since the getter could be defined as: @property int prop() { return 2; } Secondly, the error messages when you use a getter (eg, int a = prop; ), when only a setter is defined, are: bug.d(7): Error: function test0.prop (int x) is not callable using argument types () bug.d(8): Error: expected 1 function arguments, not 0 bug.d(9): Error: expression prop() is void and has no value This error message is confusing because no parens were used. The same situation applies when trying to use a setter, when only a getter is defined.
Comment #1 by adrian — 2012-12-12T09:33:35Z
I'd add also the following: struct A { @property void foo(uint x); } void main() { A a; a.foo = "bar"; // (1) } (1) causes "Error: not a property a.foo", which may look obvious here, but gets confusing with more complex types.
Comment #2 by rtcvb32 — 2013-02-09T20:03:58Z
> struct A > { > @property void foo(uint x); > } > > void main() > { > A a; > a.foo = "bar"; // (1) > } > > > (1) causes "Error: not a property a.foo", which may look obvious here, but gets > confusing with more complex types. Also related (similar types) it should mention those that need down-casting, or something more useful. struct S { //setters void test(uint v) @property {} void test2(ulong v) @property {} } ulong x; S s; s.test2 = x; s.test = x; //Error: not a property s.test
Comment #3 by slavo5150 — 2017-08-14T23:08:13Z
*** Issue 15158 has been marked as a duplicate of this issue. ***
Comment #4 by nick — 2024-11-13T16:52:33Z
(In reply to Era Scarecrow from comment #2) > > struct A > > { > > @property void foo(uint x); > > } > > > > void main() > > { > > A a; > > a.foo = "bar"; // (1) > > } > > > > > > (1) causes "Error: not a property a.foo", which may look obvious here, but gets > > confusing with more complex types. This is now: propassign.d(14): Error: function `propassign.A.foo(uint x)` is not callable using argument types `(string)` propassign.d(14): cannot pass argument `"bar"` of type `string` to parameter `uint x` > Also related (similar types) it should mention those that need > down-casting, or something more useful. > > struct S { > //setters > void test(uint v) @property {} > void test2(ulong v) @property {} > } > > ulong x; > S s; > > s.test2 = x; > s.test = x; //Error: not a property s.test This is now: propassign.d(28): Error: function `propassign.S.test(uint v)` is not callable using argument types `(ulong)` propassign.d(28): cannot pass argument `x` of type `ulong` to parameter `uint v`
Comment #5 by robert.schadek — 2024-12-13T17:53:49Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18308 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB