Skip to content

Commit

Permalink
Merge pull request #3054 from WalterBright/fix11591
Browse files Browse the repository at this point in the history
Regression fix Issue 11591 - std.typecons.Tuple -s with classes fails at runtime as associative array keys
  • Loading branch information
andralex committed Jan 2, 2014
2 parents 34fc8dd + 0e08634 commit 10de92b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/mtype.c
Expand Up @@ -4817,6 +4817,19 @@ printf("index->ito->ito = x%x\n", index->ito->ito);
error(loc, "can't have associative array key of %s", index->toBasetype()->toChars());
case Terror:
return Type::terror;
case Tstruct:
{
/* AA's need opCmp. Issue error if not correctly set up.
*/
TypeStruct *ts = (TypeStruct *)index->toBasetype();
if (ts->sym->xcmp == ts->sym->xerrcmp)
{
error(loc, "associative array key type %s does not have 'const int opCmp(ref const %s)' member function",
index->toBasetype()->toChars(), ts->sym->toChars());
return Type::terror;
}
break;
}
}
next = next->semantic(loc,sc)->merge2();
transitive();
Expand Down
14 changes: 14 additions & 0 deletions test/fail_compilation/fail11591.d
@@ -0,0 +1,14 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail11591.d(13): Error: associative array key type T does not have 'const int opCmp(ref const T)' member function
---
*/

struct T {
bool opCmp(int i) { return false; }
}

void main() {
int[T] aa;
}
5 changes: 5 additions & 0 deletions test/runnable/sdtor.d
Expand Up @@ -2415,6 +2415,11 @@ struct Test9386
printf("Deleted %.*s\n", name.length, name.ptr);
op ~= "c";
}

const int opCmp(ref const Test9386 t)
{
return op[0] - t.op[0];
}
}

void test9386()
Expand Down
1 change: 1 addition & 0 deletions test/runnable/test12.d
Expand Up @@ -914,6 +914,7 @@ struct Property
struct Value
{
int a,b,c,d;
const int opCmp(ref const Value v) { return 0; }
}

struct PropTable
Expand Down

0 comments on commit 10de92b

Please sign in to comment.