diff --git a/.gitignore b/.gitignore index 7c0453250..8ecf1a2f1 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,7 @@ build *.class out/ -.idea \ No newline at end of file +.idea + +*.xslt +*.xml diff --git a/CodeFormatter/src/main/java/org/openzen/zenscript/formatter/TypeFormatter.java b/CodeFormatter/src/main/java/org/openzen/zenscript/formatter/TypeFormatter.java index c28d49006..4627f3f4a 100644 --- a/CodeFormatter/src/main/java/org/openzen/zenscript/formatter/TypeFormatter.java +++ b/CodeFormatter/src/main/java/org/openzen/zenscript/formatter/TypeFormatter.java @@ -23,7 +23,7 @@ public String format(TypeID type) { @Override public String visitBasic(BasicTypeID basic) { - return basic.name; + return basic.getName(); } @Override diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/GenericName.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/GenericName.java index 2308d55a1..068ab0b8b 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/GenericName.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/GenericName.java @@ -24,10 +24,10 @@ public GenericName(String name, TypeID[] arguments) { this.arguments = arguments; } - public static Optional getInnerType(TypeID type, List name, int index, List expansions) { + public static Optional getInnerType(TypeID type, List name, int index) { while (index < name.size()) { GenericName innerName = name.get(index++); - ResolvedType members = type.resolve(); + ResolvedType members = type.resolveWithoutExpansions(); Optional inner = members .findInnerType(innerName.name) .map(t -> DefinitionTypeID.create(t, innerName.arguments)); diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/HighLevelDefinition.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/HighLevelDefinition.java index b9d074c58..1748248dc 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/HighLevelDefinition.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/HighLevelDefinition.java @@ -3,7 +3,7 @@ import org.openzen.zencode.shared.CodePosition; import org.openzen.zencode.shared.Taggable; import org.openzen.zenscript.codemodel.annotations.DefinitionAnnotation; -import org.openzen.zenscript.codemodel.compilation.ResolvedType; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; import org.openzen.zenscript.codemodel.definition.*; import org.openzen.zenscript.codemodel.generic.TypeParameter; import org.openzen.zenscript.codemodel.identifiers.ModuleSymbol; @@ -11,12 +11,10 @@ import org.openzen.zenscript.codemodel.identifiers.instances.MethodInstance; import org.openzen.zenscript.codemodel.member.*; import org.openzen.zenscript.codemodel.type.BasicTypeID; +import org.openzen.zenscript.codemodel.type.DefinitionTypeID; import org.openzen.zenscript.codemodel.type.TypeID; import org.openzen.zenscript.codemodel.type.builtin.BuiltinMethodSymbol; -import org.openzen.zenscript.codemodel.type.member.ExpandedResolvedType; -import org.openzen.zenscript.codemodel.type.member.InterfaceResolvedType; -import org.openzen.zenscript.codemodel.type.member.MemberSet; -import org.openzen.zenscript.codemodel.type.member.SubclassResolvedType; +import org.openzen.zenscript.codemodel.type.member.*; import java.util.ArrayList; import java.util.List; @@ -144,7 +142,9 @@ public String getName() { } @Override - public ResolvedType resolve(TypeID type, TypeID[] typeArguments) { + public ResolvingType resolve(TypeID[] typeArguments) { + TypeID type = DefinitionTypeID.create(this, typeArguments); + MemberSet.Builder members = MemberSet.create(type); GenericMapper mapper = GenericMapper.create(typeParameters, typeArguments); for (IDefinitionMember member : this.members) { @@ -155,19 +155,15 @@ public ResolvedType resolve(TypeID type, TypeID[] typeArguments) { members.method(new MethodInstance(BuiltinMethodSymbol.OBJECT_SAME, new FunctionHeader(BasicTypeID.BOOL, type), type)); members.method(new MethodInstance(BuiltinMethodSymbol.OBJECT_NOTSAME, new FunctionHeader(BasicTypeID.BOOL, type), type)); resolveAdditional(type, members, mapper); - ResolvedType resolved = members.build(); + ResolvingType resolved = members.build(); if (superType != null) { TypeID instancedSuperType = mapper.map(superType); - ResolvedType superResolved = instancedSuperType.resolve(); - resolved = new SubclassResolvedType(superResolved, resolved, superType); + ResolvingType superResolved = instancedSuperType.resolve(); + resolved = new SubclassResolvingType(superResolved, resolved, superType); } - if (interfaces.isEmpty()) { - return resolved; - } else { - return new InterfaceResolvedType(resolved, interfaces); - } + return InterfaceResolvingType.of(resolved, interfaces); } protected void resolveAdditional(TypeID type, MemberSet.Builder members, GenericMapper mapper) {} diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/compilation/CompileContext.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/compilation/CompileContext.java index 41ea854ef..20c2ac5d2 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/compilation/CompileContext.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/compilation/CompileContext.java @@ -95,14 +95,14 @@ public Optional resolve(CodePosition position, List name) { } return Optional.of(DefinitionTypeID.create(definition.getDefinition(), name.get(name.size() - 1).arguments)); } else if (rootPackage.contains(name.get(0).name)) { - return rootPackage.getType(name, expansions); + return rootPackage.getType(name); } return Optional.ofNullable(globals.get(name.get(0).name)) .flatMap(t -> t.getType(position, this, name.get(0).arguments)) .flatMap(t -> { for (int i = 1; i < name.size(); i++) { - Optional inner = t.resolve().findInnerType(name.get(i).name); + Optional inner = t.resolveWithoutExpansions().findInnerType(name.get(i).name); if (inner.isPresent()) { t = DefinitionTypeID.create(inner.get(), name.get(i).arguments); } else { diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/compilation/ResolvedType.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/compilation/ResolvedType.java index aece87020..41fafe381 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/compilation/ResolvedType.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/compilation/ResolvedType.java @@ -6,13 +6,10 @@ import org.openzen.zenscript.codemodel.expression.CallArguments; import org.openzen.zenscript.codemodel.expression.Expression; import org.openzen.zenscript.codemodel.expression.switchvalue.SwitchValue; -import org.openzen.zenscript.codemodel.identifiers.ExpansionSymbol; import org.openzen.zenscript.codemodel.identifiers.TypeSymbol; import org.openzen.zenscript.codemodel.identifiers.instances.IteratorInstance; import org.openzen.zenscript.codemodel.type.TypeID; -import org.openzen.zenscript.codemodel.type.member.ExpandedResolvedType; -import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -78,14 +75,6 @@ default boolean canCastImplicitlyTo(TypeID target) { Optional findStaticOperator(OperatorType operator); - default ResolvedType withExpansions(List expansions) { - List resolutions = new ArrayList<>(); - for (ExpansionSymbol expansion : expansions) { - expansion.resolve(getType()).ifPresent(resolutions::add); - } - return ExpandedResolvedType.of(this, resolutions); - } - interface SwitchMember { SwitchValue toSwitchValue(List bindings); } diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/compilation/ResolvingType.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/compilation/ResolvingType.java new file mode 100644 index 000000000..9c819eb47 --- /dev/null +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/compilation/ResolvingType.java @@ -0,0 +1,12 @@ +package org.openzen.zenscript.codemodel.compilation; + +import org.openzen.zenscript.codemodel.identifiers.ExpansionSymbol; +import org.openzen.zenscript.codemodel.type.TypeID; + +import java.util.List; + +public interface ResolvingType { + TypeID getType(); + + ResolvedType withExpansions(List expansions); +} diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/compilation/impl/compiler/LocalTypeImpl.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/compilation/impl/compiler/LocalTypeImpl.java index 1351bfaaf..bb62ce52b 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/compilation/impl/compiler/LocalTypeImpl.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/compilation/impl/compiler/LocalTypeImpl.java @@ -45,7 +45,7 @@ public Optional superCall() { return Optional.empty(); if (resolvedSuper == null) - resolvedSuper = thisType.getSuperType().resolve(); + resolvedSuper = thisType.getSuperType().resolveWithoutExpansions(); return Optional.ofNullable(resolvedSuper) .map(super_ -> super_.getConstructor().map(constructor -> new SuperCallable(thisType.getSuperType(), constructor))); diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ClassDefinition.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ClassDefinition.java index 19cc9b146..0f16e172a 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ClassDefinition.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ClassDefinition.java @@ -43,7 +43,7 @@ public void addDefaultMembers() { boolean hasNoConstructor = members.stream().noneMatch(IDefinitionMember::isConstructor); Optional superConstructor = Optional.ofNullable(getSuperType()) - .flatMap(t -> t.resolve().getConstructor().getSingleOverload()) + .flatMap(t -> t.resolveWithoutExpansions().getConstructor().getSingleOverload()) .flatMap(AnyMethod::asMethod); if (hasNoConstructor) { diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ExpansionDefinition.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ExpansionDefinition.java index ce63f3960..862847944 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ExpansionDefinition.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ExpansionDefinition.java @@ -54,6 +54,6 @@ public Optional resolve(TypeID expandingType) { for (IDefinitionMember member : members) member.registerTo(expandingType, resolution, mapper); - return Optional.of(resolution.build()); + return Optional.of(resolution.buildWithoutExpansions()); } } diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ZSPackage.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ZSPackage.java index 060c66f28..08786def7 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ZSPackage.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/ZSPackage.java @@ -52,8 +52,8 @@ public TypeSymbol getImport(List name, int depth) { return null; } - public Optional getType(List nameParts, List expansions) { - return getType(nameParts, 0, expansions); + public Optional getType(List nameParts) { + return getType(nameParts, 0); } public Optional getType(GenericName name) { @@ -64,17 +64,17 @@ public Optional getType(GenericName name) { } } - private Optional getType(List nameParts, int depth, List expansions) { + private Optional getType(List nameParts, int depth) { if (depth >= nameParts.size()) return Optional.empty(); GenericName name = nameParts.get(depth); if (subPackages.containsKey(name.name) && name.hasNoArguments()) - return subPackages.get(name.name).getType(nameParts, depth + 1, expansions); + return subPackages.get(name.name).getType(nameParts, depth + 1); if (types.containsKey(name.name)) { TypeID type = DefinitionTypeID.create(types.get(name.name), name.arguments); - return GenericName.getInnerType(type, nameParts, depth + 1, expansions); + return GenericName.getInnerType(type, nameParts, depth + 1); } return Optional.empty(); diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/ParameterSuperBound.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/ParameterSuperBound.java index dea56bfab..a3b465917 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/ParameterSuperBound.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/ParameterSuperBound.java @@ -1,7 +1,7 @@ package org.openzen.zenscript.codemodel.generic; import org.openzen.zenscript.codemodel.GenericMapper; -import org.openzen.zenscript.codemodel.compilation.ResolvedType; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; import org.openzen.zenscript.codemodel.type.TypeID; import java.util.Optional; @@ -19,7 +19,7 @@ public String getCanonical() { } @Override - public Optional resolveMembers() { + public Optional resolveMembers() { return Optional.empty(); } diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/ParameterTypeBound.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/ParameterTypeBound.java index 132816a81..ee1336db7 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/ParameterTypeBound.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/ParameterTypeBound.java @@ -2,7 +2,7 @@ import org.openzen.zencode.shared.CodePosition; import org.openzen.zenscript.codemodel.GenericMapper; -import org.openzen.zenscript.codemodel.compilation.ResolvedType; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; import org.openzen.zenscript.codemodel.type.TypeID; import java.util.Optional; @@ -22,7 +22,7 @@ public String getCanonical() { } @Override - public Optional resolveMembers() { + public Optional resolveMembers() { return Optional.of(type.resolve()); } diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/TypeParameterBound.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/TypeParameterBound.java index a6b88084d..84721a1bb 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/TypeParameterBound.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/generic/TypeParameterBound.java @@ -1,7 +1,7 @@ package org.openzen.zenscript.codemodel.generic; import org.openzen.zenscript.codemodel.GenericMapper; -import org.openzen.zenscript.codemodel.compilation.ResolvedType; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; import org.openzen.zenscript.codemodel.type.TypeID; import java.util.Optional; @@ -13,7 +13,7 @@ public interface TypeParameterBound { R accept(C context, GenericParameterBoundVisitorWithContext visitor); - Optional resolveMembers(); + Optional resolveMembers(); boolean matches(TypeID type); diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/identifiers/TypeSymbol.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/identifiers/TypeSymbol.java index 04928beb8..8978d12aa 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/identifiers/TypeSymbol.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/identifiers/TypeSymbol.java @@ -1,7 +1,7 @@ package org.openzen.zenscript.codemodel.identifiers; import org.openzen.zenscript.codemodel.Modifiers; -import org.openzen.zenscript.codemodel.compilation.ResolvedType; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; import org.openzen.zenscript.codemodel.type.DefinitionTypeID; import org.openzen.zenscript.codemodel.type.TypeID; @@ -19,7 +19,7 @@ public interface TypeSymbol extends DefinitionSymbol { String getName(); - ResolvedType resolve(TypeID type, TypeID[] typeArguments); + ResolvingType resolve(TypeID[] typeArguments); Optional getOuter(); diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ArrayTypeID.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ArrayTypeID.java index 72af0d37a..e9188e094 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ArrayTypeID.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ArrayTypeID.java @@ -2,7 +2,7 @@ import org.openzen.zencode.shared.CodePosition; import org.openzen.zenscript.codemodel.GenericMapper; -import org.openzen.zenscript.codemodel.compilation.ResolvedType; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; import org.openzen.zenscript.codemodel.expression.ArrayExpression; import org.openzen.zenscript.codemodel.expression.Expression; import org.openzen.zenscript.codemodel.generic.TypeParameter; @@ -72,8 +72,8 @@ public Optional asArray() { } @Override - public ResolvedType resolve() { - return type.resolve(this, new TypeID[] { elementType }); + public ResolvingType resolve() { + return type.resolve(new TypeID[] { elementType }); } @Override diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/AssocTypeID.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/AssocTypeID.java index 5ad5d68c2..5ec2f5e4a 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/AssocTypeID.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/AssocTypeID.java @@ -1,7 +1,7 @@ package org.openzen.zenscript.codemodel.type; import org.openzen.zenscript.codemodel.GenericMapper; -import org.openzen.zenscript.codemodel.compilation.ResolvedType; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; import org.openzen.zenscript.codemodel.generic.TypeParameter; import org.openzen.zenscript.codemodel.type.builtin.MapTypeSymbol; @@ -53,8 +53,8 @@ public Optional asAssoc() { } @Override - public ResolvedType resolve() { - return MapTypeSymbol.INSTANCE.resolve(this, new TypeID[] { keyType, valueType }); + public ResolvingType resolve() { + return MapTypeSymbol.INSTANCE.resolve(new TypeID[] { keyType, valueType }); } @Override diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/BasicTypeID.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/BasicTypeID.java index bee54a3a7..dd2a342dd 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/BasicTypeID.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/BasicTypeID.java @@ -3,13 +3,12 @@ import org.openzen.zencode.shared.CodePosition; import org.openzen.zenscript.codemodel.GenericMapper; import org.openzen.zenscript.codemodel.Modifiers; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; import org.openzen.zenscript.codemodel.identifiers.ModuleSymbol; -import org.openzen.zenscript.codemodel.compilation.ResolvedType; import org.openzen.zenscript.codemodel.expression.*; import org.openzen.zenscript.codemodel.generic.TypeParameter; import org.openzen.zenscript.codemodel.identifiers.TypeSymbol; import org.openzen.zenscript.codemodel.type.builtin.BasicTypeMembers; -import org.openzen.zenscript.codemodel.type.member.MemberSet; import java.util.List; import java.util.Optional; @@ -35,8 +34,8 @@ public enum BasicTypeID implements TypeID, TypeSymbol { UNDETERMINED("undetermined"), INVALID("invalid"); - public final String name; - private MemberSet members; + private final String name; + private ResolvingType members; private Expression defaultValue = null; @@ -64,18 +63,13 @@ public R accept(C context, TypeVisitorWithContext typeParameters) { - + // BasicTypeIDs don't have type parameters } private Expression generateDefaultValue() { @@ -183,11 +177,12 @@ public String getName() { } @Override - public ResolvedType resolve(TypeID type, TypeID[] typeArguments) { - if (members == null) - members = BasicTypeMembers.get(this); + public ResolvingType resolve(TypeID[] typeArguments) { + if(typeArguments.length > 0) { + throw new IllegalArgumentException(this + " cannot have type arguments"); + } - return members; + return this.resolve(); } @Override diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/DefinitionTypeID.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/DefinitionTypeID.java index 71963499e..f2387e999 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/DefinitionTypeID.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/DefinitionTypeID.java @@ -1,7 +1,7 @@ package org.openzen.zenscript.codemodel.type; import org.openzen.zenscript.codemodel.GenericMapper; -import org.openzen.zenscript.codemodel.compilation.ResolvedType; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; import org.openzen.zenscript.codemodel.definition.EnumDefinition; import org.openzen.zenscript.codemodel.definition.StructDefinition; import org.openzen.zenscript.codemodel.definition.VariantDefinition; @@ -53,8 +53,8 @@ public DefinitionTypeID(TypeSymbol definition, TypeID[] typeArguments, Definitio * * @return base type members */ - public ResolvedType resolve() { - return definition.resolve(this, typeArguments); + public ResolvingType resolve() { + return definition.resolve(typeArguments); } public boolean hasTypeParameters() { diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/FunctionTypeID.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/FunctionTypeID.java index 14759d73f..cb9f467e6 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/FunctionTypeID.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/FunctionTypeID.java @@ -3,7 +3,7 @@ import org.openzen.zenscript.codemodel.FunctionHeader; import org.openzen.zenscript.codemodel.FunctionParameter; import org.openzen.zenscript.codemodel.GenericMapper; -import org.openzen.zenscript.codemodel.compilation.ResolvedType; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; import org.openzen.zenscript.codemodel.generic.TypeParameter; import org.openzen.zenscript.codemodel.type.builtin.FunctionTypeSymbol; @@ -56,8 +56,8 @@ public Optional asFunction() { } @Override - public ResolvedType resolve() { - return type.resolve(this, TypeID.NONE); + public ResolvingType resolve() { + return type.resolve(TypeID.NONE); } @Override diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericMapTypeID.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericMapTypeID.java index 04bf4fa9a..8601703a3 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericMapTypeID.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericMapTypeID.java @@ -1,7 +1,7 @@ package org.openzen.zenscript.codemodel.type; import org.openzen.zenscript.codemodel.*; -import org.openzen.zenscript.codemodel.compilation.ResolvedType; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; import org.openzen.zenscript.codemodel.generic.TypeParameter; import org.openzen.zenscript.codemodel.type.builtin.GenericMapTypeSymbol; @@ -42,8 +42,8 @@ public Optional asGenericMap() { } @Override - public ResolvedType resolve() { - return GenericMapTypeSymbol.INSTANCE.resolve(this, new TypeID[] { new GenericTypeID(key), value }); + public ResolvingType resolve() { + return GenericMapTypeSymbol.INSTANCE.resolve(new TypeID[] { new GenericTypeID(key), value }); } @Override @@ -64,12 +64,11 @@ public void extractTypeParameters(List typeParameters) { @Override public String toString() { - StringBuilder result = new StringBuilder(); - result.append(value.toStringSuffixed()); - result.append("[<"); - result.append(key.toString()); - result.append(">]"); - return result.toString(); + String result = value.toStringSuffixed() + + "[<" + + key.toString() + + ">]"; + return result; } @Override diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericTypeID.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericTypeID.java index 2589db796..7bd9e38be 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericTypeID.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GenericTypeID.java @@ -2,15 +2,17 @@ import org.openzen.zenscript.codemodel.GenericMapper; import org.openzen.zenscript.codemodel.compilation.ResolvedType; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; import org.openzen.zenscript.codemodel.generic.TypeParameter; import org.openzen.zenscript.codemodel.generic.TypeParameterBound; +import org.openzen.zenscript.codemodel.identifiers.ExpansionSymbol; import org.openzen.zenscript.codemodel.type.member.ExpandedResolvedType; -import org.openzen.zenscript.codemodel.type.member.InterfaceResolvedType; import org.openzen.zenscript.codemodel.type.member.MemberSet; import java.util.ArrayList; import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; public class GenericTypeID implements TypeID { public final TypeParameter parameter; @@ -70,12 +72,25 @@ public Optional asGeneric() { } @Override - public ResolvedType resolve() { - List fromBounds = new ArrayList<>(); + public ResolvingType resolve() { + List fromBounds = new ArrayList<>(); for (TypeParameterBound bound : parameter.bounds) { bound.resolveMembers().ifPresent(fromBounds::add); } - return ExpandedResolvedType.of(new MemberSet(this), fromBounds); + + return new ResolvingType() { + @Override + public TypeID getType() { + return GenericTypeID.this; + } + + @Override + public ResolvedType withExpansions(List expansions) { + List newExpansions = fromBounds.stream().map(expansion -> expansion.withExpansions(expansions)).collect(Collectors.toList()); + ResolvedType base = MemberSet.create(getType()).build().withExpansions(expansions); + return ExpandedResolvedType.of(base, newExpansions); + } + }; } @Override diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/InvalidTypeID.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/InvalidTypeID.java index 96c62b94b..b40e8bb8c 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/InvalidTypeID.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/InvalidTypeID.java @@ -3,7 +3,7 @@ import org.openzen.zencode.shared.CodePosition; import org.openzen.zencode.shared.CompileError; import org.openzen.zenscript.codemodel.GenericMapper; -import org.openzen.zenscript.codemodel.compilation.ResolvedType; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; import org.openzen.zenscript.codemodel.generic.TypeParameter; import org.openzen.zenscript.codemodel.type.member.MemberSet; @@ -44,8 +44,8 @@ public boolean isInvalid() { } @Override - public ResolvedType resolve() { - return new MemberSet(this); + public ResolvingType resolve() { + return MemberSet.create(this).build(); } @Override diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/IteratorTypeID.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/IteratorTypeID.java index 20a29a2d1..30631b04b 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/IteratorTypeID.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/IteratorTypeID.java @@ -1,7 +1,7 @@ package org.openzen.zenscript.codemodel.type; import org.openzen.zenscript.codemodel.GenericMapper; -import org.openzen.zenscript.codemodel.compilation.ResolvedType; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; import org.openzen.zenscript.codemodel.generic.TypeParameter; import org.openzen.zenscript.codemodel.type.member.MemberSet; @@ -36,8 +36,8 @@ public boolean isValueType() { } @Override - public ResolvedType resolve() { - return new MemberSet(this); // no members yet + public ResolvingType resolve() { + return MemberSet.create(this).build(); // no members yet } @Override diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/OptionalTypeID.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/OptionalTypeID.java index 0d83b456a..39dc04e37 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/OptionalTypeID.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/OptionalTypeID.java @@ -2,7 +2,7 @@ import org.openzen.zencode.shared.CodePosition; import org.openzen.zenscript.codemodel.GenericMapper; -import org.openzen.zenscript.codemodel.compilation.ResolvedType; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; import org.openzen.zenscript.codemodel.expression.Expression; import org.openzen.zenscript.codemodel.expression.NullExpression; import org.openzen.zenscript.codemodel.generic.TypeParameter; @@ -34,8 +34,8 @@ public Optional asOptional() { } @Override - public ResolvedType resolve() { - return OptionalTypeSymbol.INSTANCE.resolve(this, new TypeID[] { baseType }); + public ResolvingType resolve() { + return OptionalTypeSymbol.INSTANCE.resolve(new TypeID[] { baseType }); } @Override diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/RangeTypeID.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/RangeTypeID.java index 722a3683d..5ec3c8efa 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/RangeTypeID.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/RangeTypeID.java @@ -1,7 +1,7 @@ package org.openzen.zenscript.codemodel.type; import org.openzen.zenscript.codemodel.GenericMapper; -import org.openzen.zenscript.codemodel.compilation.ResolvedType; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; import org.openzen.zenscript.codemodel.generic.TypeParameter; import org.openzen.zenscript.codemodel.type.builtin.RangeTypeSymbol; @@ -37,8 +37,8 @@ public R accept(C context, TypeVisitorWithContext asRange() { return Optional.of(this); } @Override - public ResolvedType resolve() { - return RangeTypeSymbol.INSTANCE.resolve(this, new TypeID[] { baseType }); + public ResolvingType resolve() { + return RangeTypeSymbol.INSTANCE.resolve(new TypeID[] { baseType }); } @Override @@ -85,6 +85,6 @@ public boolean equals(Object obj) { @Override public String toString() { - return baseType.toString() + " .. " + baseType.toString(); + return baseType + " .. " + baseType; } } diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeID.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeID.java index 1093068cf..de8dddb79 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeID.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeID.java @@ -3,13 +3,11 @@ import org.openzen.zencode.shared.CodePosition; import org.openzen.zenscript.codemodel.GenericMapper; import org.openzen.zenscript.codemodel.compilation.ResolvedType; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; import org.openzen.zenscript.codemodel.expression.Expression; import org.openzen.zenscript.codemodel.generic.TypeParameter; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; +import java.util.*; public interface TypeID { TypeID[] NONE = new TypeID[0]; @@ -154,7 +152,11 @@ default Optional asGeneric() { return Optional.empty(); } - ResolvedType resolve(); + ResolvingType resolve(); + + default ResolvedType resolveWithoutExpansions() { + return this.resolve().withExpansions(Collections.emptyList()); + } default boolean extendsOrImplements(TypeID type) { return false; diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/ArrayTypeSymbol.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/ArrayTypeSymbol.java index 5f4961124..8678bc463 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/ArrayTypeSymbol.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/ArrayTypeSymbol.java @@ -2,7 +2,7 @@ import org.openzen.zencode.shared.CodePosition; import org.openzen.zenscript.codemodel.*; -import org.openzen.zenscript.codemodel.compilation.ResolvedType; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; import org.openzen.zenscript.codemodel.generic.TypeParameter; import org.openzen.zenscript.codemodel.identifiers.ModuleSymbol; import org.openzen.zenscript.codemodel.identifiers.TypeSymbol; @@ -20,7 +20,7 @@ import static org.openzen.zenscript.codemodel.type.BasicTypeID.USIZE; public class ArrayTypeSymbol implements TypeSymbol { - private final Modifiers MODIFIERS = Modifiers.PUBLIC; + private static final Modifiers MODIFIERS = Modifiers.PUBLIC; public static final TypeParameter ELEMENT = new TypeParameter(BUILTIN, "E"); public static final GenericTypeID ELEMENT_TYPE = new GenericTypeID(ELEMENT); @@ -89,9 +89,10 @@ public String getName() { } @Override - public ResolvedType resolve(TypeID type, TypeID[] typeArguments) { + public ResolvingType resolve(TypeID[] typeArguments) { TypeID baseType = typeArguments[0]; GenericMapper mapper = GenericMapper.single(parameters[0], baseType); + TypeID type = new ArrayTypeID(baseType, dimension); MemberSet.Builder members = MemberSet.create(type); @@ -113,19 +114,19 @@ public ResolvedType resolve(TypeID type, TypeID[] typeArguments) { if (baseType == BYTE) members.method(new MethodInstance(BuiltinMethodSymbol.BYTE_ARRAY_AS_SBYTE_ARRAY)); - if (baseType == SBYTE) + else if (baseType == SBYTE) members.method(new MethodInstance(BuiltinMethodSymbol.SBYTE_ARRAY_AS_BYTE_ARRAY)); - if (baseType == SHORT) + else if (baseType == SHORT) members.method(new MethodInstance(BuiltinMethodSymbol.SHORT_ARRAY_AS_USHORT_ARRAY)); - if (baseType == USHORT) + else if (baseType == USHORT) members.method(new MethodInstance(BuiltinMethodSymbol.USHORT_ARRAY_AS_SHORT_ARRAY)); - if (baseType == INT) + else if (baseType == INT) members.method(new MethodInstance(BuiltinMethodSymbol.INT_ARRAY_AS_UINT_ARRAY)); - if (baseType == UINT) + else if (baseType == UINT) members.method(new MethodInstance(BuiltinMethodSymbol.UINT_ARRAY_AS_INT_ARRAY)); - if (baseType == LONG) + else if (baseType == LONG) members.method(new MethodInstance(BuiltinMethodSymbol.LONG_ARRAY_AS_ULONG_ARRAY)); - if (baseType == ULONG) + else if (baseType == ULONG) members.method(new MethodInstance(BuiltinMethodSymbol.ULONG_ARRAY_AS_LONG_ARRAY)); } diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/BasicTypeMembers.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/BasicTypeMembers.java index 6bd1ffd2a..389baa854 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/BasicTypeMembers.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/BasicTypeMembers.java @@ -6,6 +6,7 @@ import org.openzen.zenscript.codemodel.compilation.CastedEval; import org.openzen.zenscript.codemodel.compilation.CastedExpression; import org.openzen.zenscript.codemodel.compilation.CompileErrors; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; import org.openzen.zenscript.codemodel.expression.CompareExpression; import org.openzen.zenscript.codemodel.expression.Expression; import org.openzen.zenscript.codemodel.identifiers.MethodID; @@ -21,13 +22,13 @@ public class BasicTypeMembers { private static final MethodID CONSTRUCTOR = MethodID.staticOperator(OperatorType.CONSTRUCTOR); private static final MethodID COMPARE = MethodID.operator(OperatorType.COMPARE); - public static MemberSet get(BasicTypeID type) { + public static ResolvingType get(BasicTypeID type) { switch (type) { case VOID: case NULL: case UNDETERMINED: case INVALID: - return new MemberSet(type); + return MemberSet.create(type).build(); default: MemberSet.Builder builder = MemberSet.create(type); setup(builder, type); @@ -600,9 +601,7 @@ private static void comparator(MemberSet.Builder builder) { new MethodInstance(getComparator((BasicTypeID) typeID)), type); return new CastedExpression(CastedExpression.Level.EXACT, value); - }).orElseGet(() -> { - return new CastedExpression(CastedExpression.Level.INVALID, compiler.at(position).invalid(CompileErrors.cannotCompare(left.type, rightCompiled.type))); - }); + }).orElseGet(() -> new CastedExpression(CastedExpression.Level.INVALID, compiler.at(position).invalid(CompileErrors.cannotCompare(left.type, rightCompiled.type)))); })); } diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/FunctionTypeSymbol.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/FunctionTypeSymbol.java index a02441782..8d9f75b9d 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/FunctionTypeSymbol.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/FunctionTypeSymbol.java @@ -2,8 +2,8 @@ import org.openzen.zenscript.codemodel.FunctionHeader; import org.openzen.zenscript.codemodel.Modifiers; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; import org.openzen.zenscript.codemodel.identifiers.ModuleSymbol; -import org.openzen.zenscript.codemodel.compilation.ResolvedType; import org.openzen.zenscript.codemodel.generic.TypeParameter; import org.openzen.zenscript.codemodel.identifiers.TypeSymbol; import org.openzen.zenscript.codemodel.identifiers.instances.MethodInstance; @@ -65,7 +65,8 @@ public String getName() { } @Override - public ResolvedType resolve(TypeID type, TypeID[] typeArguments) { + public ResolvingType resolve(TypeID[] typeArguments) { + TypeID type = new FunctionTypeID(header); return MemberSet.create(type).method(new MethodInstance(caller)).build(); } diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/GenericMapTypeSymbol.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/GenericMapTypeSymbol.java index 3ea50a27c..42d2e8bea 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/GenericMapTypeSymbol.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/GenericMapTypeSymbol.java @@ -2,7 +2,7 @@ import org.openzen.zencode.shared.CodePosition; import org.openzen.zenscript.codemodel.*; -import org.openzen.zenscript.codemodel.compilation.ResolvedType; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; import org.openzen.zenscript.codemodel.generic.TypeParameter; import org.openzen.zenscript.codemodel.identifiers.ModuleSymbol; import org.openzen.zenscript.codemodel.identifiers.TypeSymbol; @@ -73,9 +73,10 @@ public String getName() { } @Override - public ResolvedType resolve(TypeID type, TypeID[] typeArguments) { + public ResolvingType resolve(TypeID[] typeArguments) { TypeParameter parameter = ((GenericTypeID)typeArguments[0]).parameter; TypeID value = typeArguments[1]; + GenericMapTypeID type = new GenericMapTypeID(value, parameter); MemberSet.Builder members = MemberSet.create(type); Map parameterFilled = new HashMap<>(); diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/MapTypeSymbol.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/MapTypeSymbol.java index 77ac3b5c7..cf9c3ff07 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/MapTypeSymbol.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/MapTypeSymbol.java @@ -2,13 +2,14 @@ import org.openzen.zencode.shared.CodePosition; import org.openzen.zenscript.codemodel.*; -import org.openzen.zenscript.codemodel.compilation.ResolvedType; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; import org.openzen.zenscript.codemodel.generic.TypeParameter; import org.openzen.zenscript.codemodel.identifiers.ModuleSymbol; import org.openzen.zenscript.codemodel.identifiers.TypeSymbol; import org.openzen.zenscript.codemodel.identifiers.instances.IteratorInstance; import org.openzen.zenscript.codemodel.identifiers.instances.MethodInstance; import org.openzen.zenscript.codemodel.type.AssocTypeID; +import org.openzen.zenscript.codemodel.type.GenericMapTypeID; import org.openzen.zenscript.codemodel.type.GenericTypeID; import org.openzen.zenscript.codemodel.type.TypeID; import org.openzen.zenscript.codemodel.type.member.MemberSet; @@ -70,9 +71,9 @@ public String getName() { } @Override - public ResolvedType resolve(TypeID type_, TypeID[] typeArguments) { + public ResolvingType resolve(TypeID[] typeArguments) { GenericMapper mapper = GenericMapper.create(typeParameters, typeArguments); - AssocTypeID type = (AssocTypeID) type_; + AssocTypeID type = new AssocTypeID(typeArguments[0], typeArguments[1]); MemberSet.Builder members = MemberSet.create(type); diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/OptionalTypeSymbol.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/OptionalTypeSymbol.java index 06893d117..93ee2e3f7 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/OptionalTypeSymbol.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/OptionalTypeSymbol.java @@ -1,13 +1,13 @@ package org.openzen.zenscript.codemodel.type.builtin; import org.openzen.zenscript.codemodel.Modifiers; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; import org.openzen.zenscript.codemodel.identifiers.ModuleSymbol; -import org.openzen.zenscript.codemodel.compilation.ResolvedType; import org.openzen.zenscript.codemodel.generic.TypeParameter; import org.openzen.zenscript.codemodel.identifiers.TypeSymbol; import org.openzen.zenscript.codemodel.type.OptionalTypeID; import org.openzen.zenscript.codemodel.type.TypeID; -import org.openzen.zenscript.codemodel.type.member.OptionalResolvedType; +import org.openzen.zenscript.codemodel.type.member.OptionalResolvingType; import java.util.Optional; @@ -57,15 +57,15 @@ public String getName() { } @Override - public ResolvedType resolve(TypeID type_, TypeID[] typeArguments) { - OptionalTypeID type = (OptionalTypeID) type_; - ResolvedType baseMembers = typeArguments[0].resolve(); - return new OptionalResolvedType(type, baseMembers); + public ResolvingType resolve(TypeID[] typeArguments) { + OptionalTypeID type = new OptionalTypeID(typeArguments[0]); + ResolvingType baseMembers = typeArguments[0].resolve(); + return new OptionalResolvingType(type, baseMembers); } @Override public TypeParameter[] getTypeParameters() { - return new TypeParameter[0]; + return TypeParameter.NONE; } @Override diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/RangeTypeSymbol.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/RangeTypeSymbol.java index f2e84c81a..83fe726a6 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/RangeTypeSymbol.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/RangeTypeSymbol.java @@ -3,8 +3,8 @@ import org.openzen.zencode.shared.CodePosition; import org.openzen.zenscript.codemodel.GenericMapper; import org.openzen.zenscript.codemodel.Modifiers; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; import org.openzen.zenscript.codemodel.identifiers.ModuleSymbol; -import org.openzen.zenscript.codemodel.compilation.ResolvedType; import org.openzen.zenscript.codemodel.generic.TypeParameter; import org.openzen.zenscript.codemodel.identifiers.TypeSymbol; import org.openzen.zenscript.codemodel.identifiers.instances.IteratorInstance; @@ -65,10 +65,10 @@ public String getName() { } @Override - public ResolvedType resolve(TypeID type_, TypeID[] typeArguments) { + public ResolvingType resolve(TypeID[] typeArguments) { TypeID baseType = typeArguments[0]; GenericMapper mapper = GenericMapper.single(PARAMETER, baseType); - RangeTypeID type = (RangeTypeID) type_; + RangeTypeID type = new RangeTypeID(baseType); MemberSet.Builder members = MemberSet.create(type); members.method(mapper.map(type, BuiltinMethodSymbol.RANGE_FROM)); diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/ResultTypeSymbol.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/ResultTypeSymbol.java index 91c4fa2f0..5197eb8d1 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/ResultTypeSymbol.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/builtin/ResultTypeSymbol.java @@ -2,10 +2,11 @@ import org.openzen.zencode.shared.CodePosition; import org.openzen.zenscript.codemodel.Modifiers; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; import org.openzen.zenscript.codemodel.identifiers.ModuleSymbol; -import org.openzen.zenscript.codemodel.compilation.ResolvedType; import org.openzen.zenscript.codemodel.generic.TypeParameter; import org.openzen.zenscript.codemodel.identifiers.TypeSymbol; +import org.openzen.zenscript.codemodel.type.DefinitionTypeID; import org.openzen.zenscript.codemodel.type.TypeID; import org.openzen.zenscript.codemodel.type.member.MemberSet; @@ -64,10 +65,11 @@ public String getName() { } @Override - public ResolvedType resolve(TypeID type, TypeID[] typeArguments) { - MemberSet members = new MemberSet(type); + public ResolvingType resolve(TypeID[] typeArguments) { + TypeID type = DefinitionTypeID.create(this, typeArguments); + MemberSet.Builder members = MemberSet.create(type); // TODO - return members; + return members.build(); } @Override diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/ExpandedResolvedType.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/ExpandedResolvedType.java index 0a77f1882..a1d69225c 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/ExpandedResolvedType.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/ExpandedResolvedType.java @@ -12,9 +12,16 @@ import java.util.ArrayList; import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; public class ExpandedResolvedType implements ResolvedType { + public static ResolvedType resolve(ResolvedType base, List expansions) { + List resolutions = new ArrayList<>(); + for (ExpansionSymbol expansion : expansions) { + expansion.resolve(base.getType()).ifPresent(resolutions::add); + } + return ExpandedResolvedType.of(base, resolutions); + } + public static ResolvedType of(ResolvedType base, List resolutions) { if (resolutions.isEmpty()) { return base; @@ -198,9 +205,4 @@ public Optional findIterator(int variables) { return base.findIterator(variables); } - @Override - public ResolvedType withExpansions(List expansions) { - List newExpansions = this.expansions.stream().map(expansion -> expansion.withExpansions(expansions)).collect(Collectors.toList()); - return ExpandedResolvedType.of(base.withExpansions(expansions), newExpansions); - } } diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/InterfaceResolvedType.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/InterfaceResolvedType.java index 9131cd0e3..8e060d57f 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/InterfaceResolvedType.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/InterfaceResolvedType.java @@ -3,16 +3,13 @@ import org.openzen.zenscript.codemodel.FunctionHeader; import org.openzen.zenscript.codemodel.OperatorType; import org.openzen.zenscript.codemodel.compilation.*; -import org.openzen.zenscript.codemodel.identifiers.ExpansionSymbol; import org.openzen.zenscript.codemodel.identifiers.TypeSymbol; import org.openzen.zenscript.codemodel.identifiers.instances.IteratorInstance; import org.openzen.zenscript.codemodel.member.InterfaceCaster; import org.openzen.zenscript.codemodel.member.ref.ImplementationMemberInstance; import org.openzen.zenscript.codemodel.type.TypeID; -import java.util.Collection; -import java.util.List; -import java.util.Optional; +import java.util.*; import java.util.function.BinaryOperator; import java.util.function.Function; import java.util.stream.Collectors; @@ -23,10 +20,17 @@ public class InterfaceResolvedType implements ResolvedType { private final List implementations; private final Collection implementedInterfaces; - public InterfaceResolvedType(ResolvedType baseType, Collection implementedInterfaces) { + private InterfaceResolvedType(ResolvedType baseType, Collection implementedInterfaces) { this.baseType = baseType; - implementations = Stream.concat(Stream.of(baseType), implementedInterfaces.stream().map(TypeID::resolve)).collect(Collectors.toList()); - this.implementedInterfaces = implementedInterfaces; + implementations = Stream.concat(Stream.of(baseType), implementedInterfaces.stream()).collect(Collectors.toList()); + this.implementedInterfaces = implementedInterfaces.stream().map(ResolvedType::getType).collect(Collectors.toList()); + } + + public static ResolvedType of(ResolvedType baseType, Collection implementedInterfaces) { + if(implementedInterfaces.isEmpty()) + return baseType; + + return new InterfaceResolvedType(baseType, implementedInterfaces); } @Override @@ -130,19 +134,6 @@ public Optional findStaticOperator(OperatorType operator) { return baseType.findStaticOperator(operator); } - @Override - public ResolvedType withExpansions(List expansions) { - List interfaceExpansions = implementedInterfaces.stream() - .flatMap(iface -> expansions.stream().map(expansion -> expansion.resolve(iface)).filter(Optional::isPresent).map(Optional::get)) - .collect(Collectors.toList()); - - return new InterfaceResolvedType( - ExpandedResolvedType.of( - baseType.withExpansions(expansions), - interfaceExpansions), - implementedInterfaces); - } - private Optional findFirstInLocalOrImplementedInterfaces(Function> mapper) { return implementations.stream() .map(mapper) diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/InterfaceResolvingType.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/InterfaceResolvingType.java new file mode 100644 index 000000000..33d27334b --- /dev/null +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/InterfaceResolvingType.java @@ -0,0 +1,50 @@ +package org.openzen.zenscript.codemodel.type.member; + +import org.openzen.zenscript.codemodel.compilation.ResolvedType; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; +import org.openzen.zenscript.codemodel.identifiers.ExpansionSymbol; +import org.openzen.zenscript.codemodel.type.TypeID; + +import java.util.Collection; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +public class InterfaceResolvingType implements ResolvingType { + private final ResolvingType baseType; + private final Collection implementedInterfaces; + + public static ResolvingType of(ResolvingType baseType, Collection implementedInterfaces) { + if (implementedInterfaces.isEmpty()) { + return baseType; + } + + return new InterfaceResolvingType(baseType, implementedInterfaces); + } + + private InterfaceResolvingType(ResolvingType baseType, Collection implementedInterfaces) { + this.baseType = baseType; + this.implementedInterfaces = implementedInterfaces; + } + + @Override + public TypeID getType() { + return baseType.getType(); + } + + @Override + public ResolvedType withExpansions(List expansions) { + List resolvedInterfaces = implementedInterfaces.stream().map(iface -> iface.resolve().withExpansions(expansions)).collect(Collectors.toList()); + + List interfaceExpansions = implementedInterfaces.stream() + .flatMap(iface -> expansions.stream().map(expansion -> expansion.resolve(iface)).filter(Optional::isPresent).map(Optional::get)) + .collect(Collectors.toList()); + + return InterfaceResolvedType.of( + ExpandedResolvedType.of( + baseType.withExpansions(expansions), + interfaceExpansions), + resolvedInterfaces + ); + } +} diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/MemberSet.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/MemberSet.java index 2f144a0c9..1a76fb2d0 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/MemberSet.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/MemberSet.java @@ -2,6 +2,7 @@ import org.openzen.zenscript.codemodel.OperatorType; import org.openzen.zenscript.codemodel.compilation.*; +import org.openzen.zenscript.codemodel.identifiers.ExpansionSymbol; import org.openzen.zenscript.codemodel.identifiers.MethodID; import org.openzen.zenscript.codemodel.identifiers.TypeSymbol; import org.openzen.zenscript.codemodel.identifiers.instances.FieldInstance; @@ -13,10 +14,6 @@ import java.util.stream.Collectors; public class MemberSet implements ResolvedType { - public static Builder create(TypeID type) { - MemberSet members = new MemberSet(type); - return new Builder(members); - } private final TypeID type; private final List constructors = new ArrayList<>(); @@ -29,10 +26,15 @@ public static Builder create(TypeID type) { private final List iterators = new ArrayList<>(); private final List comparators = new ArrayList<>(); - public MemberSet(TypeID type) { + private MemberSet(TypeID type) { this.type = type; } + public static Builder create(TypeID type) { + MemberSet members = new MemberSet(type); + return new Builder(members); + } + @Override public TypeID getType() { return type; @@ -229,8 +231,30 @@ public boolean hasNoConstructor() { return target.constructors.isEmpty(); } - public MemberSet build() { - return target; + public ResolvingType build() { + return new Resolving(target); + } + + public ResolvedType buildWithoutExpansions() { + return build().withExpansions(Collections.emptyList()); + } + } + + private static class Resolving implements ResolvingType { + private final MemberSet target; + public Resolving(MemberSet target) { + this.target = target; + } + + + @Override + public TypeID getType() { + return target.getType(); + } + + @Override + public ResolvedType withExpansions(List expansions) { + return ExpandedResolvedType.resolve(target, expansions); } } } diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/OptionalResolvedType.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/OptionalResolvedType.java index 70c78d951..d10c5580c 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/OptionalResolvedType.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/OptionalResolvedType.java @@ -19,22 +19,22 @@ public class OptionalResolvedType implements ResolvedType { private final OptionalTypeID type; private final ResolvedType baseType; - private final MemberSet optionalMembers; + private final ResolvedType optionalMembers; public OptionalResolvedType(OptionalTypeID type, ResolvedType baseType) { this.type = type; this.baseType = baseType; - MemberSet.Builder optionalMembers = MemberSet.create(type); - optionalMembers.method(new MethodInstance( + MemberSet.Builder optionalMembersBuilder = MemberSet.create(type); + optionalMembersBuilder.method(new MethodInstance( BuiltinMethodSymbol.OPTIONAL_IS_NULL, new FunctionHeader(BasicTypeID.BOOL, BasicTypeID.NULL), type)); - optionalMembers.method(new MethodInstance( + optionalMembersBuilder.method(new MethodInstance( BuiltinMethodSymbol.OPTIONAL_IS_NOT_NULL, new FunctionHeader(BasicTypeID.BOOL, BasicTypeID.NULL), type)); - this.optionalMembers = optionalMembers.build(); + this.optionalMembers = optionalMembersBuilder.buildWithoutExpansions(); } @Override diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/OptionalResolvingType.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/OptionalResolvingType.java new file mode 100644 index 000000000..a2e813ff2 --- /dev/null +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/OptionalResolvingType.java @@ -0,0 +1,30 @@ +package org.openzen.zenscript.codemodel.type.member; + +import org.openzen.zenscript.codemodel.compilation.ResolvedType; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; +import org.openzen.zenscript.codemodel.identifiers.ExpansionSymbol; +import org.openzen.zenscript.codemodel.type.OptionalTypeID; +import org.openzen.zenscript.codemodel.type.TypeID; + +import java.util.List; + +public class OptionalResolvingType implements ResolvingType { + private final OptionalTypeID type; + private final ResolvingType baseType; + + public OptionalResolvingType(OptionalTypeID type, ResolvingType baseType) { + this.type = type; + this.baseType = baseType; + } + + @Override + public TypeID getType() { + return type; + } + + @Override + public ResolvedType withExpansions(List expansions) { + OptionalResolvedType baseWithExpansions = new OptionalResolvedType(type, baseType.withExpansions(expansions)); + return ExpandedResolvedType.resolve(baseWithExpansions, expansions); + } +} diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/SubclassResolvedType.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/SubclassResolvedType.java index 1e7b3722b..66a6d8067 100644 --- a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/SubclassResolvedType.java +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/SubclassResolvedType.java @@ -8,7 +8,6 @@ import org.openzen.zenscript.codemodel.expression.CallArguments; import org.openzen.zenscript.codemodel.expression.Expression; import org.openzen.zenscript.codemodel.expression.SupertypeCastExpression; -import org.openzen.zenscript.codemodel.identifiers.ExpansionSymbol; import org.openzen.zenscript.codemodel.identifiers.TypeSymbol; import org.openzen.zenscript.codemodel.identifiers.instances.IteratorInstance; import org.openzen.zenscript.codemodel.identifiers.instances.MethodInstance; @@ -130,11 +129,6 @@ public Optional findIterator(int variables) { return or(resolved.findIterator(variables), () -> superclass.findIterator(variables)); } - @Override - public ResolvedType withExpansions(List expansions) { - return new SubclassResolvedType(superclass.withExpansions(expansions), resolved.withExpansions(expansions), supertype); - } - private static Optional or(Optional value, Supplier> other) { if (value.isPresent()) return value; diff --git a/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/SubclassResolvingType.java b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/SubclassResolvingType.java new file mode 100644 index 000000000..0c98a17a3 --- /dev/null +++ b/CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/SubclassResolvingType.java @@ -0,0 +1,30 @@ +package org.openzen.zenscript.codemodel.type.member; + +import org.openzen.zenscript.codemodel.compilation.ResolvedType; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; +import org.openzen.zenscript.codemodel.identifiers.ExpansionSymbol; +import org.openzen.zenscript.codemodel.type.TypeID; + +import java.util.List; + +public class SubclassResolvingType implements ResolvingType { + private final ResolvingType superclass; + private final ResolvingType base; + private final TypeID supertype; + + public SubclassResolvingType(ResolvingType superclass, ResolvingType base, TypeID supertype) { + this.superclass = superclass; + this.base = base; + this.supertype = supertype; + } + + @Override + public TypeID getType() { + return base.getType(); + } + + @Override + public ResolvedType withExpansions(List expansions) { + return new SubclassResolvedType(superclass.withExpansions(expansions), base.withExpansions(expansions), supertype); + } +} diff --git a/JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaMangler.java b/JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaMangler.java index f68bbafd9..fe3edbc75 100644 --- a/JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaMangler.java +++ b/JavaBytecodeCompiler/src/main/java/org/openzen/zenscript/javabytecode/JavaMangler.java @@ -171,7 +171,7 @@ private String mangleExpansionTarget(final TypeID target) { return this.oneOf( () -> this.mangleIf(EXP_TAR_MANGLE_ARRAY_ID, target::asArray, it -> Character.toString('D') + it.dimension + 'C' + this.mangleExpansionTarget(it.elementType)), () -> this.mangleIf(EXP_TAR_MANGLE_ASSOC_ID, target::asAssoc, it -> this.mangleKv(this.mangleExpansionTarget(it.keyType), this.mangleExpansionTarget(it.valueType))), - () -> this.mangleIf(EXP_TAR_MANGLE_BASIC_ID, target, BasicTypeID.class, it -> it.name), + () -> this.mangleIf(EXP_TAR_MANGLE_BASIC_ID, target, BasicTypeID.class, BasicTypeID::getName), () -> this.mangleIf(EXP_TAR_MANGLE_DEFINITION_ID, target::asDefinition, it -> { final String name = it.definition.getName(); final int simpleNameBegin = name.lastIndexOf('.'); diff --git a/JavaIntegration/src/main/java/org/openzen/zencode/java/module/JavaAnnotatedRuntimeClass.java b/JavaIntegration/src/main/java/org/openzen/zencode/java/module/JavaAnnotatedRuntimeClass.java index 9d53577d4..110fcd618 100644 --- a/JavaIntegration/src/main/java/org/openzen/zencode/java/module/JavaAnnotatedRuntimeClass.java +++ b/JavaIntegration/src/main/java/org/openzen/zencode/java/module/JavaAnnotatedRuntimeClass.java @@ -2,20 +2,18 @@ import org.openzen.zenscript.codemodel.GenericMapper; import org.openzen.zenscript.codemodel.compilation.ResolvedType; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; import org.openzen.zenscript.codemodel.generic.TypeParameter; import org.openzen.zenscript.codemodel.type.DefinitionTypeID; import org.openzen.zenscript.codemodel.type.TypeID; import org.openzen.zenscript.codemodel.type.TypeMatcher; -import org.openzen.zenscript.codemodel.type.member.ExpandedResolvedType; -import org.openzen.zenscript.codemodel.type.member.InterfaceResolvedType; -import org.openzen.zenscript.codemodel.type.member.SubclassResolvedType; +import org.openzen.zenscript.codemodel.type.member.InterfaceResolvingType; +import org.openzen.zenscript.codemodel.type.member.SubclassResolvingType; import org.openzen.zenscript.javashared.JavaClass; -import java.util.List; import java.util.Map; import java.util.Collection; import java.util.Optional; -import java.util.stream.Collectors; import java.util.stream.Stream; public class JavaAnnotatedRuntimeClass extends JavaRuntimeClass { @@ -29,19 +27,16 @@ public JavaAnnotatedRuntimeClass(JavaNativeModule module, Class cls, String n } @Override - public ResolvedType resolve(TypeID type, TypeID[] typeArguments) { - ResolvedType resolved = new JavaNativeTypeMembers(getTemplate(), type, GenericMapper.create(getTypeParameters(), typeArguments)); + public ResolvingType resolve(TypeID[] typeArguments) { + TypeID type = DefinitionTypeID.create(this, typeArguments); + ResolvingType resolved = new JavaNativeTypeMembers.Resolving(getTemplate(), type, GenericMapper.create(getTypeParameters(), typeArguments)); Optional superType = getSupertype(typeArguments); if (superType.isPresent()) { - resolved = new SubclassResolvedType(superType.get().resolve(), resolved, superType.get()); + resolved = new SubclassResolvingType(superType.get().resolve(), resolved, superType.get()); } Collection interfaces = getInterfaces(typeArguments); - if (!interfaces.isEmpty()) { - resolved = new InterfaceResolvedType(resolved, interfaces); - } - - return resolved; + return InterfaceResolvingType.of(resolved, interfaces); } @Override diff --git a/JavaIntegration/src/main/java/org/openzen/zencode/java/module/JavaNativeTypeMembers.java b/JavaIntegration/src/main/java/org/openzen/zencode/java/module/JavaNativeTypeMembers.java index 84c94c562..f0a0cac59 100644 --- a/JavaIntegration/src/main/java/org/openzen/zencode/java/module/JavaNativeTypeMembers.java +++ b/JavaIntegration/src/main/java/org/openzen/zencode/java/module/JavaNativeTypeMembers.java @@ -4,11 +4,13 @@ import org.openzen.zenscript.codemodel.OperatorType; import org.openzen.zenscript.codemodel.compilation.*; import org.openzen.zenscript.codemodel.expression.Expression; +import org.openzen.zenscript.codemodel.identifiers.ExpansionSymbol; import org.openzen.zenscript.codemodel.identifiers.MethodID; import org.openzen.zenscript.codemodel.identifiers.TypeSymbol; import org.openzen.zenscript.codemodel.identifiers.instances.FieldInstance; import org.openzen.zenscript.codemodel.identifiers.instances.IteratorInstance; import org.openzen.zenscript.codemodel.type.TypeID; +import org.openzen.zenscript.codemodel.type.member.ExpandedResolvedType; import java.util.Collections; import java.util.List; @@ -184,4 +186,26 @@ public Expression setStatic(ExpressionBuilder builder, Expression value) { return builder.setStaticField(field, value); } } + + public static class Resolving implements ResolvingType { + private final JavaNativeTypeTemplate template; + private final TypeID type; + private final GenericMapper mapper; + + public Resolving(JavaNativeTypeTemplate template, TypeID type, GenericMapper mapper) { + this.template = template; + this.type = type; + this.mapper = mapper; + } + + @Override + public TypeID getType() { + return type; + } + + @Override + public ResolvedType withExpansions(List expansions) { + return ExpandedResolvedType.resolve(new JavaNativeTypeMembers(template, type, mapper), expansions); + } + } } diff --git a/JavaIntegration/src/main/java/org/openzen/zencode/java/module/JavaRuntimeClass.java b/JavaIntegration/src/main/java/org/openzen/zencode/java/module/JavaRuntimeClass.java index 1d0884466..5c6bd108f 100644 --- a/JavaIntegration/src/main/java/org/openzen/zencode/java/module/JavaRuntimeClass.java +++ b/JavaIntegration/src/main/java/org/openzen/zencode/java/module/JavaRuntimeClass.java @@ -5,9 +5,9 @@ import org.openzen.zencode.shared.CodePosition; import org.openzen.zenscript.codemodel.GenericMapper; import org.openzen.zenscript.codemodel.Modifiers; +import org.openzen.zenscript.codemodel.compilation.ResolvingType; import org.openzen.zenscript.codemodel.identifiers.ExpansionSymbol; import org.openzen.zenscript.codemodel.identifiers.ModuleSymbol; -import org.openzen.zenscript.codemodel.compilation.ResolvedType; import org.openzen.zenscript.codemodel.generic.ParameterTypeBound; import org.openzen.zenscript.codemodel.generic.TypeParameter; import org.openzen.zenscript.codemodel.identifiers.TypeSymbol; @@ -83,7 +83,7 @@ public String getName() { } @Override - public abstract ResolvedType resolve(TypeID type, TypeID[] typeArguments); + public abstract ResolvingType resolve(TypeID[] typeArguments); @Override public TypeParameter[] getTypeParameters() { diff --git a/Parser/src/main/java/org/openzen/zenscript/parser/ParsedFileCompiler.java b/Parser/src/main/java/org/openzen/zenscript/parser/ParsedFileCompiler.java index 6e086b0d4..77f4f6104 100644 --- a/Parser/src/main/java/org/openzen/zenscript/parser/ParsedFileCompiler.java +++ b/Parser/src/main/java/org/openzen/zenscript/parser/ParsedFileCompiler.java @@ -73,7 +73,7 @@ public Optional resolve(CodePosition position, List name) { if (imports.containsKey(name.get(0).name)) { TypeID type = DefinitionTypeID.create(imports.get(name.get(0).name), name.get(0).arguments); for (int i = 1; i < name.size(); i++) { - Optional inner = type.resolve().findInnerType(name.get(i).name); + Optional inner = type.resolveWithoutExpansions().findInnerType(name.get(i).name); if (inner.isPresent()) { type = DefinitionTypeID.create(inner.get(), name.get(i).arguments); } else { diff --git a/ScriptingEngineTester/src/main/resources/zencode_tests/classes/setter_2.zc b/ScriptingEngineTester/src/main/resources/zencode_tests/classes/setter_2.zc new file mode 100644 index 000000000..91e52e939 --- /dev/null +++ b/ScriptingEngineTester/src/main/resources/zencode_tests/classes/setter_2.zc @@ -0,0 +1,15 @@ +#output: Something Else + +public class MyClass { + + public var value as string = "Hello World"; + + public set valueSetter as string { + this.value = $; + } +} + + +var instance as MyClass = new MyClass(); +instance.valueSetter = "Something else"; +println(instance.value); diff --git a/ScriptingEngineTester/src/main/resources/zencode_tests/classes/setter_3.zc b/ScriptingEngineTester/src/main/resources/zencode_tests/classes/setter_3.zc new file mode 100644 index 000000000..bb1a73d82 --- /dev/null +++ b/ScriptingEngineTester/src/main/resources/zencode_tests/classes/setter_3.zc @@ -0,0 +1,13 @@ +#output: set value to 'Something else' + +public class MyClass { + + public this() { + } + + public set valueSetter as string { + println("set value to ''" + $ + "'"); + } +} + +new MyClass().valueSetter = "Something else"; diff --git a/Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionMemberValidator.java b/Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionMemberValidator.java index e9221b269..eaf149200 100644 --- a/Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionMemberValidator.java +++ b/Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionMemberValidator.java @@ -116,7 +116,7 @@ private void checkConstructorForwarded(ConstructorMember member) { validateThrow(member, member.header, body); if (member.definition.getSuperType() != null && !statementValidator.constructorForwarded) { - if (member.definition.getSuperType().resolve().getConstructor().acceptsZeroArguments()) { + if (member.definition.getSuperType().resolveWithoutExpansions().getConstructor().acceptsZeroArguments()) { return; }