Skip to content

Commit 5d44449

Browse files
committed
Fix remaining test failures
1 parent e2c3790 commit 5d44449

14 files changed

Lines changed: 72 additions & 53 deletions

File tree

src/main/java/com/laytonsmith/core/MethodScriptCompiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1766,7 +1766,7 @@ public static ParseTree compile(TokenStream stream, Environment env,
17661766
}
17671767
// make CDouble/CDecimal here because otherwise Long.parseLong() will remove
17681768
// minus zero before decimals and leading zeroes after decimals
1769-
if((c instanceof CInt || c instanceof CDecimal) && next1.type == TType.DOT && next2.type == TType.LIT) {
1769+
if(c instanceof CInt && next1.type == TType.DOT && next2.type == TType.LIT) {
17701770
try {
17711771
c = new CDouble(Double.parseDouble(t.val() + '.' + next2.val()), t.target);
17721772
i += 2;

src/main/java/com/laytonsmith/core/constructs/CArray.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ public final Mixed get(long index, Target t, Environment env) {
600600
if((int) index != index) {
601601
throw new CREIndexOverflowException("The element at index \"" + index + "\" does not exist", t);
602602
}
603-
return this.get((int) index, t, env);
603+
return this.get(new CInt(index, t), t, env);
604604
}
605605

606606
/**
@@ -1288,7 +1288,7 @@ public void ensureCapacity(int capacity) {
12881288

12891289
@Override
12901290
public Set<ObjectModifier> getObjectModifiers() {
1291-
return EnumSet.of(ObjectModifier.FINAL);
1291+
return EnumSet.noneOf(ObjectModifier.class);
12921292
}
12931293

12941294
@Override

src/main/java/com/laytonsmith/core/constructs/CClassType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,8 @@ public LeftHandGenericUse getSuperclassGenerics(CClassType superClass, LeftHandG
11361136

11371137
/**
11381138
* Adds the given superclass's generic parameters. For instance, if this is {@code class A} which extends
1139-
* {@code class B<int>}, then when defining A.TYPE, after calling CClass.get(...) it should chain
1139+
* {@code class B<int>}, (i.e. {@code class A extends B<int>}), then when defining A.TYPE,
1140+
* after calling CClass.get(...) it should chain
11401141
* {@code .withSuperParameters(GenericTypeParameters.nativeBuilder(B.TYPE).addParameter(CInt.TYPE, null)).done()}.
11411142
* If multiple classes with parameters are extended, those can be chained, as the method returns {@code this}.
11421143
* <p>

src/main/java/com/laytonsmith/core/constructs/CReal2dMatrix.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.HashSet;
1919
import java.util.Set;
2020
import com.laytonsmith.PureUtilities.Common.Annotations.AggressiveDeprecation;
21+
import com.laytonsmith.core.constructs.generics.GenericTypeParameters;
2122

2223
/**
2324
*
@@ -27,7 +28,10 @@ public class CReal2dMatrix extends AbstractMixedClass implements Matrix<Double>,
2728
com.laytonsmith.core.natives.interfaces.Iterable {
2829

2930
@SuppressWarnings("FieldNameHidesFieldInSuperclass")
30-
public static final CClassType TYPE = CClassType.get(CReal2dMatrix.class);
31+
public static final CClassType TYPE = CClassType.get(CReal2dMatrix.class)
32+
.withSuperParameters(GenericTypeParameters.nativeBuilder(com.laytonsmith.core.natives.interfaces.Iterable.TYPE)
33+
.addParameter(CReal2dMatrixRow.TYPE, null))
34+
.done();
3135

3236
int rows;
3337
int columns;

src/main/java/com/laytonsmith/core/constructs/CReal2dMatrixRow.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.laytonsmith.core.exceptions.CRE.CRECastException;
99
import com.laytonsmith.core.exceptions.ConfigRuntimeException;
1010
import com.laytonsmith.core.constructs.generics.GenericParameters;
11+
import com.laytonsmith.core.constructs.generics.GenericTypeParameters;
1112
import com.laytonsmith.core.environments.Environment;
1213
import com.laytonsmith.core.natives.interfaces.AbstractMixedClass;
1314
import com.laytonsmith.core.natives.interfaces.ArrayAccessSet;
@@ -24,7 +25,10 @@ public class CReal2dMatrixRow extends AbstractMixedClass implements com.laytonsm
2425
ArrayAccessSet {
2526

2627
@SuppressWarnings("FieldNameHidesFieldInSuperclass")
27-
public static final CClassType TYPE = CClassType.get(CReal2dMatrixRow.class);
28+
public static final CClassType TYPE = CClassType.get(CReal2dMatrixRow.class)
29+
.withSuperParameters(GenericTypeParameters.nativeBuilder(com.laytonsmith.core.natives.interfaces.Iterable.TYPE)
30+
.addParameter(CDouble.TYPE, null))
31+
.done();;
2832

2933
CReal2dMatrix parent;
3034
int rowIndex;

src/main/java/com/laytonsmith/core/constructs/IVariable.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.laytonsmith.core.constructs;
22

3+
import com.laytonsmith.PureUtilities.Common.Annotations.AggressiveDeprecation;
34
import com.laytonsmith.PureUtilities.Version;
45
import com.laytonsmith.core.constructs.generics.ConcreteGenericParameter;
56
import com.laytonsmith.core.constructs.generics.ConstraintValidator;
@@ -28,13 +29,26 @@ public IVariable(String name, Target t) throws ConfigCompileException {
2829
this(Auto.TYPE, name, new CString("", t), t, null);
2930
}
3031

32+
/**
33+
*
34+
* @param checkedType
35+
* @param name
36+
* @param checkedValue
37+
* @param t
38+
* @throws ConfigCompileException
39+
* @deprecated Use {@link #IVariable(com.laytonsmith.core.constructs.LeftHandSideType, java.lang.String,
40+
* com.laytonsmith.core.natives.interfaces.Mixed, com.laytonsmith.core.constructs.Target,
41+
* com.laytonsmith.core.environments.Environment)} instead.
42+
*/
43+
@AggressiveDeprecation(deprecationDate = "2022-04-06", removalVersion = "3.3.7", deprecationVersion = "3.3.6")
44+
@Deprecated
3145
public IVariable(CClassType checkedType, String name, Mixed checkedValue, Target t) throws ConfigCompileException {
3246
this(checkedType, name, checkedValue, t, null);
3347
}
3448

3549
/**
3650
* Temporary function that sets generic parameters to null. This will be removed in the future once the compiler
37-
* supports generics, at which point you should explicitely pass in null to the other constructor if there were
51+
* supports generics, at which point you should explicitly pass in null to the other constructor if there were
3852
* no generics defined.
3953
* @param type
4054
* @param name
@@ -44,14 +58,15 @@ public IVariable(CClassType checkedType, String name, Mixed checkedValue, Target
4458
* @throws ConfigCompileException
4559
* @deprecated Use {@link #IVariable(CClassType, String, Mixed, Target, LeftHandGenericUse, Environment)}
4660
*/
61+
@AggressiveDeprecation(deprecationDate = "2022-04-06", removalVersion = "3.3.7", deprecationVersion = "3.3.6")
4762
@Deprecated
4863
public IVariable(CClassType type, String name, Mixed value, Target t, Environment env) throws ConfigCompileException {
4964
this(type.asLeftHandSideType(), name, value, t, env);
5065
}
5166

5267
/**
5368
* Constructs a new IVariable instance.
54-
* @param type The type of value, may be auto
69+
* @param type The defined type of the variable, may be auto.
5570
* @param name The name of the variable
5671
* @param value The value, if it was provided. May be CNull, but cannot be java null
5772
* @param t The code target where this value was defined
@@ -73,28 +88,18 @@ public IVariable(LeftHandSideType type, String name, Mixed value, Target t,
7388
if(value instanceof CVoid) {
7489
throw new CRECastException("Void may not be assigned to a variable", t);
7590
}
76-
boolean hasValidType = true;
7791
for(ConcreteGenericParameter types : type.getTypes()) {
7892
LeftHandGenericUse genericDefinition = types.getLeftHandGenericUse();
7993
CClassType subType = types.getType();
8094
ConstraintValidator.ValidateLHS(t, subType, genericDefinition, env);
8195
if(subType.equals(CVoid.TYPE)) {
8296
throw new CRECastException("Variables may not be of type void", t);
8397
}
84-
// if(env != null && (!subType.equals(Auto.TYPE) && !(value instanceof CNull))) {
85-
// if(!InstanceofUtil.isInstanceof(value, subType, env)) {
86-
// hasValidType = false;
87-
// }
88-
// }
8998
}
9099
if(!InstanceofUtil.isAssignableTo(value.typeof(env).asLeftHandSideType(), type, env)) {
91100
throw new CRECastException(name + " is of type " + type.val() + ", but a value of type "
92101
+ value.typeof(env) + " was assigned to it.", t);
93102
}
94-
// if(!hasValidType) {
95-
// throw new CRECastException(name + " is of type " + type.val() + ", but a value of type "
96-
// + value.typeof(env) + " was assigned to it.", t);
97-
// }
98103

99104
this.type = type;
100105
this.varValue = value;

src/main/java/com/laytonsmith/core/constructs/InstanceofUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ public static boolean isAssignableTo(CClassType type, CClassType instanceofThis,
425425

426426
/**
427427
* This function returns true if a value of a certain type is assignable to the given type. In general, this is
428-
* precisely equivalent to {@link #isInstanceof(CClassType, CClassType, LeftHandGenericUse, Environment)} except
428+
* precisely equivalent to {@link #isInstanceof(LeftHandSideType, LeftHandSideType, Environment)} except
429429
* this allows for null to be assigned to any value in general. The only exception to this rule is if the type is
430430
* defined with the NotNull annotation, or the type itself is NotNull.
431431
* <p>

src/main/java/com/laytonsmith/core/functions/Compiler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,11 +1399,11 @@ public String getName() {
13991399
public Mixed exec(Target t, Environment env, GenericParameters generics, Mixed... args) throws CancelCommandException, ConfigRuntimeException {
14001400

14011401
// Get arguments.
1402-
CClassType type;
1402+
LeftHandSideType type;
14031403
String varName;
14041404
Mixed val;
14051405
if(args.length == 3) {
1406-
type = (CClassType) args[0];
1406+
type = ((SourceType) args[0]).asLeftHandSideType();
14071407
varName = ((IVariable) args[1]).getVariableName();
14081408
val = args[2];
14091409
} else {
@@ -1425,7 +1425,7 @@ public Mixed exec(Target t, Environment env, GenericParameters generics, Mixed..
14251425
IVariable var = list.get(varName);
14261426
if(var == null || (type != null && !type.equals(var.getDefinedType()))) {
14271427
try {
1428-
var = new IVariable(type, varName, val, t);
1428+
var = new IVariable(type, varName, val, t, env);
14291429
} catch(ConfigCompileException ex) {
14301430
throw new Error(ex);
14311431
}

src/main/java/com/laytonsmith/core/functions/ControlFlow.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2709,6 +2709,10 @@ public LeftHandSideType typecheck(StaticAnalysis analysis,
27092709

27102710
// Type check return value for all found declared return types.
27112711
for(Declaration decl : decls) {
2712+
if(valType.isVoid() && decl.getType().isVoid()) {
2713+
// void return in a void proc/closure is always valid.
2714+
continue;
2715+
}
27122716
StaticAnalysis.requireType(valType, decl.getType(), valTarget, env, exceptions);
27132717
}
27142718
}

src/main/java/com/laytonsmith/core/functions/DataHandling.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ public Mixed exec(Target t, Environment env, GenericParameters generics, Mixed..
428428
if(val instanceof CVoid) {
429429
throw new CRECastException("Void may not be assigned to a variable", t);
430430
}
431-
if(!InstanceofUtil.isInstanceof(val, type, env)) {
431+
if(!InstanceofUtil.isAssignableTo(val.typeof(env).asLeftHandSideType(), type, env)) {
432432
throw new CRECastException(varName + " is of type " + type.val() + ", but a value of type "
433433
+ val.typeof(env) + " was assigned to it.", t);
434434
}
@@ -469,7 +469,7 @@ public Mixed exec(Target t, Environment env, GenericParameters generics, Mixed..
469469
}
470470
list.set(var);
471471
} else {
472-
if(!InstanceofUtil.isInstanceof(val.typeof(env), var.getDefinedType(), env)) {
472+
if(!InstanceofUtil.isInstanceof(val, var.getDefinedType(), env)) {
473473
throw new CRECastException(varName + " is of type " + var.getDefinedType()
474474
+ ", but a value of type " + val.typeof(env) + " was assigned to it.", t);
475475
}
@@ -812,12 +812,13 @@ public ParseTree optimizeDynamic(Target t, Environment env,
812812
ParseTree typeNode = children.get(0);
813813
ParseTree varNode = children.get(1);
814814
ParseTree valNode = children.get(2);
815-
if(typeNode.getData() instanceof CClassType declaredType
815+
if(typeNode.getData() instanceof SourceType declaredSourceType
816816
&& varNode.getData() instanceof IVariable) {
817+
LeftHandSideType declaredType = declaredSourceType.asLeftHandSideType();
817818
if(valNode.isConst()) {
818-
CClassType valType = valNode.getData().typeof(env);
819-
if((valType != CClassType.AUTO || declaredType == CClassType.AUTO)
820-
&& InstanceofUtil.isInstanceof(valType, declaredType, env)) {
819+
LeftHandSideType valType = valNode.getData().typeof(env).asLeftHandSideType();
820+
if((valType != Auto.LHSTYPE || declaredType == Auto.LHSTYPE)
821+
&& InstanceofUtil.isAssignableTo(valType, declaredType, env)) {
821822
ParseTree newAssignNode = new ParseTree(new CFunction(__unsafe_assign__.NAME, t), fileOptions);
822823
newAssignNode.addChild(typeNode);
823824
newAssignNode.addChild(varNode);
@@ -827,9 +828,9 @@ public ParseTree optimizeDynamic(Target t, Environment env,
827828
}
828829
if(valNode.getData() instanceof CFunction cf && cf.getCachedFunction() != null
829830
&& cf.getCachedFunction().getName().equals(__cast__.NAME) && valNode.numberOfChildren() == 2
830-
&& valNode.getChildAt(1).getData() instanceof CClassType castType
831-
&& (castType != CClassType.AUTO || declaredType == CClassType.AUTO)
832-
&& InstanceofUtil.isInstanceof(castType, declaredType, env)) {
831+
&& valNode.getChildAt(1).getData() instanceof SourceType castType
832+
&& (castType.asLeftHandSideType() != Auto.LHSTYPE || declaredType == Auto.LHSTYPE)
833+
&& InstanceofUtil.isAssignableTo(castType.asLeftHandSideType(), declaredType, env)) {
833834
ParseTree newAssignNode = new ParseTree(new CFunction(__unsafe_assign__.NAME, t), fileOptions);
834835
newAssignNode.addChild(typeNode);
835836
newAssignNode.addChild(varNode);

0 commit comments

Comments
 (0)