www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4953] New: opBinaryRight for "in" doesn't work right

reply d-bugmail puremagic.com writes:
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: -------
Sep 28 2010
next sibling parent d-bugmail puremagic.com writes:
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: -------
Sep 29 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
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: -------
Sep 30 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
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: -------
Sep 30 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
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: -------
Sep 30 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
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: -------
Oct 05 2010
prev sibling next sibling parent d-bugmail puremagic.com writes:
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: -------
Jul 12 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
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: -------
Jul 21 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
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: -------
Jul 21 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
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: -------
Aug 28 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4953


Erik Baklund <ebaklund hotmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ebaklund hotmail.com


--- Comment #9 from Erik Baklund <ebaklund hotmail.com> 2011-09-25 01:38:23 PDT
---
Yet another example:



module main;

struct MyStruct
{
    void funOpAssign(float[1u] data) { }
    void opOpAssign(string op)(float[1u] data) if(op=="<<") { }
}

int main(string[] argv)
{
    // dmd v2.054, v2.055
    MyStruct s;
    float[1u] a = [1.0f]; // OK: Implicit cast from float[] compiles
    s.funOpAssign([1.0f]); // OK: Implicit cast from float[] compiles
    s <<= [1.0f]; // Issue: Implicit cast from float[] does not compile
    s <<= cast(float[1u])[1.0f]; // OK: Explicit cast from float[] compiles

    return 0;
}

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


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|pull                        |
         AssignedTo|nobody puremagic.com        |bugzilla digitalmars.com


--- Comment #10 from yebblies <yebblies gmail.com> 2012-02-20 00:17:01 EST ---
The pull is still valid (if in need of a rebase) but the solution needs a
decision from Walter on how the match level problem is going to be solved in
the future.

See issue 2367 for another example.

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


hsteoh quickfur.ath.cx changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hsteoh quickfur.ath.cx


--- Comment #11 from hsteoh quickfur.ath.cx 2012-03-19 08:04:35 PDT ---
Another data point:

void f(dstring d) { dstring e = d; }
f("abc");  // OK

void f()(dstring d) { dstring e = d; }
f("abc");  // OK

void f(byte[] b) { byte[] c = b; }
f([1,2,3]); // OK

void f()(byte[] b) { byte[] c = b; }
f([1,2,3]);
// Error: template test2.f() does not match any function template declaration
// Error: template test2.f() cannot deduce template function from argument
types !()(int[])

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


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #12 from Kenji Hara <k.hara.pg gmail.com> 2012-03-24 02:50:06 PDT
---
https://github.com/D-Programming-Language/dmd/pull/45

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


Brad Roberts <braddr puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|pull                        |
                 CC|                            |braddr puremagic.com


--- Comment #13 from Brad Roberts <braddr puremagic.com> 2012-05-12 10:08:27
PDT ---
Looking at this history of this bug and the pulls in github, it looks like
there isn't a valid pull request that fixes this bug right now.  Removing the
keyword.

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



--- Comment #14 from Kenji Hara <k.hara.pg gmail.com> 2012-05-12 10:19:09 PDT
---
(In reply to comment #13)
 Looking at this history of this bug and the pulls in github, it looks like
 there isn't a valid pull request that fixes this bug right now.  Removing the
 keyword.
My dmd/pull/45 fixes both bug 5896 and this. I think the two bugs need the changes of each other. Please keep 'pull' keyword. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 12 2012
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4953


Brad Roberts <braddr puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull


--- Comment #15 from Brad Roberts <braddr puremagic.com> 2012-05-12 10:29:31
PDT ---
I'll add it back, but it looked like Walter was rejecting the pull request.  It
is still open, so might as well leave them linked.

Walter, would you put regression pull requests such as this one near the top of
your todo list?  Either reject with reasons or pull.  Limbo sucks.

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



--- Comment #16 from github-bugzilla puremagic.com 2012-05-12 11:35:46 PDT ---
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/91093c7bb19b2f43dffa868c5f8125e1bd347412
fix Issue 4953 - Regression(2.031): templates don't do implicit conversion
properly

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


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


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


yebblies <yebblies gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |timon.gehr gmx.ch


--- Comment #17 from yebblies <yebblies gmail.com> 2012-07-11 01:38:27 EST ---
*** Issue 7366 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: -------
Jul 10 2012