Skip to content

Commit

Permalink
Short-circuit checkArithmeticBin when lhs is an error
Browse files Browse the repository at this point in the history
  • Loading branch information
dkorpel authored and thewilsonator committed Jan 23, 2025
1 parent 8358e6d commit 279f305
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 28 deletions.
3 changes: 0 additions & 3 deletions compiler/src/dmd/dcast.d
Original file line number Diff line number Diff line change
Expand Up @@ -4144,9 +4144,6 @@ Expression typeCombine(BinExp be, Scope* sc)
return ErrorExp.get();
}

Type t1 = be.e1.type.toBasetype();
Type t2 = be.e2.type.toBasetype();

if (auto result = typeMerge(sc, be.op, be.e1, be.e2))
{
if (be.type is null)
Expand Down
11 changes: 8 additions & 3 deletions compiler/src/dmd/expression.d
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,13 @@ extern (C++) abstract class Expression : ASTNode
error(loc, msg, EXPtoString(op).ptr, toChars(), type.toChars());
return true;
}

// FIXME: Existing code relies on adding / subtracting types in typeof() expressions:
// alias I = ulong; alias U = typeof(I + 1u);
// https://github.com/dlang/dmd/issues/20763
if (op == EXP.add || op == EXP.min)
return false;

return checkValue();
}

Expand Down Expand Up @@ -3067,9 +3074,7 @@ extern (C++) abstract class BinExp : Expression

extern (D) final bool checkArithmeticBin()
{
bool r1 = e1.checkArithmetic(this.op);
bool r2 = e2.checkArithmetic(this.op);
return (r1 || r2);
return e1.checkArithmetic(this.op) || e2.checkArithmetic(this.op);
}

/*********************
Expand Down
28 changes: 12 additions & 16 deletions compiler/test/fail_compilation/fail10534.d
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail10534.d(28): Error: illegal operator `+` for `a` of type `int delegate()`
fail_compilation/fail10534.d(28): Error: illegal operator `+` for `b` of type `int delegate()`
fail_compilation/fail10534.d(29): Error: illegal operator `-` for `a` of type `int delegate()`
fail_compilation/fail10534.d(29): Error: illegal operator `-` for `b` of type `int delegate()`
fail_compilation/fail10534.d(30): Error: illegal operator `/` for `a` of type `int delegate()`
fail_compilation/fail10534.d(30): Error: illegal operator `/` for `b` of type `int delegate()`
fail_compilation/fail10534.d(31): Error: illegal operator `*` for `a` of type `int delegate()`
fail_compilation/fail10534.d(31): Error: illegal operator `*` for `b` of type `int delegate()`
fail_compilation/fail10534.d(36): Error: illegal operator `+` for `a` of type `int function()`
fail_compilation/fail10534.d(36): Error: illegal operator `+` for `b` of type `int function()`
fail_compilation/fail10534.d(37): Error: illegal operator `-` for `a` of type `int function()`
fail_compilation/fail10534.d(37): Error: illegal operator `-` for `b` of type `int function()`
fail_compilation/fail10534.d(38): Error: illegal operator `/` for `a` of type `int function()`
fail_compilation/fail10534.d(38): Error: illegal operator `/` for `b` of type `int function()`
fail_compilation/fail10534.d(39): Error: illegal operator `*` for `a` of type `int function()`
fail_compilation/fail10534.d(39): Error: illegal operator `*` for `b` of type `int function()`
fail_compilation/fail10534.d(24): Error: illegal operator `+` for `a` of type `int delegate()`
fail_compilation/fail10534.d(24): Error: illegal operator `+` for `b` of type `int delegate()`
fail_compilation/fail10534.d(25): Error: illegal operator `-` for `a` of type `int delegate()`
fail_compilation/fail10534.d(25): Error: illegal operator `-` for `b` of type `int delegate()`
fail_compilation/fail10534.d(26): Error: illegal operator `/` for `a` of type `int delegate()`
fail_compilation/fail10534.d(27): Error: illegal operator `*` for `a` of type `int delegate()`
fail_compilation/fail10534.d(32): Error: illegal operator `+` for `a` of type `int function()`
fail_compilation/fail10534.d(32): Error: illegal operator `+` for `b` of type `int function()`
fail_compilation/fail10534.d(33): Error: illegal operator `-` for `a` of type `int function()`
fail_compilation/fail10534.d(33): Error: illegal operator `-` for `b` of type `int function()`
fail_compilation/fail10534.d(34): Error: illegal operator `/` for `a` of type `int function()`
fail_compilation/fail10534.d(35): Error: illegal operator `*` for `a` of type `int function()`
---
*/

Expand Down
3 changes: 1 addition & 2 deletions compiler/test/fail_compilation/fail11445.d
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail11445.d(12): Error: illegal operator `+` for `a` of type `double[string]`
fail_compilation/fail11445.d(12): Error: illegal operator `+` for `b` of type `double[string]`
fail_compilation/fail11445.d(11): Error: illegal operator `+` for `a` of type `double[string]`
---
*/

Expand Down
3 changes: 1 addition & 2 deletions compiler/test/fail_compilation/fail297.d
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail297.d(31): Error: operator `+` is not defined for `Bar()` of type `Bar`
fail_compilation/fail297.d(31): Error: operator `+` is not defined for `baz()` of type `const(Bar)`
fail_compilation/fail297.d(30): Error: operator `+` is not defined for `Bar()` of type `Bar`
---
*/

Expand Down
3 changes: 1 addition & 2 deletions compiler/test/fail_compilation/fail3.d
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail3.d(42): Error: operator `+` is not defined for `a` of type `vec2`
fail_compilation/fail3.d(42): Error: operator `+` is not defined for `b` of type `vec2`
fail_compilation/fail3.d(41): Error: operator `+` is not defined for `a` of type `vec2`
---
*/

Expand Down

0 comments on commit 279f305

Please sign in to comment.