Jump to page: 1 2
Thread overview
[Issue 4953] New: opBinaryRight for "in" doesn't work right
[Issue 4953] opBinary, opBinaryRight don't do implicit conversion properly
Sep 30, 2010
Don
Sep 30, 2010
Don
[Issue 4953] Regression(2.031): templates don't do implicit conversion properly
Oct 05, 2010
Don
Jul 12, 2011
yebblies
Jul 22, 2011
Walter Bright
Jul 22, 2011
yebblies
Aug 29, 2011
yebblies
Sep 25, 2011
Erik Baklund
Feb 19, 2012
yebblies
Mar 24, 2012
Kenji Hara
May 12, 2012
Brad Roberts
May 12, 2012
Kenji Hara
May 12, 2012
Brad Roberts
May 12, 2012
Walter Bright
Jul 10, 2012
yebblies
September 28, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4953

           Summary: opBinaryRight for "in" doesn't work right
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: schveiguy@yahoo.com


--- Comment #0 from Steven Schveighoffer <schveiguy@yahoo.com> 2010-09-28 14:13:57 PDT ---
Given this struct:

struct S
{
    short _x;
    bool opBinaryRight(string op)(short x) if (op == "in")
    {
        return x == _x;
    }
}

void main()
{
    S s;
    5 in s;
}

This produces the error:

testopin.d(13): Error: rvalue of in expression must be an associative array,
not S

But change the type of x to int, and it works.  However, the type of the argument should play no role in whether the template can be instantiated.  It seems this is the error message that is given when a type does not support opIn, so the error message is very bad too.

Slightly related, but not the same issue: bug 3905

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 29, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4953



--- Comment #1 from Steven Schveighoffer <schveiguy@yahoo.com> 2010-09-29 06:06:21 PDT ---
Further evidence, this compiles:

void main()
{
    S s;
    s.opBinaryRight!"in"(5);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 30, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4953


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |rejects-valid
                 CC|                            |clugdbug@yahoo.com.au
            Summary|opBinaryRight for "in"      |opBinary, opBinaryRight
                   |doesn't work right          |don't do implicit
                   |                            |conversion properly


--- Comment #2 from Don <clugdbug@yahoo.com.au> 2010-09-30 01:48:40 PDT ---
(In reply to comment #1)
> Further evidence, this compiles:
> 
> void main()
> {
>     S s;
>     s.opBinaryRight!"in"(5);
> }

This is not specific to "in". The code below fails to compile, but it works if you change "short" to "int".

struct S
{
    void opBinary(string op)(short x)
    {}
}

void main()
{
    S s;
    s + 5;
}

Original title for this bug was:
opBinaryRight for "in" doesn't work right

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 30, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4953



--- Comment #3 from Don <clugdbug@yahoo.com.au> 2010-09-30 09:47:34 PDT ---
Wow. This is a lot more general than I thought. Consider this code:


void foo(T = void)(short x) {}

void main()
{
  foo(5);
}

This compiled in 2.030, failed in 2.031 and later.

However, if you change 'short' to 'long', it works.

It's because of mtype.c,  TypeBasic::implicitConvTo(), line 3010.

Implicit conversion to a smaller size is disallowed. That's fine in general, but shouldn't be true of template deduction.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
September 30, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4953


bearophile_hugs@eml.cc changed:

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


--- Comment #4 from bearophile_hugs@eml.cc 2010-09-30 10:19:37 PDT ---
Another example:


void foo(T = void)(short x) {}
void main() {
  foo(5_000_000);
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
October 05, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4953


Don <clugdbug@yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|opBinary, opBinaryRight     |Regression(2.031):
                   |don't do implicit           |templates don't do implicit
                   |conversion properly         |conversion properly
           Severity|normal                      |regression


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 12, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4953


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch
                 CC|                            |yebblies@gmail.com
           Platform|Other                       |All
         OS/Version|Linux                       |All


--- Comment #5 from yebblies <yebblies@gmail.com> 2011-07-12 20:18:23 EST ---
https://github.com/D-Programming-Language/dmd/pull/239

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 22, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4953


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla@digitalmars.com


--- Comment #6 from Walter Bright <bugzilla@digitalmars.com> 2011-07-21 18:09:50 PDT ---
(In reply to comment #5)
> https://github.com/D-Programming-Language/dmd/pull/239

The patch breaks the test suite.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 22, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4953



--- Comment #7 from yebblies <yebblies@gmail.com> 2011-07-22 16:08:51 EST ---
(In reply to comment #6)
> (In reply to comment #5)
> > https://github.com/D-Programming-Language/dmd/pull/239
> 
> The patch breaks the test suite.

Redone: https://github.com/D-Programming-Language/dmd/pull/269

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 29, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=4953


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |k.hara.pg@gmail.com


--- Comment #8 from yebblies <yebblies@gmail.com> 2011-08-29 14:39:56 EST ---
*** Issue 6567 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: -------
« First   ‹ Prev
1 2