Proper generic array processing + showed bound type for generic on assignment errors + small constructor forgor from last commit

This commit is contained in:
bigguy345 committed 2026-03-10 23:57:06 +02:00
1 parent db909866b8
commit 7615eda083
5 files changed
+25 -12

No files matched your search

@@ -3816,20 +3816,25 @@ public class ScriptDocument {
}
if (typeName != null && !typeName.contains(".")) {
TypeStringNormalizer.ArraySplit arraySplit = TypeStringNormalizer.splitArraySuffixes(typeName);
String baseTypeName = arraySplit.base;
int arrayDims = arraySplit.dimensions;
ScriptTypeInfo enclosing = findEnclosingScriptType(position);
while (enclosing != null) {
// Check if the name is a declared type parameter on this class (e.g., E in class Box<E>)
TypeParamInfo typeParam = enclosing.getDeclaredTypeParam(typeName);
TypeParamInfo typeParam = enclosing.getDeclaredTypeParam(baseTypeName);
if (typeParam != null) {
TypeInfo boundType = typeParam.getBoundTypeInfo();
if (boundType == null) {
typeParam.resolveBoundType();
boundType = typeParam.getBoundTypeInfo();
}
if (boundType != null && boundType.isResolved()) {
return TypeInfo.typeParameter(typeName, boundType);
}
return TypeInfo.typeParameter(typeName);
TypeInfo result = (boundType != null && boundType.isResolved())
? TypeInfo.typeParameter(baseTypeName, boundType)
: TypeInfo.typeParameter(baseTypeName);
for (int i = 0; i < arrayDims; i++) result = TypeInfo.arrayOf(result);
return result;
}
// Check inner classes
@@ -1,6 +1,7 @@
package noppes.npcs.client.gui.util.script.interpreter.field;
import noppes.npcs.client.gui.util.script.ScopeInfo;
import noppes.npcs.client.gui.util.script.interpreter.method.MethodCallInfo;
import noppes.npcs.client.gui.util.script.interpreter.type.TypeChecker;
import noppes.npcs.client.gui.util.script.interpreter.type.TypeInfo;
@@ -139,8 +140,8 @@ public class AssignmentInfo {
// Check type compatibility
if (targetType != null && sourceType != null) {
if (!TypeChecker.isTypeCompatible(targetType, sourceType)) {
this.requiredType = targetType.getSimpleName();
this.providedType = sourceType.getSimpleName();
this.requiredType = MethodCallInfo.getTypeDisplayName(targetType);
this.providedType = MethodCallInfo.getTypeDisplayName(sourceType);
setError(ErrorType.TYPE_MISMATCH, buildTypeMismatchMessage());
}
}
@@ -443,7 +443,7 @@ public class MethodCallInfo {
* in error "Expect T but got String", if T has a resolved bound aka "int" show it instead of T to avoid confusion.
* So the error would be "Expect int but got String"
*/
private String getTypeDisplayName(TypeInfo type) {
public static String getTypeDisplayName(TypeInfo type) {
if(type.isTypeParameter()) {
TypeInfo bound = type.getBoundType();
if (bound != null)
@@ -178,12 +178,15 @@ public class ScriptTypeInfo extends TypeInfo {
result.outerClass = this.outerClass;
GenericContext ctx = GenericContext.forReceiver(result);
// Parameterize methods and fields with the generic context of this type.
// Parameterize methods, constructors, and fields with the generic context of this type.
for (Map.Entry<String, List<MethodInfo>> entry : this.methods.entrySet()) {
List<MethodInfo> substituted = new ArrayList<>();
for (MethodInfo m : entry.getValue()) substituted.add(substituteMethod(m, ctx));
result.methods.put(entry.getKey(), substituted);
}
for (MethodInfo ctor : this.constructors) {
result.constructors.add(substituteMethod(ctor, ctx));
}
for (Map.Entry<String, FieldInfo> entry : this.fields.entrySet()) {
FieldInfo f = entry.getValue();
TypeInfo subType = ctx.substitute(f.getTypeInfo());
@@ -490,14 +490,18 @@ public class TypeInfo {
// Fallback to Object array if we can't create the specific array type
}
}
TypeInfo arr = new TypeInfo(simpleName, fullName, pkg, elementType.kind, arrayClass, true, null, null, null, null, elementType);
TypeInfo arr = new TypeInfo(simpleName, fullName, pkg, elementType.kind, arrayClass, elementType.isResolved(),
null, null, null, null, elementType);
arr.setPrimitive(elementType.isPrimitive());
arr.syntheticFields.add(FieldInfo.external("length", TypeInfo.fromPrimitive("int"), null,
Modifier.PUBLIC | Modifier.FINAL));
arr.syntheticMethods.add(MethodInfo.external("clone", arr, null,
Collections.emptyList(), Modifier.PUBLIC, null));
return arr;
arr.typeParameterName = elementType.typeParameterName;
if (elementType.boundType != null)
arr.boundType = arrayOf(elementType.boundType);
return arr;
}
/**