Skip to content

Commit

Permalink
Merge pull request #2840 from 9rnsr/fix10938
Browse files Browse the repository at this point in the history
Issue 10938 - ICE on recursive instantiation in opDispatch
  • Loading branch information
WalterBright committed Jan 5, 2014
2 parents a78295a + d872976 commit cd8a425
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 33 deletions.
19 changes: 0 additions & 19 deletions src/expression.c
Expand Up @@ -8161,25 +8161,6 @@ Expression *DotTemplateInstanceExp::semanticY(Scope *sc, int flag)
Declaration *v = s->isDeclaration();
if (v && (v->isFuncDeclaration() || v->isVarDeclaration()))
{
/* Fix for Bugzilla 4003
* The problem is a class template member function v returning a reference to the same
* type as the enclosing template instantiation. This results in a nested instantiation,
* which of course gets short circuited. The return type then gets set to
* the template instance type before instantiation, rather than after.
* We can detect this by the deco not being set. If so, go ahead and retry
* the return type semantic.
* The offending code is the return type from std.typecons.Tuple.slice:
* ref Tuple!(Types[from .. to]) slice(uint from, uint to)()
* {
* return *cast(typeof(return) *) &(field[from]);
* }
* and this line from the following unittest:
* auto s = a.slice!(1, 3);
* where s's type wound up not having semantic() run on it.
*/
if (v->type && !v->type->deco)
v->type = v->type->semantic(v->loc, sc);

e = new DotVarExp(loc, eleft, v);
e = e->semantic(sc);
return e;
Expand Down
3 changes: 3 additions & 0 deletions test/compilable/imports/stdio4003.d
@@ -0,0 +1,3 @@
module imports.stdio4003;

import imports.typecons4003;
6 changes: 6 additions & 0 deletions test/compilable/imports/test4003a.d
@@ -0,0 +1,6 @@
module imports.test4003a;

import imports.typecons4003;

Tuple!(string) t;

6 changes: 0 additions & 6 deletions test/compilable/imports/test65a.d

This file was deleted.

22 changes: 22 additions & 0 deletions test/compilable/imports/typecons4003.d
@@ -0,0 +1,22 @@
module imports.typecons4003;

struct Tuple(T...)
{
alias T Types;
Types field;

ref Tuple!(Types[from .. to]) slice(uint from, uint to)()
{
return *cast(typeof(return) *) &(field[from]);
}

void test() //unittest
{
.Tuple!(int, string, float, double) a;
a.field[1] = "abc";
a.field[2] = 4.5;
auto s = a.slice!(1, 3);
static assert(is(typeof(s) == Tuple!(string, float)));
//assert(s.field[0] == "abc" && s.field[1] == 4.5);
}
}
6 changes: 6 additions & 0 deletions test/compilable/test4003.d
@@ -0,0 +1,6 @@
// EXTRA_SOURCES: imports/test4003a.d
// PERMUTE_ARGS:

import imports.stdio4003;
void main(){}

8 changes: 0 additions & 8 deletions test/compilable/test65.d

This file was deleted.

23 changes: 23 additions & 0 deletions test/fail_compilation/ice10938.d
@@ -0,0 +1,23 @@
/*
TEST_OUTPUT:
---
fail_compilation/ice10938.d(12): Error: no property 'opts' for type 'ice10938.C'
---
*/

class C
{
this()
{
this.opts["opts"] = 1;
}

auto opDispatch(string field : "opts")()
{
return this.opts; // ICE -> compile time error
}
}

void main()
{
}

0 comments on commit cd8a425

Please sign in to comment.