Skip to content

Commit

Permalink
Fix Issue 22157 - Bad diagnostic for static/non-static overload resol…
Browse files Browse the repository at this point in the history
…ution conflict
  • Loading branch information
RazvanN7 committed Aug 5, 2021
1 parent d0406f3 commit c1a79d3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/dmd/expressionsem.d
Expand Up @@ -5060,6 +5060,20 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
}
else if (isNeedThisScope(sc, exp.f))
{
// At this point it is possible that `f` has an ambiguity error that was
// silenced because the previous call to `resolveFuncCall` was done using
// `FuncResolveFlag.overloadOnly`. To make sure that a proper error message
// is printed, redo the call with `FuncResolveFlag.standard`.
//
// https://issues.dlang.org/show_bug.cgi?id=22157
if (exp.f.overnext)
exp.f = resolveFuncCall(exp.loc, sc, exp.f, tiargs, null, exp.arguments, FuncResolveFlag.standard);

if (!exp.f || exp.f.errors)
return setError();

// If no error is printed, it means that `f` is the single matching overload
// and it needs `this`.
exp.error("need `this` for `%s` of type `%s`", exp.f.toChars(), exp.f.type.toChars());
return setError();
}
Expand Down
34 changes: 34 additions & 0 deletions test/fail_compilation/fail22157.d
@@ -0,0 +1,34 @@
// https://issues.dlang.org/show_bug.cgi?id=22157

/*
TEST_OUTPUT:
---
fail_compilation/fail22157.d(32): Error: `fail22157.S!true.S.foo` called with argument types `()` matches both:
fail_compilation/fail22157.d(21): `fail22157.S!true.S.foo()`
and:
fail_compilation/fail22157.d(22): `fail22157.S!true.S.foo()`
fail_compilation/fail22157.d(33): Error: `fail22157.S!false.S.foo` called with argument types `()` matches both:
fail_compilation/fail22157.d(26): `fail22157.S!false.S.foo()`
and:
fail_compilation/fail22157.d(27): `fail22157.S!false.S.foo()`
---
*/

struct S(bool b)
{
static if(b)
{
void foo() {}
static void foo() {}
}
else
{
static void foo() {}
void foo() {}
}
}

void main() {
S!true.foo;
S!false.foo;
}

0 comments on commit c1a79d3

Please sign in to comment.