fix bugzilla Issue 16643 - CTFE internal error with null

This commit is contained in:
Walter Bright 2024-09-26 08:41:10 -07:00 committed by Nicholas Wilson
parent 17ee13030f
commit e04ca660f7
2 changed files with 19 additions and 1 deletions

View file

@ -12202,7 +12202,8 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
return; return;
} }
if (tb1.ty == Tpointer && tb2.ty == Tpointer) if (tb1.ty == Tpointer && tb2.ty == Tpointer ||
tb1.ty == Tnull && tb2.ty == Tnull)
{ {
result = exp.incompatibleTypes(); result = exp.incompatibleTypes();
return; return;
@ -12299,6 +12300,11 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
{ {
err |= exp.e2.checkArithmetic(exp.op) || exp.e2.checkSharedAccess(sc); err |= exp.e2.checkArithmetic(exp.op) || exp.e2.checkSharedAccess(sc);
} }
if (t1.ty == Tnull && t2.ty == Tnull)
{
exp.incompatibleTypes();
return setError();
}
if (err) if (err)
return setError(); return setError();

View file

@ -0,0 +1,12 @@
/* TEST_OUTPUT:
---
fail_compilation/test16443.d(10): Error: incompatible types for `(null) + (null)`: both operands are of type `typeof(null)`
fail_compilation/test16443.d(11): Error: incompatible types for `(null) - (null)`: both operands are of type `typeof(null)`
---
*/
void foo()
{
auto a = null + null;
auto b = null - null;
}