Skip to content

Commit 8b0bdc3

Browse files
authored
Fix bugzilla 24731 - IFTI cannot handle integer expressions (dlang/dmd!16822)
1 parent cf38499 commit 8b0bdc3

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

dmd/dtemplate.d

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,9 @@ MATCH deduceType(RootObject o, Scope* sc, Type tparam, ref TemplateParameters pa
16981698
edim = s ? getValue(s) : getValue(e);
16991699
}
17001700
}
1701-
if (tp && tp.matchArg(sc, t.dim, i, &parameters, dedtypes, null) || edim && edim.toInteger() == t.dim.toInteger())
1701+
if ((tp && tp.matchArg(sc, t.dim, i, &parameters, dedtypes, null)) ||
1702+
(edim && edim.isIntegerExp() && edim.toInteger() == t.dim.toInteger())
1703+
)
17021704
{
17031705
result = deduceType(t.next, sc, tparam.nextOf(), parameters, dedtypes, wm);
17041706
return;

dmd/expression.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ extern (C++) abstract class Expression : ASTNode
474474
dinteger_t toInteger()
475475
{
476476
//printf("Expression %s\n", EXPtoString(op).ptr);
477-
if (!type.isTypeError())
477+
if (!type || !type.isTypeError())
478478
error(loc, "integer constant expression expected instead of `%s`", toChars());
479479
return 0;
480480
}

tests/dmd/runnable/ifti.d

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,20 @@ class Tst(TST, int v = 2) {
7272

7373
class Y : Tst!(float) {}
7474

75+
// https://issues.dlang.org/show_bug.cgi?id=24731
76+
void test24731()
77+
{
78+
static int solve(size_t N)(ref double[N+1][N])
79+
{
80+
return N;
81+
}
82+
83+
double[3][2] m;
84+
assert(solve(m) == 2);
85+
assert(solve!2(m) == 2);
86+
}
87+
88+
7589
void main() {
7690
Tst!(int) t = new Tst!(int);
7791
Y u = new Y;
@@ -113,4 +127,5 @@ void main() {
113127
printf("%g\n", i);
114128
}
115129

130+
test24731();
116131
}

0 commit comments

Comments
 (0)