Skip to content

Commit 7445172

Browse files
Fix Uncommon Arithmetic Type Errors (#7907)
1 parent d885349 commit 7445172

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/main/java/ch/njol/skript/expressions/arithmetic/ArithmeticChain.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ public class ArithmeticChain<L, R, T> implements ArithmeticGettable<T> {
3434
private final ArithmeticGettable<R> right;
3535
private final Operator operator;
3636
private final Class<? extends T> returnType;
37-
@Nullable
38-
private OperationInfo<? extends L, ? extends R, ? extends T> operationInfo;
37+
private final @Nullable OperationInfo<? extends L, ? extends R, ? extends T> operationInfo;
3938

4039
public ArithmeticChain(ArithmeticGettable<L> left, Operator operator, ArithmeticGettable<R> right, @Nullable OperationInfo<L, R, T> operationInfo) {
4140
this.left = left;
@@ -63,6 +62,7 @@ public T get(Event event) {
6362
if (leftClass == Object.class && rightClass == Object.class)
6463
return null;
6564

65+
OperationInfo<? extends L, ? extends R, ? extends T> operationInfo = this.operationInfo;
6666
if (left == null && leftClass == Object.class) {
6767
operationInfo = lookupOperationInfo(rightClass, OperationInfo::getRight);
6868
} else if (right == null && rightClass == Object.class) {

src/test/skript/tests/syntaxes/expressions/ExprArithmetic.sk

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,18 @@ test "arithmetic return types":
263263
# however, we can get more specific return types by returning the superclass of the return types of all Object-Number operations
264264
set {_location} to location(0,10,0,"world")
265265
assert (y-coordinate of {_location} - 4) is 6 with "y-coordinate of {_location} - 4 is not 6 (got '%y-coordinate of {_location} - 4%')"
266+
267+
test "arithmetic type switcheroo":
268+
# operation info swap test
269+
set {_a} to 1
270+
set {_b} to 1
271+
loop 2 times:
272+
set {_x} to {_a} * {_b}
273+
assert {_x} is set with "Failed to get a result"
274+
set {_b} to a random vector
275+
276+
# operation info trick test
277+
set {_a} to "Hello"
278+
loop 2 times:
279+
set {_x} to {_a} + {_b}
280+
set {_b} to 5

0 commit comments

Comments
 (0)