www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5010] New: Error messages for properties could be improved

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5010

           Summary: Error messages for properties could be improved
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: diagnostic
          Severity: minor
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: clugdbug yahoo.com.au


--- Comment #0 from Don <clugdbug yahoo.com.au> 2010-10-07 07:22:52 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Oct 07 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5010


Adrian Matoga <epi atari8.info> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |epi atari8.info


--- Comment #1 from Adrian Matoga <epi atari8.info> 2012-12-12 09:33:35 PST ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 12 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5010


Era Scarecrow <rtcvb32 yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rtcvb32 yahoo.com


--- Comment #2 from Era Scarecrow <rtcvb32 yahoo.com> 2013-02-09 20:03:58 PST
---
 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 -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Feb 09 2013