mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 13:10:12 +03:00
Fix Issue 22157 - Bad diagnostic for static/non-static overload resolution conflict (#12958)
This commit is contained in:
parent
ffcc851a89
commit
1963056317
2 changed files with 48 additions and 0 deletions
|
@ -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();
|
||||
}
|
||||
|
|
34
test/fail_compilation/fail22157.d
Normal file
34
test/fail_compilation/fail22157.d
Normal 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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue