Skip to content
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

Fix expression conversion #7165

Open
wants to merge 9 commits into
base: dev/patch
Choose a base branch
from
18 changes: 14 additions & 4 deletions src/main/java/ch/njol/skript/lang/SkriptParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -371,8 +371,13 @@ private <T> Expression<? extends T> parseSingleExpr(boolean allowUnparsedLiteral
for (Class<? extends T> type : types) {
// Check return type against everything that expression accepts
if (parsedExpression.canReturn(type)) {
log.printLog();
return (Expression<? extends T>) parsedExpression;
Expression<? extends T> convertedExpression = parsedExpression.getConvertedExpression(type);
if (convertedExpression != null) {
log.printLog();
return convertedExpression;
}
log.printError(parsedExpression.toString(null, false) + " " + Language.get("is") + " " + notOfType(type), ErrorQuality.NOT_AN_EXPRESSION);
return null;
UnderscoreTud marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down Expand Up @@ -556,8 +561,13 @@ private Expression<?> parseSingleExpr(boolean allowUnparsedLiteral, @Nullable Lo
return null;
}

log.printLog();
return parsedExpression;
Expression<?> convertedExpression = parsedExpression.getConvertedExpression(type);
if (convertedExpression != null) {
log.printLog();
return convertedExpression;
}
log.printError(parsedExpression.toString(null, false) + " " + Language.get("is") + " " + notOfType(type), ErrorQuality.NOT_AN_EXPRESSION);
return null;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
test "expressions sometimes dont convert":
assert formatted ({_foo} + {_bar}) is not set with "formatting nothing shouldn't throw an error"

set {_foo} to "test"
assert formatted ({_foo} + {_bar}) is not set with "formatting string + none shouldn't throw an error"

set {_foo} to 1
set {_bar} to 2
assert formatted ({_foo} + {_bar}) is not set with "formatting number + number shouldn't throw an error"

set {_foo} to "foo"
set {_bar} to "bar"
assert formatted ({_foo} + {_bar}) is "foobar" with "formatting strings doesn't work"