Bug 17222 – assert in compiler caused by opDispatch

Status
RESOLVED
Resolution
WORKSFORME
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2017-02-24T18:17:34Z
Last change time
2022-11-16T15:38:05Z
Keywords
ice, patch
Assigned to
No Owner
Creator
John Colvin

Comments

Comment #0 by john.loughran.colvin — 2017-02-24T18:17:34Z
Dustmite reduced from a slightly modified phobos, testing with a debug build of dmd git HEAD: template AliasSeq() { } template Proxy(alias a) { template opDispatch(string name) { static if (__traits(isTemplate, mixin("a."~name))) template opDispatch(T ...) { alias opDispatch = AliasSeq!(mixin("a."~name~"!(T)")); } } } unittest { class Foo { T ifti1(T)(T) { } } class Hoge { Foo foo; mixin Proxy!foo; } Hoge.ifti1; } $ dmd -unittest std/typecons.d [email protected](714): Assertion failure ---------------- ??:? _d_assert [0x717377] ??:? void ddmd.dinterpret.__assert(int) [0x54cf7e] ??:? _Z13ctfeInterpretP10Expression [0x53b395] ??:? _ZN10Expression13ctfeInterpretEv [0x581288] ??:? _ZN16TemplateInstance14semanticTiargsE3LocP5ScopeP5ArrayIP10RootObjectEi [0x57188b] ??:? _ZN16TemplateInstance14semanticTiargsEP5Scope [0x571c8d] ??:? _ZN16TemplateInstance8semanticEP5ScopeP5ArrayIP10ExpressionE [0x56f0f0] ??:? _ZN16TemplateInstance8semanticEP5Scope [0x56fedf] ??:? _ZN12TypeInstance7resolveE3LocP5ScopePP10ExpressionPP4TypePP7Dsymbolb [0x5eab95] ??:? _ZN12TypeInstance9toDsymbolEP5Scope [0x5ead85] ??:? _ZN16AliasDeclaration13aliasSemanticEP5Scope [0x530274] ??:? _ZN16AliasDeclaration8semanticEP5Scope [0x530049] ??:? _ZN16TemplateInstance13expandMembersEP5Scope [0x5739c1] ??:? _ZN16TemplateInstance16tryExpandMembersEP5Scope [0x573a36] ??:? _ZN16TemplateInstance8semanticEP5ScopeP5ArrayIP10ExpressionE [0x56f7c7] ??:? int ddmd.dtemplate.functionResolve(ddmd.declaration.Match*, ddmd.dsymbol.Dsymbol, ddmd.globals.Loc, ddmd.dscope.Scope*, ddmd.root.array.Array!(ddmd.root.rootobject.RootObject).Array*, ddmd.mtype.Type, ddmd.root.array.Array!(ddmd.expression.Expression).Array*).applyTemplate(ddmd.dtemplate.TemplateDeclaration) [0x5676df] ??:? int ddmd.dtemplate.functionResolve(ddmd.declaration.Match*, ddmd.dsymbol.Dsymbol, ddmd.globals.Loc, ddmd.dscope.Scope*, ddmd.root.array.Array!(ddmd.root.rootobject.RootObject).Array*, ddmd.mtype.Type, ddmd.root.array.Array!(ddmd.expression.Expression).Array*).__lambda10(ddmd.dsymbol.Dsymbol) [0x5681aa] ??:? int ddmd.func.overloadApply(ddmd.dsymbol.Dsymbol, scope int delegate(ddmd.dsymbol.Dsymbol)) [0x5b0bbf] ??:? void ddmd.dtemplate.functionResolve(ddmd.declaration.Match*, ddmd.dsymbol.Dsymbol, ddmd.globals.Loc, ddmd.dscope.Scope*, ddmd.root.array.Array!(ddmd.root.rootobject.RootObject).Array*, ddmd.mtype.Type, ddmd.root.array.Array!(ddmd.expression.Expression).Array*) [0x566d69] ??:? _Z15resolveFuncCall3LocP5ScopeP7DsymbolP5ArrayIP10RootObjectEP4TypePS4_IP10ExpressionEi [0x5b0e94] ??:? _Z18resolvePropertiesXP5ScopeP10ExpressionS2_ [0x57a0ac] ??:? _Z17resolvePropertiesP5ScopeP10Expression [0x57a4de] ??:? _ZN24StatementSemanticVisitor5visitEP12ExpStatement [0x61ea81] ??:? _ZN12ExpStatement6acceptEP7Visitor [0x6132b9] ??:? ddmd.statement.Statement ddmd.statementsem.semantic(ddmd.statement.Statement, ddmd.dscope.Scope*) [0x62c242] ??:? _ZN24StatementSemanticVisitor5visitEP17CompoundStatement [0x61ed05] ??:? _ZN17CompoundStatement6acceptEP7Visitor [0x613a31] ??:? ddmd.statement.Statement ddmd.statementsem.semantic(ddmd.statement.Statement, ddmd.dscope.Scope*) [0x62c242] ??:? _ZN15FuncDeclaration9semantic3EP5Scope [0x5aa12f] ??:? _ZN6Module9semantic3EP5Scope [0x552781] ??:? int ddmd.mars.tryMain(ulong, const(char)**) [0x5d9a2f] ??:? _Dmain [0x5da6f6] ??:? _D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv [0x7190be] ??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x719004] ??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).runAll() [0x71907a] ??:? void rt.dmain2._d_run_main(int, char**, extern (C) int function(char[][])*).tryExec(scope void delegate()) [0x719004] ??:? _d_run_main [0x718f7e] ??:? main [0x5dae97] ??:? __libc_start_main [0xe3f0c290]
Comment #1 by b2.temp — 2019-12-12T02:29:17Z
reduced a bit more: --- template AliasSeq() { } template Proxy(alias a) { template opDispatch(string name, T...) { alias Dummy = AliasSeq!(mixin("a."~name~"!(T)")); } } class Foo { T ifti1(T)(T) { } } static class Hoge { Foo foo; mixin Proxy!foo; } void main() { Hoge.ifti1; } --- The problem seems to be that there's an attempt to alias an expression but the error does not prevent the semantic of: alias Dummy = AliasSeq!(mixin("a."~name~"!(T)")); to stop early because we're in a opDispatch which is infamously known for the problems it creates by ignoring errors.
Comment #2 by b2.temp — 2019-12-12T02:31:57Z
patch: --- diff --git a/src/dmd/dinterpret.d b/src/dmd/dinterpret.d index 28911bc19..22ea4927e 100644 --- a/src/dmd/dinterpret.d +++ b/src/dmd/dinterpret.d @@ -80,9 +80,9 @@ public Expression ctfeInterpret(Expression e) break; } - assert(e.type); // https://issues.dlang.org/show_bug.cgi?id=14642 - //assert(e.type.ty != Terror); // FIXME - if (e.type.ty == Terror) + // https://issues.dlang.org/show_bug.cgi?id=14642 + // https://issues.dlang.org/show_bug.cgi?id=17222 + if (e.type && e.type.ty == Terror) --- It seems that the assertion on the expression type is not relevant anymore. In the present case, the exp has not type and is a "dotTemplateInstance", for which the InterpreterClass don't access the type.
Comment #3 by razvan.nitu1305 — 2022-11-16T15:38:05Z
This now yields: test.d-mixin-10(10): Error: template instance `ifti1!()` does not match template declaration `ifti1(T)(T)` test.d(27): Error: template instance `test.__unittest_L15_C1.Hoge.Proxy!(foo).opDispatch!"ifti1".opDispatch!()` error instantiating test.d(27): Error: `opDispatch(T...)` has no effect Closing as worksforme.