www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 16213] New: CTFE internal error with static array $ as

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

          Issue ID: 16213
           Summary: CTFE internal error with static array $ as template
                    argument
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: kirsybuu gmail.com

Linux 64-bit DMD 2.072.0-devel-8ed6966-dirty DEBUG

enum Id(size_t i) = i;
void main() {
    int[5] y;
    y[ Id!($) - 1 ] = 3;
}
un_init_dollar.d(4): Error: CTFE internal error: trying to access uninitialized
var
core.exception.AssertError dinterpret.d(2353): Assertion failure
----------------
??:? _d_assert [0x707f67]
??:? void ddmd.dinterpret.__assert(int) [0x5322ff]
dinterpret.d:2353
_ZN11Interpreter9getVarExpE3LocP10InterStateP11Declaration8CtfeGoal [0x523ba2]
dinterpret.d:2455 _ZN11Interpreter5visitEP6VarExp [0x5240b9]
expression.d:6669 _ZN6VarExp6acceptEP7Visitor [0x56fac9]
dinterpret.d:6304 _Z9interpretP10ExpressionP10InterState8CtfeGoal [0x52fab3]
dinterpret.d:723 _Z13ctfeInterpretP10Expression [0x51ffc3]
expression.d:3459 _ZN10Expression13ctfeInterpretEv [0x566e84]
dtemplate.d:5399
_ZN22TemplateValueParameter8matchArgEP5ScopeP10RootObjectmP5ArrayIP17TemplateParameterEPS4_IS3_EPP11Declaration
[0x554200]
dtemplate.d:5006
_ZN17TemplateParameter8matchArgE3LocP5ScopeP5ArrayIP10RootObjectEmPS3_IPS_ES7_PP11Declaration
[0x5534b8]
dtemplate.d:893
_ZN19TemplateDeclaration17matchWithInstanceEP5ScopeP16TemplateInstanceP5ArrayIP10RootObjectEPS4_IP10ExpressionEi
[0x54905b]
dtemplate.d:7574
_D4ddmd9dtemplate16TemplateInstance13findBestMatchMRPS4ddmd6dscope5ScopePS4ddmd4root5array41__T5ArrayTC4ddmd10expression10ExpressionZ5ArrayZ9__lambda3MFC4ddmd7dsymbol7DsymbolZi
[0x559204]
func.d:4052 int ddmd.func.overloadApply(ddmd.dsymbol.Dsymbol, scope int
delegate(ddmd.dsymbol.Dsymbol)) [0x597f96]
dtemplate.d:7559
_ZN16TemplateInstance13findBestMatchEP5ScopeP5ArrayIP10ExpressionE [0x558ade]
dtemplate.d:6058 _ZN16TemplateInstance8semanticEP5ScopeP5ArrayIP10ExpressionE
[0x555ad3]
dtemplate.d:6527 _ZN16TemplateInstance8semanticEP5Scope [0x5569c3]
expression.d:5776 _ZN8ScopeExp8semanticEP5Scope [0x56cc7b]
expression.d:7877 _ZN6BinExp11binSemanticEP5Scope [0x572d06]
expression.d:7890 _ZN6BinExp15binSemanticPropEP5Scope [0x572d90]
expression.d:14031 _ZN6MinExp8semanticEP5Scope [0x586ed6]
expression.d:12191 _ZN8IndexExp8semanticEP5Scope [0x581268]
opover.d:652 _ZN11op_overload10OpOverload5visitEP8ArrayExp [0x5dc9de]
expression.d:11792 _ZN8ArrayExp6acceptEP7Visitor [0x5803d9]
opover.d:1522 _Z11op_overloadP10ExpressionP5Scope [0x5dbdfa]
expression.d:3477 _ZN10Expression11op_overloadEP5Scope [0x566ed4]
expression.d:11764 _ZN8ArrayExp8semanticEP5Scope [0x58029c]
expression.d:12719 _ZN9AssignExp8semanticEP5Scope [0x582df6]
statementsem.d:92 _ZN24StatementSemanticVisitor5visitEP12ExpStatement
[0x60a8fb]
statement.d:1169 _ZN12ExpStatement6acceptEP7Visitor [0x5fd7f6]
statementsem.d:3409 ddmd.statement.Statement
ddmd.statementsem.semantic(ddmd.statement.Statement, ddmd.dscope.Scope*)
[0x618270]
statementsem.d:146 _ZN24StatementSemanticVisitor5visitEP17CompoundStatement
[0x60ab93]
statement.d:1346 _ZN17CompoundStatement6acceptEP7Visitor [0x5fe026]
statementsem.d:3409 ddmd.statement.Statement
ddmd.statementsem.semantic(ddmd.statement.Statement, ddmd.dscope.Scope*)
[0x618270]
func.d:1672 _ZN15FuncDeclaration9semantic3EP5Scope [0x5919dd]
dmodule.d:1047 _ZN6Module9semantic3Ev [0x537cf0]
mars.d:1397 int ddmd.mars.tryMain(ulong, const(char)**) [0x5c175a]
mars.d:1587 _Dmain [0x5c22ae]
??:? _D2rt6dmain211_d_run_mainUiPPaPUAAaZiZ6runAllMFZ9__lambda1MFZv [0x709fba]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int
function(char[][])*).tryExec(scope void delegate()) [0x709f04]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int
function(char[][])*).runAll() [0x709f76]
??:? void rt.dmain2._d_run_main(int, char**, extern (C) int
function(char[][])*).tryExec(scope void delegate()) [0x709f04]
??:? _d_run_main [0x709e75]
??:? main [0x5c27ff]
??:? __libc_start_main [0xbb2ff44]

Also fails in DMD 2.071.0, 2.070.0, 2.069.2, 2.069.0, 2.068.0, 2.067.1,
2.067.0, and 2.065.0.

The length of a static array is a compile-time constant, as 2.071.0 accepts the
code when using "y.length" instead of $, so $ should also be a compile-time
constant when using a static array or ct-compatible opDollar (such as enum
opDollar(size_t i) = 0).

--
Jun 27 2016