www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18266] New: ICE: should allow reusing identifier in

https://issues.dlang.org/show_bug.cgi?id=18266

          Issue ID: 18266
           Summary: ICE: should allow reusing identifier in declarations
                    in disjoint scopes in a function
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: critical
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: hsteoh quickfur.ath.cx

Code:

-------
void main() {
        foreach (i; 0 .. 10) {
                struct S {
                        int x;
                }
                auto s = S(i);
        }
        foreach (i; 11 .. 20) {
                struct S {
                        int y;
                }
                auto s = S(i);
        }
}
-------

Compiler output:

-------
test.d(9): Error: declaration S is already defined in another scope in main
core.exception.AssertError dmd/typesem.d(1257): Assertion failure
----------------
dmd() [0x63259f]
dmd(_ZN19TypeSemanticVisitor5visitEP10TypeStruct+0x8a) [0x631f3a]
dmd(_ZN10TypeStruct6acceptEP7Visitor+0x1d) [0x603965]
dmd(_Z12typeSemanticP4Type3LocP5Scope+0x4f) [0x62ec8f]
dmd(_ZN4Type7resolveE3LocP5ScopePP10ExpressionPPS_PP7Dsymbolb+0x26) [0x5f9bde]
dmd(_ZN25ExpressionSemanticVisitor5visitEP7TypeExp+0x5e) [0x5ad44e]
dmd(_ZN7TypeExp6acceptEP7Visitor+0x1d) [0x5a103d]
dmd(_Z18expressionSemanticP10ExpressionP5Scope+0x43) [0x5c344b]
dmd(dmd.expression.Expression dmd.expression.resolve(dmd.globals.Loc,
dmd.dscope.Scope*, dmd.dsymbol.Dsymbol, bool)+0x896) [0x5997f6]
dmd(_ZN25ExpressionSemanticVisitor5visitEP13IdentifierExp+0x410) [0x5ac060]
dmd(_ZN13IdentifierExp6acceptEP7Visitor+0x1d) [0x59eced]
dmd(_Z18expressionSemanticP10ExpressionP5Scope+0x43) [0x5c344b]
dmd(dmd.expression.Expression
dmd.expressionsem.unaSemantic(dmd.expression.UnaExp, dmd.dscope.Scope*)+0x1c)
[0x5c3294]
dmd(_ZN25ExpressionSemanticVisitor5visitEP7CallExp+0x903) [0x5b08b3]
dmd(_ZN7CallExp6acceptEP7Visitor+0x1d) [0x5a49ed]
dmd(_Z18expressionSemanticP10ExpressionP5Scope+0x43) [0x5c344b]
dmd(_ZN16InferTypeVisitor5visitEP14ExpInitializer+0x2c) [0x5df034]
dmd(_ZN14ExpInitializer6acceptEP7Visitor+0x1d) [0x5dccf5]
dmd(_Z9inferTypeP11InitializerP5Scope+0x40) [0x5dcfd0]
dmd(_ZN22DsymbolSemanticVisitor5visitEP14VarDeclaration+0x185) [0x575815]
dmd(_ZN14VarDeclaration6acceptEP7Visitor+0x1d) [0x5358b5]
dmd(_Z15dsymbolSemanticP7DsymbolP5Scope+0x3d) [0x574fd5]
dmd(_ZN25ExpressionSemanticVisitor5visitEP14DeclarationExp+0xba) [0x5b385a]
dmd(_ZN14DeclarationExp6acceptEP7Visitor+0x1d) [0x5a287d]
dmd(_Z18expressionSemanticP10ExpressionP5Scope+0x43) [0x5c344b]
dmd(_ZN24StatementSemanticVisitor5visitEP12ExpStatement+0x50) [0x63d790]
dmd(_ZN12ExpStatement6acceptEP7Visitor+0x1d) [0x62a03d]
dmd(_Z17statementSemanticP9StatementP5Scope+0x43) [0x63d6b3]
dmd(_ZN24StatementSemanticVisitor5visitEP17CompoundStatement+0xe8) [0x63da40]
dmd(_ZN17CompoundStatement6acceptEP7Visitor+0x1d) [0x62a7e5]
dmd(_Z17statementSemanticP9StatementP5Scope+0x43) [0x63d6b3]
dmd(dmd.statement.Statement
dmd.statementsem.semanticNoScope(dmd.statement.Statement,
dmd.dscope.Scope*)+0x82) [0x64b432]
dmd(_ZN24StatementSemanticVisitor5visitEP12ForStatement+0x3c2) [0x63ed02]
dmd(_ZN12ForStatement6acceptEP7Visitor+0x1d) [0x62b295]
dmd(_Z17statementSemanticP9StatementP5Scope+0x43) [0x63d6b3]
dmd(_ZN24StatementSemanticVisitor5visitEP17CompoundStatement+0xe8) [0x63da40]
dmd(_ZN17CompoundStatement6acceptEP7Visitor+0x1d) [0x62a7e5]
dmd(_Z17statementSemanticP9StatementP5Scope+0x43) [0x63d6b3]
dmd(_ZN24StatementSemanticVisitor5visitEP14ScopeStatement+0xdd) [0x63e51d]
dmd(_ZN14ScopeStatement6acceptEP7Visitor+0x1d) [0x62ac1d]
dmd(_Z17statementSemanticP9StatementP5Scope+0x43) [0x63d6b3]
dmd(_ZN24StatementSemanticVisitor5visitEP12ForStatement+0xfd) [0x63ea3d]
dmd(_ZN12ForStatement6acceptEP7Visitor+0x1d) [0x62b295]
dmd(_Z17statementSemanticP9StatementP5Scope+0x43) [0x63d6b3]
dmd(_ZN24StatementSemanticVisitor5visitEP21ForeachRangeStatement+0x134e)
[0x64451e]
dmd(_ZN21ForeachRangeStatement6acceptEP7Visitor+0x1d) [0x62b5e5]
dmd(_Z17statementSemanticP9StatementP5Scope+0x43) [0x63d6b3]
dmd(_ZN24StatementSemanticVisitor5visitEP17CompoundStatement+0xe8) [0x63da40]
dmd(_ZN17CompoundStatement6acceptEP7Visitor+0x1d) [0x62a7e5]
dmd(_Z17statementSemanticP9StatementP5Scope+0x43) [0x63d6b3]
dmd(_ZN16Semantic3Visitor5visitEP15FuncDeclaration+0x1217) [0x652077]
dmd(_ZN15FuncDeclaration6acceptEP7Visitor+0x1d) [0x5ca4e5]
dmd(_Z9semantic3P7DsymbolP5Scope+0x3d) [0x650a6d]
dmd(_ZN16Semantic3Visitor5visitEP6Module+0x6a) [0x650e12]
dmd(_ZN6Module6acceptEP7Visitor+0x1d) [0x55188d]
dmd(_Z9semantic3P7DsymbolP5Scope+0x3d) [0x650a6d]
dmd(int dmd.mars.tryMain(ulong, const(char)**)+0x20f5) [0x5f04ad]
dmd(_Dmain+0x27) [0x5f1487]
dmd(_D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv+0x1f)
[0x7338f7]
dmd(void rt.dmain2._d_run_main(int, char**, extern (C) int
function(char[][])*).tryExec(scope void delegate())+0x2a) [0x73384a]
dmd(void rt.dmain2._d_run_main(int, char**, extern (C) int
function(char[][])*).runAll()+0x30) [0x7338b0]
dmd(void rt.dmain2._d_run_main(int, char**, extern (C) int
function(char[][])*).tryExec(scope void delegate())+0x2a) [0x73384a]
dmd(_d_run_main+0x1dc) [0x7337c4]
dmd(main+0x14) [0x5f4dc4]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xea) [0x7fa22ecacf2a]
-------


While it's debatable whether or not reusing the same identifier in declarations
in disjoint sub-scopes should be allowed, the compiler ICE definitely is a bug
that needs to be fixed.

--
Jan 19