Skip to content

Commit

Permalink
fix: reverted original changes but still left some changes to the Sim…
Browse files Browse the repository at this point in the history
…pleLiteral

Vararg generics are just not the way to go in Java and the code was not working when you'd use it as expected. The original changes were therefore reverted, but there was still a small change left in the SimpleLiteral class.
  • Loading branch information
Mwexim committed Jan 1, 2024
1 parent 961a60d commit fb52ceb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,18 @@
public class SimpleLiteral<T> implements Literal<T> {

private boolean isAndList = true;
private Class<T> returnType;
private final Class<T> returnType;
private final T[] values;

@SafeVarargs
public SimpleLiteral(T... values) {
public SimpleLiteral(T[] values) {
this.values = values;
this.returnType = (Class<T>) values.getClass().getComponentType();
}

@SafeVarargs
public SimpleLiteral(Class<T> c, T... values) {
this.values = Arrays.copyOf(values, values.length);
this.returnType = c;
}

@Override
Expand Down Expand Up @@ -62,11 +63,7 @@ public boolean isSingle() {
}

public Class<? extends T> getReturnType() {
if (returnType != null) {
return returnType;
} else {
return returnType = (Class<T>) values.getClass().getComponentType();
}
return returnType;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ public class SyntaxParser {
* The pattern type representing {@link Object}
*/
// Gradle requires the cast, but IntelliJ considers it redundant
public static final PatternType<Object> OBJECT_PATTERN_TYPE = new PatternType<>(TypeManager.getByClass(Object.class).orElseThrow(AssertionError::new), true);
public static final PatternType<Object> OBJECT_PATTERN_TYPE = new PatternType<>((Type<Object>) TypeManager.getByClass(Object.class).orElseThrow(AssertionError::new), true);

// Gradle requires the cast, but IntelliJ considers it redundant
public static final PatternType<Object> OBJECTS_PATTERN_TYPE = new PatternType<>(TypeManager.getByClass(Object.class).orElseThrow(AssertionError::new), false);
public static final PatternType<Object> OBJECTS_PATTERN_TYPE = new PatternType<>((Type<Object>) TypeManager.getByClass(Object.class).orElseThrow(AssertionError::new), false);


// We control input, so new SkriptLogger instance is fine
Expand Down Expand Up @@ -532,7 +532,7 @@ public static <T> Optional<? extends Expression<? extends T>> parseLiteral(Strin
if (literalParser.isPresent()) {
var literal = literalParser.map(l -> (T) l.apply(s));
if (literal.isPresent() && expectedClass.isAssignableFrom(c)) {
return Optional.of(new SimpleLiteral<>(literal.get()));
return Optional.of(new SimpleLiteral<>((Class<T>) literal.get().getClass(), literal.get()));
} else if (literal.isPresent()) {
return new SimpleLiteral<>((Class<T>) c, literal.get()).convertExpression(expectedType.getType().getTypeClass());
}
Expand Down

0 comments on commit fb52ceb

Please sign in to comment.