D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 18136 - ICE in dmd/statement.d(426)
Summary: ICE in dmd/statement.d(426)
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86_64 All
: P1 major
Assignee: No Owner
URL:
Keywords: ice
Depends on:
Blocks:
 
Reported: 2017-12-28 00:49 UTC by Seb
Modified: 2020-03-21 03:56 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Seb 2017-12-28 00:49:20 UTC
```
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 Seb 2018-03-15 22:05:34 UTC
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 Seb 2018-04-04 11:50:19 UTC
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 basile-z 2019-07-05 13:40:53 UTC
this doesn't crash anymore.