diff --git a/src/init.c b/src/init.c index 6e7e954b5c65..28f10f893719 100644 --- a/src/init.c +++ b/src/init.c @@ -1060,17 +1060,17 @@ Type *ExpInitializer::inferType(Scope *sc) // Give error for overloaded function addresses if (exp->op == TOKsymoff) - { SymOffExp *se = (SymOffExp *)exp; + { + SymOffExp *se = (SymOffExp *)exp; if (se->hasOverloads && !se->var->isFuncDeclaration()->isUnique()) { exp->error("cannot infer type from overloaded function symbol %s", exp->toChars()); return Type::terror; } } - - // Give error for overloaded function addresses if (exp->op == TOKdelegate) - { DelegateExp *se = (DelegateExp *)exp; + { + DelegateExp *se = (DelegateExp *)exp; if (se->hasOverloads && se->func->isFuncDeclaration() && !se->func->isFuncDeclaration()->isUnique()) @@ -1079,6 +1079,15 @@ Type *ExpInitializer::inferType(Scope *sc) return Type::terror; } } + if (exp->op == TOKaddress) + { + AddrExp *ae = (AddrExp *)exp; + if (ae->e1->op == TOKoverloadset) + { + exp->error("cannot infer type from overloaded function symbol %s", exp->toChars()); + return Type::terror; + } + } Type *t = exp->type; if (!t) diff --git a/test/fail_compilation/fail10082.d b/test/fail_compilation/fail10082.d new file mode 100644 index 000000000000..fd3080109d44 --- /dev/null +++ b/test/fail_compilation/fail10082.d @@ -0,0 +1,25 @@ +/* +TEST_OUTPUT: +--- +fail_compilation/fail10082.d(24): Error: cannot infer type from overloaded function symbol &foo +--- +*/ + +mixin template T() +{ + int foo() + { + return 0; + } +} + +class A +{ + mixin T; + mixin T; +} + +void main() +{ + auto x = &A.foo; +}