Skip to content

Commit

Permalink
Merge pull request #7404 from JinShil/fix_16042
Browse files Browse the repository at this point in the history
Fix Issue 16042 - Identifier on template arguments should consider eponymous member lookup
  • Loading branch information
WalterBright committed Dec 29, 2017
2 parents ed47f25 + b2a5fb8 commit 5470151
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/dmd/mtype.d
Expand Up @@ -6802,6 +6802,25 @@ extern (C++) final class TypeIdentifier : TypeQualified

Dsymbol scopesym;
Dsymbol s = sc.search(loc, ident, &scopesym);

if (s)
{
// https://issues.dlang.org/show_bug.cgi?id=16042
// If `f` is really a function template, then replace `f`
// with the function template declaration.
if (auto f = s.isFuncDeclaration())
{
if (auto td = getFuncTemplateDecl(f))
{
// If not at the beginning of the overloaded list of
// `TemplateDeclaration`s, then get the beginning
if (td.overroot)
td = td.overroot;
s = td;
}
}
}

resolveHelper(loc, sc, s, scopesym, pe, pt, ps, intypeid);
if (*pt)
(*pt) = (*pt).addMod(mod);
Expand Down
52 changes: 52 additions & 0 deletions test/runnable/template9.d
Expand Up @@ -4848,6 +4848,56 @@ void test15781()
static assert(is(typeof(foo(cs, cs)) == const S));
}

/******************************************/
// https://issues.dlang.org/show_bug.cgi?id=16042

struct Foo16042 {}

auto map16042(alias func, T)(T t)
{
return func(t);
}

auto toChars16042(R)(R r) if (is(R == int[]))
{
Foo16042 f;
assert(toChars16042(f) == 1); // OK
assert(map16042!(toChars16042)(f) == 1); // OK <- NG
assert(map16042!((toChars16042))(f) == 1); // OK
}

auto toChars16042(Foo16042 f)
{
return 1;
}

void test16042()
{
[1].toChars16042();
}

// ---

auto fn16042(R)(R r) if (is(R == int[])) {}
auto fn16042(Foo16042 f) { return 1; }

struct Namespace16042
{
alias fn = fn16042!(int[]);
}

void test16042b()
{
Foo16042 f;

with (Namespace16042)
{
static assert(!__traits(compiles, fn(f))); // NG
static assert(!__traits(compiles, map16042!(fn)(f))); // should be NG -> actually NG
static assert(!__traits(compiles, map16042!((fn))(f))); // NG
}
}

/******************************************/
// https://issues.dlang.org/show_bug.cgi?id=15243

Expand Down Expand Up @@ -4991,6 +5041,8 @@ int main()
test14735();
test14802();
test15116();
test16042();
test16042b();
test15243();

printf("Success\n");
Expand Down

0 comments on commit 5470151

Please sign in to comment.