Permalink
Browse files

Fix compiler bug when dealing with bad breaks

Previously, when using the break(1) format, if the integer wasn't
atomic, then this would cause a java stack trace. Now it causes a normal
compile error.
  • Loading branch information...
LadyCailin committed Dec 3, 2018
1 parent 2c40de7 commit bae5875571c209d083b0ad8db2fbd2edceaab36f
@@ -74,29 +74,6 @@ public static CArray getArray(Mixed construct, Target t) {
}
}
/**
* Works like the other get* methods, but works in a more generic way for other types of Mixeds.
*
* @param <T> The type expected.
* @param construct The generic object
* @param t Code target
* @param expectedClassName The expected class type, for use in the error message if the construct is the wrong
* type.
* @param clazz The type expected.
* @return The properly cast object.
* @deprecated Use
* {@link #getObject(Mixed, com.laytonsmith.core.constructs.Target, java.lang.Class)}
* instead, as that gets the expected class name automatically.
*/
@Deprecated
public static <T extends Mixed> T getObject(Mixed construct, Target t, String expectedClassName, Class<T> clazz) {
if(clazz.isAssignableFrom(construct.getClass())) {
return (T) construct;
} else {
throw new CRECastException("Expecting " + expectedClassName + " but receieved " + construct.val() + " instead.", t);
}
}
/**
* Works like the other get* methods, but works in a more generic way for other types of Mixeds. It also assumes
* that the class specified is tagged with a typeof annotation, thereby preventing the need for the
@@ -244,6 +221,7 @@ public static float getDouble32(Mixed c, Target t) {
*
* @param c
* @param t
* @throws CRECastException If the value cannot be converted to a long
* @return
*/
public static long getInt(Mixed c, Target t) {
@@ -279,6 +257,8 @@ public static long getInt(Mixed c, Target t) {
*
* @param c
* @param t
* @throws CRERangeException If the value would be truncated
* @throws CRECastException If the value cannot be cast to an int
* @return
*/
public static int getInt32(Mixed c, Target t) {
@@ -300,6 +280,8 @@ public static int getInt32(Mixed c, Target t) {
*
* @param c
* @param t
* @throws CRERangeException If the value would be truncated
* @throws CRECastException If the value cannot be cast to an int
* @return
*/
public static short getInt16(Mixed c, Target t) {
@@ -321,6 +303,8 @@ public static short getInt16(Mixed c, Target t) {
*
* @param c
* @param t
* @throws CRERangeException If the value would be truncated
* @throws CRECastException If the value cannot be cast to an int
* @return
*/
public static byte getInt8(Mixed c, Target t) {
@@ -31,6 +31,8 @@
import com.laytonsmith.core.environments.CommandHelperEnvironment;
import com.laytonsmith.core.environments.Environment;
import com.laytonsmith.core.environments.GlobalEnv;
import com.laytonsmith.core.exceptions.CRE.CRECastException;
import com.laytonsmith.core.exceptions.CRE.CRERangeException;
import com.laytonsmith.core.exceptions.ConfigCompileException;
import com.laytonsmith.core.exceptions.ConfigCompileGroupException;
import com.laytonsmith.core.exceptions.ConfigRuntimeException;
@@ -1710,11 +1712,15 @@ private static void checkBreaks0(ParseTree tree, long currentLoops, String lastU
if(func instanceof DataHandling._break) {
// First grab the counter in the break function. If the break function doesn't
// have any children, then 1 is implied. break() requires the argument to be
// a CInt, so if it weren't, there would already have been a compile error, so
// we can assume it will be a CInt.
// a CInt, so if it weren't, there should be a compile error.
long breakCounter = 1;
if(tree.getChildren().size() == 1) {
breakCounter = ((CInt) tree.getChildAt(0).getData()).getInt();
try {
breakCounter = Static.getInt32(tree.getChildAt(0).getData(), tree.getChildAt(0).getTarget());
} catch(CRECastException | CRERangeException e) {
compilerErrors.add(new ConfigCompileException(e));
return;
}
}
if(breakCounter > currentLoops) {
// Throw an exception, as this would break above a loop. Different error messages
@@ -51,6 +51,7 @@
import com.laytonsmith.core.exceptions.CRE.CRELengthException;
import com.laytonsmith.core.exceptions.CRE.CRENullPointerException;
import com.laytonsmith.core.exceptions.CRE.CREPlayerOfflineException;
import com.laytonsmith.core.exceptions.CRE.CRERangeException;
import com.laytonsmith.core.exceptions.ConfigRuntimeException;
import com.laytonsmith.core.functions.Function;
import com.laytonsmith.core.natives.interfaces.Mixed;
@@ -186,6 +187,8 @@ public static float getDouble32(Mixed c, Target t) {
* Returns an integer from any given construct.
*
* @param c
* @throws CRERangeException If the value would be truncated
* @throws CRECastException If the value cannot be cast to an int
* @return
*/
public static long getInt(Mixed c, Target t) {
@@ -199,6 +202,8 @@ public static long getInt(Mixed c, Target t) {
*
* @param c
* @param t
* @throws CRERangeException If the value would be truncated
* @throws CRECastException If the value cannot be cast to an int
* @return
*/
public static int getInt32(Mixed c, Target t) {
@@ -212,6 +217,8 @@ public static int getInt32(Mixed c, Target t) {
*
* @param c
* @param t
* @throws CRERangeException If the value would be truncated
* @throws CRECastException If the value cannot be cast to an int
* @return
*/
public static short getInt16(Mixed c, Target t) {
@@ -225,6 +232,8 @@ public static short getInt16(Mixed c, Target t) {
*
* @param c
* @param t
* @throws CRERangeException If the value would be truncated
* @throws CRECastException If the value cannot be cast to an int
* @return
*/
public static byte getInt8(Mixed c, Target t) {
@@ -244,23 +253,6 @@ public static boolean getBoolean(Mixed c, Target t) {
return ArgumentValidation.getBoolean(c, t);
}
/**
* Returns a boolean from any given construct. Depending on the type of the construct being converted, it follows
* the following rules: If it is an integer or a double, it is false if 0, true otherwise. If it is a string, if it
* is empty, it is false, otherwise it is true.
*
* @param c
* @return
* @deprecated Use
* {@link #getBoolean(Mixed, com.laytonsmith.core.constructs.Target)}
* instead, as it provides better error messages for users that use the string "false" as a boolean. This method
* should be removed in version 3.3.3 or above.
*/
@Deprecated
public static boolean getBoolean(Mixed c) {
return getBoolean(c, Target.UNKNOWN);
}
/**
* Returns a primitive from any given construct.
*
@@ -3126,7 +3126,7 @@ public Mixed exec(Target t, Environment environment, Mixed... args) throws Confi
throw new CRECastException("The closure passed to " + getName() + " must return a"
+ " boolean value", t);
} catch (FunctionReturnException fre) {
boolean res = Static.getBoolean(fre.getReturn());
boolean res = Static.getBoolean(fre.getReturn(), fre.getTarget());
if(res) {
ret.push(one.get(k1[i], t), t);
continue i;

0 comments on commit bae5875

Please sign in to comment.