View mode: basic / threaded / horizontal-split · Log in · Help
September 21, 2011
[Issue 6707] New: Error message for mismatch of const/non-const property functions needs to improve
http://d.puremagic.com/issues/show_bug.cgi?id=6707

          Summary: Error message for mismatch of const/non-const property
                   functions needs to improve
          Product: D
          Version: D2
         Platform: Other
       OS/Version: Windows
           Status: NEW
         Severity: normal
         Priority: P2
        Component: DMD
       AssignedTo: nobody@puremagic.com
       ReportedBy: andrej.mitrovich@gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2011-09-21 08:44:17 PDT ---
struct Foo
{
   int payload;

   @property void value(int x) { payload = x;}
   @property int value() { return payload; }

   const bool opEquals(ref const(Foo) other)
   {
       return this.value == other.value;
   }        
}

void main() { }

This errors with: 
Error: function test.Foo.value (int x) is not callable using argument types ()
The solution is to add a const property function like this one:

@property const(int) value() const { return payload; }

But this can't be easily figured out from that error message.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 04, 2012
[Issue 6707] Error message for mismatch of const/non-const property functions needs to improve
http://d.puremagic.com/issues/show_bug.cgi?id=6707



--- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-10-04 12:56:30 PDT ---
Better test case:

struct Foo
{
   @property bool value() { return true; }

   void test() const
   {
       auto x = value;   // not callable using argument types ()
       auto y = value(); // not callable using argument types () const
   }
}

void main() { }

It seems 'this' for property func isn't printed out properly unless it's called
as a function, I'll see if this is fixable.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 08, 2012
[Issue 6707] Error message for mismatch of const/non-const property functions needs to improve
http://d.puremagic.com/issues/show_bug.cgi?id=6707



--- Comment #2 from github-bugzilla@puremagic.com 2012-10-08 10:48:56 PDT ---
Commits pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/d123b58057a8116d3549418551ed7ea03f9c46cd
Fixes Issue 6707

https://github.com/D-Programming-Language/dmd/commit/b022c3c66616600cdf349d53d32983774b72fdbd
Merge pull request #1164 from AndrejMitrovic/Fix6707

Fix Issue 6707 - Print better error message on const property mismatch

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 08, 2012
[Issue 6707] Error message for mismatch of const/non-const property functions needs to improve
http://d.puremagic.com/issues/show_bug.cgi?id=6707


Brad Roberts <braddr@puremagic.com> changed:

          What    |Removed                     |Added
----------------------------------------------------------------------------
            Status|NEW                         |RESOLVED
                CC|                            |braddr@puremagic.com
        Resolution|                            |FIXED


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 20, 2012
[Issue 6707] Error message for mismatch of const/non-const property functions needs to improve
http://d.puremagic.com/issues/show_bug.cgi?id=6707


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

          What    |Removed                     |Added
----------------------------------------------------------------------------
                CC|                            |bearophile_hugs@eml.cc


--- Comment #3 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-10-19 20:57:42 PDT ---
*** Issue 8549 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 21, 2012
[Issue 6707] Error message for mismatch of const/non-const property functions needs to improve
http://d.puremagic.com/issues/show_bug.cgi?id=6707


bearophile_hugs@eml.cc changed:

          What    |Removed                     |Added
----------------------------------------------------------------------------
            Status|RESOLVED                    |REOPENED
        Resolution|FIXED                       |
          Severity|normal                      |enhancement


--- Comment #4 from bearophile_hugs@eml.cc 2012-10-21 14:09:55 PDT ---
I reopen this as enhancement request because I think the error message is not
good enough still. See Issue 8549 for more info.

This program:


struct Foo {
   int[] opSlice() {
       return [0];
   }
}
struct Bar {
   Foo spam;
   const(Foo) bar() const { return spam; }
}
void main() {
   Bar().bar()[];
}


Currently gives:

test.d(11): Error: function test.Foo.opSlice () is not callable using argument
types () const


In Issue 8549 Andrej Mitrovic suggests an error message similar to:

Error: function test.Foo.opSlice () is not callable using const(this)


But I think a better error message, more newbie-friendly, tells the programmer
how to fix the problem, (not complete error message):

test.d(11): Error: function test.Foo.opSlice() needs to be const to [...]

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 21, 2012
[Issue 6707] Error message for mismatch of const/non-const property functions needs to improve
http://d.puremagic.com/issues/show_bug.cgi?id=6707



--- Comment #5 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-10-21 14:15:14 PDT ---
(In reply to comment #4)
> But I think a better error message, more newbie-friendly, tells the programmer
> how to fix the problem, (not complete error message):
> 
> test.d(11): Error: function test.Foo.opSlice() needs to be const to [...]

If it's in a 3rd party library then the user has no other choice but to use a
const object. I don't think we should start recommending to rewrite code like
that, especially to newbies.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 21, 2012
[Issue 6707] Error message for mismatch of const/non-const property functions needs to improve
http://d.puremagic.com/issues/show_bug.cgi?id=6707



--- Comment #6 from bearophile_hugs@eml.cc 2012-10-21 14:33:36 PDT ---
(In reply to comment #5)

> If it's in a 3rd party library then the user has no other choice but to use a
> const object. I don't think we should start recommending to rewrite code like
> that, especially to newbies.

I understand.

Time ago I have seen this error message and it took me some some to understand
what's the problem. So I've asked for a simpler to understand error message. If
you think my suggestion is not good, then do something different :-)

Maybe we should ask to more people in the D newsgroup.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 10, 2012
[Issue 6707] Error message for mismatch of const/non-const property functions needs to improve
http://d.puremagic.com/issues/show_bug.cgi?id=6707


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

          What    |Removed                     |Added
----------------------------------------------------------------------------
                CC|                            |bugzilla@kyllingen.net


--- Comment #7 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-12-10 08:57:39 PST ---
*** Issue 9132 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
December 28, 2012
[Issue 6707] Error message for mismatch of const/non-const property functions needs to improve
http://d.puremagic.com/issues/show_bug.cgi?id=6707


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

          What    |Removed                     |Added
----------------------------------------------------------------------------
            Status|REOPENED                    |RESOLVED
        Resolution|                            |DUPLICATE


--- Comment #8 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-12-27 17:43:17 PST ---
The pull for Issue 1730 will likely resolve your issue of the unreadable error
message.

*** This issue has been marked as a duplicate of issue 1730 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2
Top | Discussion index | About this forum | D home