Skip to content

Commit

Permalink
fix bugzilla Issue 16643 - CTFE internal error with null
Browse files Browse the repository at this point in the history
  • Loading branch information
WalterBright committed Sep 26, 2024
1 parent 17ee130 commit 824aa46
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion compiler/src/dmd/expressionsem.d
Original file line number Diff line number Diff line change
Expand Up @@ -12202,7 +12202,8 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
return;
}

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

Check warning on line 12306 in compiler/src/dmd/expressionsem.d

View check run for this annotation

Codecov / codecov/patch

compiler/src/dmd/expressionsem.d#L12305-L12306

Added lines #L12305 - L12306 were not covered by tests
}
if (err)
return setError();

Expand Down
12 changes: 12 additions & 0 deletions compiler/test/fail_compilation/test16443.d
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 824aa46

Please sign in to comment.