mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 05:00:16 +03:00
Improve error for failing opDispatch instantiation (#20902)
This commit is contained in:
parent
f88520c3c1
commit
54a142412c
6 changed files with 34 additions and 22 deletions
|
@ -3461,10 +3461,26 @@ Expression getProperty(Type t, Scope* scope_, Loc loc, Identifier ident, int fla
|
|||
{
|
||||
if (auto sym = dsym.isAggregateDeclaration())
|
||||
{
|
||||
if (auto fd = search_function(sym, Id.opDispatch))
|
||||
errorSupplemental(loc, "potentially malformed `opDispatch`. Use an explicit instantiation to get a better error message");
|
||||
else if (!sym.members)
|
||||
if (!sym.members)
|
||||
{
|
||||
errorSupplemental(sym.loc, "`%s %s` is opaque and has no members.", sym.kind, mt.toPrettyChars(true));
|
||||
return ErrorExp.get();
|
||||
}
|
||||
|
||||
if (auto fd = search_function(sym, Id.opDispatch))
|
||||
{
|
||||
if (auto td = fd.isTemplateDeclaration())
|
||||
{
|
||||
e = mt.defaultInitLiteral(loc);
|
||||
auto se = new StringExp(e.loc, ident.toString());
|
||||
auto tiargs = new Objects();
|
||||
tiargs.push(se);
|
||||
auto dti = new DotTemplateInstanceExp(e.loc, e, Id.opDispatch, tiargs);
|
||||
dti.ti.tempdecl = td;
|
||||
dti.dotTemplateSemanticProp(scope_, DotExpFlag.none);
|
||||
return ErrorExp.get();
|
||||
}
|
||||
}
|
||||
}
|
||||
errorSupplemental(dsym.loc, "%s `%s` defined here",
|
||||
dsym.kind, dsym.toChars());
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
/*
|
||||
TEST_OUTPUT:
|
||||
---
|
||||
fail_compilation/diag14145.d(16): Error: no property `i` for `_` of type `diag14145.main.Capture!(i)`
|
||||
fail_compilation/diag14145.d(16): potentially malformed `opDispatch`. Use an explicit instantiation to get a better error message
|
||||
fail_compilation/diag14145.d(26): struct `Capture` defined here
|
||||
fail_compilation/diag14145.d(35): Error: expression `*this.ptr` of type `shared(int)` is not implicitly convertible to return type `ref int`
|
||||
fail_compilation/diag14145.d(17): Error: template instance `diag14145.main.Capture!(i).Capture.opDispatch!"i"` error instantiating
|
||||
fail_compilation/diag14145.d(14): Error: no property `i` for `_` of type `diag14145.main.Capture!(i)`
|
||||
fail_compilation/diag14145.d(33): Error: expression `*this.ptr` of type `shared(int)` is not implicitly convertible to return type `ref int`
|
||||
fail_compilation/diag14145.d(14): Error: template instance `diag14145.main.Capture!(i).Capture.opDispatch!"i"` error instantiating
|
||||
---
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
TEST_OUTPUT:
|
||||
---
|
||||
fail_compilation/fail18970.d(26): Error: no property `y` for `S()` of type `fail18970.S`
|
||||
fail_compilation/fail18970.d(26): potentially malformed `opDispatch`. Use an explicit instantiation to get a better error message
|
||||
fail_compilation/fail18970.d(15): struct `S` defined here
|
||||
fail_compilation/fail18970.d(19): Error: undefined identifier `x`
|
||||
fail_compilation/fail18970.d(26): Error: template instance `fail18970.S.opDispatch!"y"` error instantiating
|
||||
fail_compilation/fail18970.d(33): Error: no property `yyy` for `this` of type `fail18970.S2`
|
||||
fail_compilation/fail18970.d(33): potentially malformed `opDispatch`. Use an explicit instantiation to get a better error message
|
||||
fail_compilation/fail18970.d(29): struct `S2` defined here
|
||||
fail_compilation/fail18970.d(38): Error: undefined identifier `x`
|
||||
fail_compilation/fail18970.d(33): Error: template instance `fail18970.S2.opDispatch!"yyy"` error instantiating
|
||||
---
|
||||
*/
|
||||
|
||||
|
|
|
@ -3,12 +3,10 @@
|
|||
/*
|
||||
TEST_OUTPUT:
|
||||
---
|
||||
fail_compilation/fail22054.d(23): Error: no property `what` for type `fail22054.exception`
|
||||
fail_compilation/fail22054.d(18): `class fail22054.exception` is opaque and has no members.
|
||||
fail_compilation/fail22054.d(18): class `exception` defined here
|
||||
fail_compilation/fail22054.d(24): Error: no property `what` for type `fail22054.exception2`
|
||||
fail_compilation/fail22054.d(19): `struct fail22054.exception2` is opaque and has no members.
|
||||
fail_compilation/fail22054.d(19): struct `exception2` defined here
|
||||
fail_compilation/fail22054.d(21): Error: no property `what` for type `fail22054.exception`
|
||||
fail_compilation/fail22054.d(16): `class fail22054.exception` is opaque and has no members.
|
||||
fail_compilation/fail22054.d(22): Error: no property `what` for type `fail22054.exception2`
|
||||
fail_compilation/fail22054.d(17): `struct fail22054.exception2` is opaque and has no members.
|
||||
---
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
TEST_OUTPUT:
|
||||
---
|
||||
fail_compilation/ice10938.d(14): Error: no property `opts` for `this` of type `ice10938.C`
|
||||
fail_compilation/ice10938.d(14): potentially malformed `opDispatch`. Use an explicit instantiation to get a better error message
|
||||
fail_compilation/ice10938.d(10): class `C` defined here
|
||||
fail_compilation/ice10938.d(19): Error: forward reference to inferred return type of function call `this.opDispatch()`
|
||||
fail_compilation/ice10938.d(14): Error: template instance `ice10938.C.opDispatch!"opts"` error instantiating
|
||||
---
|
||||
*/
|
||||
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
* TEST_OUTPUT:
|
||||
---
|
||||
fail_compilation/test16188.d(101): Error: no property `name` for `Where()` of type `test16188.Where`
|
||||
fail_compilation/test16188.d(101): potentially malformed `opDispatch`. Use an explicit instantiation to get a better error message
|
||||
fail_compilation/test16188.d(103): struct `Where` defined here
|
||||
fail_compilation/test16188.d(107): Error: undefined identifier `getMember`
|
||||
fail_compilation/test16188.d(101): Error: template instance `test16188.Where.opDispatch!"name"` error instantiating
|
||||
---
|
||||
*/
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue