diff --git a/compiler/src/dmd/expressionsem.d b/compiler/src/dmd/expressionsem.d index 9368b0c850..7488119fc7 100644 --- a/compiler/src/dmd/expressionsem.d +++ b/compiler/src/dmd/expressionsem.d @@ -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; @@ -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(); + } if (err) return setError(); diff --git a/compiler/test/fail_compilation/test16443.d b/compiler/test/fail_compilation/test16443.d new file mode 100644 index 0000000000..a83dc53bbe --- /dev/null +++ b/compiler/test/fail_compilation/test16443.d @@ -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; +}