www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3905] New: Wrong error message with wrong opBinary("in")

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

           Summary: Wrong error message with wrong opBinary("in")
           Product: D
           Version: 2.041
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc


--- Comment #0 from bearophile_hugs eml.cc 2010-03-08 16:10:09 PST ---
This D2 program is wrong, because it needs a opBinaryRight to work:


struct Group {
    int i1, i2;
    bool opBinary(string s:"in")(int x) { 
        return x == this.i1 || x == this.i2;
    }
}
auto enum r = 3 in Group(1, 2);
void main() {}


But the compiler gives a bad error message, that doesn't help the programmer
much (and there are no associative arrays in this program):

test.d(7): Error: rvalue of in expression must be an associative array, not
Group

For example a better error message can be:

test.d(7): Error: Group has no opBinaryRight("in") operator and int has no
opBinary("in") operator.

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


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |diagnostic, patch
                 CC|                            |clugdbug yahoo.com.au


--- Comment #1 from Don <clugdbug yahoo.com.au> 2010-09-30 01:37:09 PDT ---
PATCH:
expression.c, line 10624, InExp::semantic()


        default:
-            error("rvalue of in expression must be an associative array, not
%s", e2->type->toChars());
+            error("%s has no opBinaryRight(\"in\") operator and %s has no
opBinary(\"in\") operator", e1->type->toChars(), e2->type->toChars());
        case Terror:
            return new ErrorExp();
    }

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



--- Comment #2 from bearophile_hugs eml.cc 2010-09-30 05:10:35 PDT ---
Thank you Don :-) I need to be able to write a patch like this by myself.

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


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |WONTFIX


--- Comment #3 from Walter Bright <bugzilla digitalmars.com> 2010-12-04
18:36:08 PST ---
I'm not convinced this new error message is an improvement. All the expression
error messages work on the assumption that operator overloads do not exist, as
that is the normal case. Trying to write an error message for the normal case
in terms of "you screwed up the operator overloads" is not helpful. For
example,

  int a;
  double b;
  a in b;

will give a pretty much incomprehensible error message to the user:

  test.d(7): Error: double has no opBinaryRight("in") operator and int has no
  opBinary("in") operator.

???

I'd prefer to leave the message as is. If someone is doing operator
overloading, the message makes it clear the operator overloading failed to find
a match.

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


Steven Schveighoffer <schveiguy yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |schveiguy yahoo.com
         Resolution|WONTFIX                     |


--- Comment #4 from Steven Schveighoffer <schveiguy yahoo.com> 2010-12-04
22:46:00 PST ---
I agree that the proposed patch is not better.  But the original message is
invalid.  This is a bug that needs to be fixed, regardless of whether you like
the given proposals.

Point in fact, in *can* work on types besides associative arrays.

I tried this:

struct S {}

void main()
{
   S s;
   auto t = s + s;
}

And got:

Error: incompatible types for ((s) + (s)): 'S' and 'S'

So extrapolating to in, the error should look like:

Error: incompatible types for ((3) in (Group(1, 2))): 'int' and 'Group'

Although, I'm unsure why there are so many parentheses...

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



--- Comment #5 from bearophile_hugs eml.cc 2010-12-11 00:20:31 PST ---
Saying that double has no "in" is correct (even if it's a bit noisy and
overkill), while saying "rvalue of in expression must be an associative array,
not Group" is wrong.

I think this bug report is valid still, because the current error message is
confusing. So a better solution will be useful.

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



--- Comment #6 from yebblies <yebblies gmail.com> 2013-01-17 02:14:10 EST ---
*** Issue 7837 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: -------
Jan 16 2013