-
-
Notifications
You must be signed in to change notification settings - Fork 390
EffOperations #7764
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev/feature
Are you sure you want to change the base?
EffOperations #7764
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i will look more closely later
src/main/java/org/skriptlang/skript/lang/arithmetic/Arithmetics.java
Outdated
Show resolved
Hide resolved
@@ -0,0 +1,68 @@ | |||
test "operations numbers": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs tests where both values are variables, where the other value is not a valid option, where the value is a variable with an invalid type, etc. Edge cases need to be covered.
src/main/java/org/skriptlang/skript/lang/arithmetic/Arithmetics.java
Outdated
Show resolved
Hide resolved
src/main/java/org/skriptlang/skript/lang/arithmetic/Arithmetics.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
everything else looks good, though there might be an opportunity for optimization if the left expression has a return value that exactly matches an operation, then you wouldn't have to do lookups during the function. Optional, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are some initial things I noticed
Operator operator, | ||
Class<L> leftClass, | ||
Class<R> rightClass, | ||
Class<?> ... possibleReturnTypes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Class<?> ... possibleReturnTypes | |
Class<?>... possibleReturnTypes |
OperationInfo<L, R, ?> info = lookupOperationInfo(operator, leftClass, rightClass); | ||
if (info == null) | ||
return null; | ||
for (Class<?> returnType : possibleReturnTypes) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably want to first check that the return type of the operation info is not one of possibleReturnTypes
. That is, we want to avoid converting if possible.
if (leftType.isArray()) | ||
leftType = leftType.getComponentType(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't think this is necessary
// for 'left's acceptedClasses | ||
Class<?>[] allReturnTypes = Arithmetics.getAllReturnTypes(operator).toArray(Class[]::new); | ||
if (!ChangerUtils.acceptsChangeTypes(leftAccepts, allReturnTypes)) { | ||
Skript.error(left + " cannot be " + getOperatorName() + "."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skript.error(left + " cannot be " + getOperatorName() + "."); | |
Skript.error(left.toString(null, Skript.debug()) + " cannot be " + getOperatorName() + "."); |
It is not guaranteed that regular toString
will return a readable result for an expression.
return false; | ||
} | ||
return LiteralUtils.canInitSafely(right); | ||
} else if (leftType.equals(Object.class) || rightType.equals(Object.class)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would appreciate further docs for what is being done here
Description
This PR aims to add effects for multiplication, division and exponentiation operations, allowing users to perform an arithmetic operation on an variable, single or list. Rather than doing, for example
set {_int} to {_int} * 2
Does not work for literals.
Target Minecraft Versions: any
Requirements: none
Related Issues: #7763