digitalmars.D.bugs - [Issue 10394] New: opBinaryRight!"in" and tuple
- d-bugmail puremagic.com (42/42) Jun 17 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10394
- d-bugmail puremagic.com (15/15) Jun 17 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10394
- d-bugmail puremagic.com (14/22) Jun 17 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10394
- d-bugmail puremagic.com (38/38) Jul 15 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10394
- d-bugmail puremagic.com (13/13) Aug 25 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10394
- d-bugmail puremagic.com (11/11) Aug 27 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10394
- d-bugmail puremagic.com (10/10) Aug 27 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10394
http://d.puremagic.com/issues/show_bug.cgi?id=10394
Summary: opBinaryRight!"in" and tuple
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Severity: regression
Priority: P2
Component: DMD
AssignedTo: nobody puremagic.com
ReportedBy: justin economicmodeling.com
13:48:39 PDT ---
The following code compiles with 2.062 but not with 2.063:
-------------------------------------------------------
import std.typetuple;
struct Cube
{
alias Address = TypeTuple!(int, int);
//alias Address = int;
int* opBinaryRight(string op)(Address where)
{
return null;
}
}
void main()
{
Cube cube;
cube.Address addr;
auto ptr = addr in cube;
}
---------------------------------------------------------
In 2.063, DMD produces the following:
cube.d(18): Error: rvalue of in expression must be an associative array, not
Cube
Flipping the comments on the two "alias Address" lines causes the sample to
compile under both, so the problem is triggered by the use of a tuple as the
left side of the "in" operator. Using DMD with -v indicates the trouble is
during the semantic3 phase.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 17 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10394
Andrej Mitrovic <andrej.mitrovich gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |andrej.mitrovich gmail.com
15:52:18 PDT ---
You could use Tuple from std.typecons instead and it will work.
It seems to me what's going on is auto-expansion of a TypeTuple into two
arguments, and opBinaryRight (or opIn_r) simply can't accept more than one
argument.
I don't know why that even worked before, it might have been an accepts-invalid
bug in 2.062 and earlier. Kenji Hara will probably know more.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 17 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10394 16:08:36 PDT ---You could use Tuple from std.typecons instead and it will work. It seems to me what's going on is auto-expansion of a TypeTuple into two arguments, and opBinaryRight (or opIn_r) simply can't accept more than one argument. I don't know why that even worked before, it might have been an accepts-invalid bug in 2.062 and earlier. Kenji Hara will probably know more.From my perspective it'd be somewhat unfortunate to lose the ability to do this. We make extensive use of "in" as a complement to indexing the same way associative arrays do: indexing returns the thing or throws if not present while "in" returns a pointer to the thing or null if not present. Because we use indexing with multiple "keys" it's nice to have a symmetric way of using "in". As for your suggestion to use Tuple, we usually provide an overload for that as well, particularly because tuples can't be returned from functions. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Jun 17 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10394
15:45:23 PDT ---
An update on this issue: we have worked around this by switching away from "in"
to a method-based approach, so this is no longer blocking for the reporter. I
think this issue remains valid until it's decided whether the "in" operator (or
operators in general) will allow a tuple on the left hand side. Here's a
simplified example that matches with our use case:
-----------------------------
struct Graph(T, Address...)
{
struct Node
{
Address address;
T payload;
}
...
Node* opBinaryRight(string op)(Address address) if (op == "in)
{
...
}
}
void main()
{
Graph!(double, int, string) graph;
auto node = ...procure a node from somwhere...
// node.address is preferred to tuple(node.address)
if (auto inGraph = node.address in graph)
{
...
}
}
-----------------------------
As I said, we have worked around this because it's not unreasonable for binary
operators to only allow one value on each side, but it was also nice to have
this kind of syntax in 2.062 and previous.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 15 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10394
Kenji Hara <k.hara.pg gmail.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |pull
https://github.com/D-Programming-Language/dmd/pull/2497
I still have a doubt that this should be fixed... Even if the dmd
implementation will be fixed in 2.064 release, we should continue discussion
about the combination of operator-overloading and built-in tuple behavior.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 25 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10394 Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/c4ca9257ed2863f8ef2c1be31e8690f2363a3ab9 fix Issue 10394 - opBinaryRight!"in" and tuple https://github.com/D-Programming-Language/dmd/commit/73ca1a9b83ef6fcd8922fb7c5d6b2c0a0b576ca9 [REG2.064a] Issue 10394 - opBinaryRight!"in" and tuple -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 27 2013
http://d.puremagic.com/issues/show_bug.cgi?id=10394
Walter Bright <bugzilla digitalmars.com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
CC| |bugzilla digitalmars.com
Resolution| |FIXED
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 27 2013









d-bugmail puremagic.com 