mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 13:10:12 +03:00
Fix Issue 16213 - CTFE internal error with static array $ as template argument (#14964)
This commit is contained in:
parent
9e3e295d8c
commit
23514c6256
2 changed files with 25 additions and 4 deletions
|
@ -2162,10 +2162,23 @@ extern (C++) final class ArrayScopeSymbol : ScopeDsymbol
|
|||
* or a variable (in which case an expression is created in
|
||||
* toir.c).
|
||||
*/
|
||||
auto e = new VoidInitializer(Loc.initial);
|
||||
e.type = Type.tsize_t;
|
||||
v = new VarDeclaration(loc, Type.tsize_t, Id.dollar, e);
|
||||
v.storage_class |= STC.temp | STC.ctfe; // it's never a true static variable
|
||||
|
||||
// https://issues.dlang.org/show_bug.cgi?id=16213
|
||||
// For static arrays $ is known at compile time,
|
||||
// so declare it as a manifest constant.
|
||||
auto tsa = ce.type ? ce.type.isTypeSArray() : null;
|
||||
if (tsa)
|
||||
{
|
||||
auto e = new ExpInitializer(loc, tsa.dim);
|
||||
v = new VarDeclaration(loc, tsa.dim.type, Id.dollar, e, STC.manifest);
|
||||
}
|
||||
else
|
||||
{
|
||||
auto e = new VoidInitializer(Loc.initial);
|
||||
e.type = Type.tsize_t;
|
||||
v = new VarDeclaration(loc, Type.tsize_t, Id.dollar, e);
|
||||
v.storage_class |= STC.temp | STC.ctfe; // it's never a true static variable
|
||||
}
|
||||
}
|
||||
*pvar = v;
|
||||
}
|
||||
|
|
8
compiler/test/compilable/test16213.d
Normal file
8
compiler/test/compilable/test16213.d
Normal file
|
@ -0,0 +1,8 @@
|
|||
// https://issues.dlang.org/show_bug.cgi?id=16213
|
||||
|
||||
enum Id(size_t i) = i;
|
||||
void main()
|
||||
{
|
||||
int[5] y;
|
||||
y[ Id!($) - 1 ] = 3;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue