Fix Issue 22157 - Bad diagnostic for static/non-static overload resolution conflict (#12958)

This commit is contained in:
Razvan Nitu 2021-08-06 17:01:21 +08:00 committed by GitHub
parent ffcc851a89
commit 1963056317
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 0 deletions

View file

@ -5060,6 +5060,20 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
}
else if (isNeedThisScope(sc, exp.f))
{
// At this point it is possible that `exp.f` had 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();
}

View file

@ -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;
}