Bug 18136 – ICE in dmd/statement.d(426)

Status
RESOLVED
Resolution
WORKSFORME
Severity
major
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
All
Creation time
2017-12-28T00:49:20Z
Last change time
2020-03-21T03:56:34Z
Keywords
ice
Assigned to
No Owner
Creator
Seb

Comments

Comment #0 by greensunny12 — 2017-12-28T00:49:20Z
``` void main() { import std.regex; import std.algorithm : joiner, map; string[] messages; auto matchToRefs(M)(M m) { return m.captures[0].splitter(regex(`foo`)); } auto issueRE = regex("foo"); messages.map!( m => m.matchAll(issueRE) .map!matchToRefs ).joiner; } ``` Stacktrace: ``` core.exception.AssertError@dmd/statement.d(426): Assertion failure ---------------- ??:? _d_assert [0xce1a2ef0] ??:? void dmd.statement.__assert(int) [0xce09fba2] ??:? dmd.statement.ErrorStatement dmd.statement.ErrorStatement.__ctor() [0xce09b4a7] ??:? _ZN16Semantic3Visitor5visitEP15FuncDeclaration [0xcdfd15c0] ??:? _ZN16ParseTimeVisitorI10ASTCodegenE5visitEP22FuncLiteralDeclaration [0xce0a9459] ??:? _ZN22FuncLiteralDeclaration6acceptEP7Visitor [0xce02c568] ??:? _Z9semantic3P7DsymbolP5Scope [0xce09a2e0] ??:? _ZN25ExpressionSemanticVisitor5visitEP7FuncExp [0xce00f3ae] ??:? _ZN7FuncExp6acceptEP7Visitor [0xce001c20] ??:? _Z18expressionSemanticP10ExpressionP5Scope [0xce023716] ??:? _ZN10TypeTypeof7resolveE3LocP5ScopePP10ExpressionPP4TypePP7Dsymbolb [0xce072c7e] ??:? _ZN19TypeSemanticVisitor5visitEP10TypeTypeof [0xce0a3e20] ??:? _ZN10TypeTypeof6acceptEP7Visitor [0xce072fb0] ??:? _Z12typeSemanticP4Type3LocP5Scope [0xce0a0c22] ??:? _ZN4Type11trySemanticE3LocP5Scope [0xce06795b] ??:? _ZN25ExpressionSemanticVisitor5visitEP5IsExp [0xce0139f7] ??:? _ZN5IsExp6acceptEP7Visitor [0xce002118] ??:? _Z18expressionSemanticP10ExpressionP5Scope [0xce023716] ??:? _ZN25ExpressionSemanticVisitor5visitEP10LogicalExp [0xce021647] ??:? _ZN10LogicalExp6acceptEP7Visitor [0xce006500] ??:? _Z18expressionSemanticP10ExpressionP5Scope [0xce023716] ??:? _ZN25ExpressionSemanticVisitor5visitEP10LogicalExp [0xce021535] ??:? _ZN10LogicalExp6acceptEP7Visitor [0xce006500] ??:? _Z18expressionSemanticP10ExpressionP5Scope [0xce023716] ??:? _ZN25ExpressionSemanticVisitor5visitEP10LogicalExp [0xce021535] ??:? _ZN10LogicalExp6acceptEP7Visitor [0xce006500] ??:? _Z18expressionSemanticP10ExpressionP5Scope [0xce023716] ??:? _ZN22DsymbolSemanticVisitor5visitEP14VarDeclaration [0xcdfd6a35] ??:? _ZN14VarDeclaration6acceptEP7Visitor [0xcdfa3998] ??:? _Z15dsymbolSemanticP7DsymbolP5Scope [0xcdfcee08] ??:? _ZN16TemplateInstance13expandMembersEP5Scope [0xcdff36eb] ??:? _ZN16TemplateInstance16tryExpandMembersEP5Scope [0xcdff3762] ??:? void dmd.dsymbolsem.templateInstanceSemantic(dmd.dtemplate.TemplateInstance, dmd.dscope.Scope*, dmd.root.array.Array!(dmd.expression.Expression).Array*) [0xcdfe256b] ```
Comment #1 by greeenify — 2018-03-15T22:05:34Z
From Slack by @LemonBoy > @wilzbach, 18136 is easy to fix, you just need to check out `visit(FuncDeclaration funcdecl)' in semantic3.d where it calls f.checkRetType. It seems you must call something that increases `global.errors` first such as `error()` before you're able to construct an ErrorStatement instance. At the moment this triggers a different error in Phobos, so it would require a bit of work to reproduce it again as the underlying phobos code apparently changed. https://run.dlang.io/is/w3u6Oz
Comment #2 by greensunny12 — 2018-04-04T11:50:19Z
Reduced example without Phobos: --- template ReturnType(func...) { static if (is(FunctionTypeOf!func R )) alias ReturnType = R; } template FunctionTypeOf(func...) { static if (is(typeof(func) T)) static if (is(T Fptr ) ) alias FunctionTypeOf = Fptr; } enum isInputRange(R) = is(ReturnType!((R r) => r.empty) ) && is(typeof((R r) => r.popFront)); @property empty(T)(const(T) ){} void popFront(T)(T) {} template unaryFun(alias fun) { alias unaryFun = fun; } template map(fun...) { auto map(Range)(Range ) if (isInputRange!Range) { alias RE = Range; alias _fun = unaryFun!fun; !is(typeof(_fun(RE.init)) ); } } auto joiner(){} struct RegexMatch(R) { void popFront(){} bool empty() { } } auto matchMany(RegEx, R)(R , RegEx ) { return RegexMatch!R(); } auto matchAll(R, RegEx)(R input, RegEx re) { return matchMany(input, re); } void main() { string[] messages; auto issueRE = "foo"; messages.map!(m => m.matchAll(issueRE).map); } ---
Comment #3 by b2.temp — 2019-07-05T13:40:53Z
this doesn't crash anymore.