Skip to content

Commit

Permalink
Fix some type conversion bugs (#1747)
Browse files Browse the repository at this point in the history
  • Loading branch information
bensku committed Dec 19, 2018
1 parent 7b059fd commit 4088ce1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/main/java/ch/njol/skript/classes/Converter.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;

import ch.njol.skript.Skript;
import ch.njol.skript.registrations.Converters;

/**
Expand Down
25 changes: 24 additions & 1 deletion src/main/java/ch/njol/skript/expressions/ExprXOf.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
*/
package ch.njol.skript.expressions;

import java.util.Arrays;

import org.bukkit.event.Event;
import org.bukkit.inventory.ItemStack;
import org.eclipse.jdt.annotation.Nullable;
Expand All @@ -34,7 +36,9 @@
import ch.njol.skript.lang.Expression;
import ch.njol.skript.lang.ExpressionType;
import ch.njol.skript.lang.Literal;
import ch.njol.skript.lang.Variable;
import ch.njol.skript.lang.SkriptParser.ParseResult;
import ch.njol.skript.lang.util.ConvertedExpression;
import ch.njol.util.Kleenean;

/**
Expand Down Expand Up @@ -69,7 +73,7 @@ public Class<? extends Object> getReturnType() {

@Override
protected Object[] get(final Event e, final Object[] source) {
return get(source, new Converter<Object, Object>() {
Object[] ret = get(source, new Converter<Object, Object>() {
@Override
@Nullable
public Object convert(final Object o) {
Expand All @@ -87,6 +91,25 @@ public Object convert(final Object o) {
}
}
});
return ret;
}

@SuppressWarnings("unchecked")
@Override
@Nullable
public <R> Expression<? extends R> getConvertedExpression(Class<R>... to) {
// Make sure we get converted expression from Variables etc. correctly
// Then, wrap it so that our 'X' is properly applied
// See #1747 for issue that was caused by failure to do this

Expression<? extends R> converted = getExpr().getConvertedExpression(to);
if (converted == null) // Can't create converted expression
return null;

ExprXOf wrapped = new ExprXOf();
wrapped.setExpr(converted);
wrapped.amount = amount;
return (Expression<? extends R>) wrapped;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
package ch.njol.skript.lang.util;

import java.util.Arrays;
import java.util.Iterator;
import java.util.NoSuchElementException;

Expand Down Expand Up @@ -155,7 +156,9 @@ public T getSingle(final Event e) {

@Override
public T[] getArray(final Event e) {
return Converters.convert(source.getArray(e), to, conv);
F[] arr = source.getArray(e);
T[] ret = Converters.convert(arr, to, conv);
return ret;
}

@Override
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/ch/njol/skript/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,11 @@ public static Class<?> getSuperType(final Class<?>... cs) {
return Object.class;
}
}
return r;

// Cloneable is about as useful as object as super type
// However, it lacks special handling used for Object supertype
// See #1747 to learn how it broke returning items from functions
return r.equals(Cloneable.class) ? Object.class : r;
}

/**
Expand Down

0 comments on commit 4088ce1

Please sign in to comment.