瀏覽代碼

- Fixed various issues with generics and made instancing strict (all generic types MUST be defined in the mapper or an exception is thrown)

- Member registration mapping is now all-or-nothing: either no mapping is performed (for local scopes) or ALL mentioned type parameters must have an entry in the type parameter map.
- Static inner type IDs (including inner interfaces and inner aliases) no longer record their outer type; this caused problems when comparing types
Stan Hebben 6 年之前
父節點
當前提交
8221a1e43b
共有 40 個文件被更改,包括 329 次插入125 次删除
  1. 15
    18
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java
  2. 37
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/GenericMapper.java
  3. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/AliasDefinition.java
  4. 5
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/InterfaceDefinition.java
  5. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ExpressionBuilder.java
  6. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/CasterMember.java
  7. 5
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FieldMember.java
  8. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ImplementationMember.java
  9. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/InnerDefinitionMember.java
  10. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/ArrayIteratorKeyValues.java
  11. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/ArrayIteratorValues.java
  12. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/AssocIterator.java
  13. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/RangeIterator.java
  14. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/FunctionalMemberRef.java
  15. 0
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/GetterMemberRef.java
  16. 2
    2
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/PropertyRef.java
  17. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/BlockScope.java
  18. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/CompileTypeScope.java
  19. 11
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/DefinitionScope.java
  20. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ExpressionScope.java
  21. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FileScope.java
  22. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ForeachScope.java
  23. 8
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FunctionScope.java
  24. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/GenericFunctionScope.java
  25. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/GlobalScriptScope.java
  26. 5
    9
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ImplementationScope.java
  27. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/LambdaScope.java
  28. 6
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/LoopScope.java
  29. 3
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/TypeScope.java
  30. 1
    1
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GlobalTypeRegistry.java
  31. 4
    7
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ITypeID.java
  32. 0
    18
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/StaticDefinitionTypeID.java
  33. 88
    0
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeParameterCollector.java
  34. 3
    3
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/DefinitionMemberGroup.java
  35. 47
    51
      CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java
  36. 6
    0
      CompilerShared/src/main/java/org/openzen/zenscript/compiler/CompileScope.java
  37. 1
    1
      Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedNewExpression.java
  38. 6
    0
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedCatchClause.java
  39. 6
    0
      Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementSwitch.java
  40. 6
    0
      Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionValidator.java

+ 15
- 18
CodeModel/src/main/java/org/openzen/zenscript/codemodel/FunctionHeader.java 查看文件

@@ -126,31 +126,20 @@ public class FunctionHeader {
126 126
 	
127 127
 	public FunctionHeader inferFromOverride(GlobalTypeRegistry registry, FunctionHeader overridden) {
128 128
 		TypeParameter[] resultTypeParameters = typeParameters;
129
-		GenericMapper mapper;
130
-		if (resultTypeParameters == TypeParameter.NONE) {
131
-			resultTypeParameters = overridden.typeParameters;
132
-			mapper = new GenericMapper(registry, Collections.emptyMap());
133
-		} else {
134
-			Map<TypeParameter, ITypeID> mapping = new HashMap<>();
135
-			for (int i = 0; i < overridden.typeParameters.length; i++)
136
-				mapping.put(overridden.typeParameters[i], registry.getGeneric(typeParameters[i]));
137
-			mapper = new GenericMapper(registry, mapping);
138
-		}
139
-		
140 129
 		ITypeID resultReturnType = this.returnType;
141 130
 		if (resultReturnType == BasicTypeID.UNDETERMINED)
142
-			resultReturnType = overridden.returnType.instance(mapper);
131
+			resultReturnType = overridden.returnType;
143 132
 		
144 133
 		ITypeID resultThrownType = this.thrownType;
145 134
 		if (resultThrownType == null && overridden.thrownType != null)
146
-			resultThrownType = overridden.thrownType.instance(mapper);
135
+			resultThrownType = overridden.thrownType;
147 136
 		
148 137
 		FunctionParameter[] resultParameters = Arrays.copyOf(parameters, parameters.length);
149 138
 		for (int i = 0; i < resultParameters.length; i++) {
150 139
 			if (resultParameters[i].type == BasicTypeID.UNDETERMINED) {
151 140
 				FunctionParameter parameter = resultParameters[i];
152 141
 				FunctionParameter original = overridden.parameters[i];
153
-				resultParameters[i] = new FunctionParameter(original.type.instance(mapper), parameter.name, parameter.defaultValue, original.variadic);
142
+				resultParameters[i] = new FunctionParameter(original.type, parameter.name, parameter.defaultValue, original.variadic);
154 143
 			}
155 144
 		}
156 145
 		
@@ -161,7 +150,7 @@ public class FunctionHeader {
161 150
 		if (arguments.arguments.length < minParameters || arguments.arguments.length > maxParameters)
162 151
 			return false;
163 152
 		
164
-		FunctionHeader header = fillGenericArguments(scope.getTypeRegistry(), arguments.typeArguments);
153
+		FunctionHeader header = fillGenericArguments(scope.getTypeRegistry(), arguments.typeArguments, scope.getLocalTypeParameters());
165 154
 		for (int i = 0; i < header.parameters.length; i++) {
166 155
 			if (arguments.arguments[i].type != header.parameters[i].type)
167 156
 				return false;
@@ -174,7 +163,7 @@ public class FunctionHeader {
174 163
 		if (arguments.arguments.length < minParameters || arguments.arguments.length > maxParameters)
175 164
 			return false;
176 165
 		
177
-		FunctionHeader header = fillGenericArguments(scope.getTypeRegistry(), arguments.typeArguments);
166
+		FunctionHeader header = fillGenericArguments(scope.getTypeRegistry(), arguments.typeArguments, scope.getLocalTypeParameters());
178 167
 		for (int i = 0; i < header.parameters.length; i++) {
179 168
 			if (!scope.getTypeMembers(arguments.arguments[i].type).canCastImplicit(header.parameters[i].type))
180 169
 				return false;
@@ -331,6 +320,14 @@ public class FunctionHeader {
331 320
 	}
332 321
 	
333 322
 	public FunctionHeader withGenericArguments(GenericMapper mapper) {
323
+		if (typeParameters.length > 0) {
324
+			Map<TypeParameter, ITypeID> innerMap = new HashMap<>();
325
+			for (TypeParameter parameter : typeParameters)
326
+				innerMap.put(parameter, mapper.registry.getGeneric(parameter));
327
+			
328
+			mapper = mapper.getInner(innerMap);
329
+		}
330
+		
334 331
 		ITypeID returnType = this.returnType.instance(mapper);
335 332
 		FunctionParameter[] parameters = new FunctionParameter[this.parameters.length];
336 333
 		for (int i = 0; i < parameters.length; i++) {
@@ -339,14 +336,14 @@ public class FunctionHeader {
339 336
 		return new FunctionHeader(typeParameters, returnType, thrownType == null ? null : thrownType.instance(mapper), parameters);
340 337
 	}
341 338
 	
342
-	public FunctionHeader fillGenericArguments(GlobalTypeRegistry registry, ITypeID[] arguments) {
339
+	public FunctionHeader fillGenericArguments(GlobalTypeRegistry registry, ITypeID[] arguments, GenericMapper typeParameterMapping) {
343 340
 		if (arguments == null || arguments.length == 0)
344 341
 			return this;
345 342
 		
346 343
 		Map<TypeParameter, ITypeID> typeArguments = new HashMap<>();
347 344
 		for (int i = 0; i < typeParameters.length; i++)
348 345
 			typeArguments.put(typeParameters[i], arguments[i]);
349
-		GenericMapper mapper = new GenericMapper(registry, typeArguments);
346
+		GenericMapper mapper = typeParameterMapping.getInner(typeArguments);
350 347
 		
351 348
 		ITypeID returnType = this.returnType.instance(mapper);
352 349
 		FunctionParameter[] parameters = new FunctionParameter[this.parameters.length];

+ 37
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/GenericMapper.java 查看文件

@@ -6,6 +6,7 @@
6 6
 package org.openzen.zenscript.codemodel;
7 7
 
8 8
 import java.util.Collections;
9
+import java.util.HashMap;
9 10
 import java.util.Map;
10 11
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
11 12
 import org.openzen.zenscript.codemodel.type.GenericTypeID;
@@ -46,10 +47,46 @@ public class GenericMapper {
46 47
 	}
47 48
 	
48 49
 	public ITypeID map(GenericTypeID type) {
50
+		if (!mapping.containsKey(type.parameter))
51
+			throw new IllegalStateException("No mapping found for type " + type);
52
+		
49 53
 		return mapping.containsKey(type.parameter) ? mapping.get(type.parameter) : type;
50 54
 	}
51 55
 	
52 56
 	public FunctionHeader map(FunctionHeader original) {
53 57
 		return mapping.isEmpty() ? original : original.withGenericArguments(this);
54 58
 	}
59
+	
60
+	public GenericMapper getInner(Map<TypeParameter, ITypeID> mapping) {
61
+		Map<TypeParameter, ITypeID> resultMap = new HashMap<>(this.mapping);
62
+		resultMap.putAll(mapping);
63
+		return new GenericMapper(registry, resultMap);
64
+	}
65
+	
66
+	public GenericMapper getInner(GlobalTypeRegistry registry, TypeParameter[] parameters) {
67
+		Map<TypeParameter, ITypeID> resultMap = new HashMap<>(this.mapping);
68
+		for (TypeParameter parameter : parameters)
69
+			resultMap.put(parameter, registry.getGeneric(parameter));
70
+		return new GenericMapper(registry, resultMap);
71
+	}
72
+	
73
+	@Override
74
+	public String toString() {
75
+		if (mapping.isEmpty())
76
+			return "{}";
77
+		
78
+		StringBuilder result = new StringBuilder();
79
+		result.append('{');
80
+		boolean first = true;
81
+		for (Map.Entry<TypeParameter, ITypeID> entry : mapping.entrySet()) {
82
+			if (first) {
83
+				first = false;
84
+			} else {
85
+				result.append(", ");
86
+			}
87
+			result.append(entry.getKey().toString()).append(": ").append(entry.getValue());
88
+		}
89
+		result.append('}');
90
+		return result.toString();
91
+	}
55 92
 }

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/AliasDefinition.java 查看文件

@@ -7,6 +7,7 @@ package org.openzen.zenscript.codemodel.definition;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9 9
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
10
+import org.openzen.zenscript.codemodel.Modifiers;
10 11
 import org.openzen.zenscript.codemodel.scope.TypeScope;
11 12
 import org.openzen.zenscript.codemodel.type.ITypeID;
12 13
 
@@ -27,6 +28,11 @@ public class AliasDefinition extends HighLevelDefinition {
27 28
 		
28 29
 		this.type = type;
29 30
 	}
31
+	
32
+	@Override
33
+	public boolean isStatic() {
34
+		return true;
35
+	}
30 36
 
31 37
 	@Override
32 38
 	public <T> T accept(DefinitionVisitor<T> visitor) {

+ 5
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/definition/InterfaceDefinition.java 查看文件

@@ -9,7 +9,6 @@ import java.util.ArrayList;
9 9
 import java.util.List;
10 10
 import org.openzen.zencode.shared.CodePosition;
11 11
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
12
-import org.openzen.zenscript.codemodel.Modifiers;
13 12
 import org.openzen.zenscript.codemodel.type.ITypeID;
14 13
 
15 14
 /**
@@ -26,6 +25,11 @@ public class InterfaceDefinition extends HighLevelDefinition {
26 25
 	public void addBaseInterface(ITypeID baseInterface) {
27 26
 		baseInterfaces.add(baseInterface);
28 27
 	}
28
+	
29
+	@Override
30
+	public boolean isStatic() {
31
+		return true;
32
+	}
29 33
 
30 34
 	@Override
31 35
 	public <T> T accept(DefinitionVisitor<T> visitor) {

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/expression/ExpressionBuilder.java 查看文件

@@ -59,7 +59,7 @@ public class ExpressionBuilder {
59 59
 				type,
60 60
 				member,
61 61
 				compiledArguments,
62
-				compiledArguments.getNumberOfTypeArguments() == 0 ? member.getHeader() : member.getHeader().fillGenericArguments(scope.getTypeRegistry(), compiledArguments.typeArguments));
62
+				compiledArguments.getNumberOfTypeArguments() == 0 ? member.getHeader() : member.getHeader().fillGenericArguments(scope.getTypeRegistry(), compiledArguments.typeArguments, scope.getLocalTypeParameters()));
63 63
 	}
64 64
 	
65 65
 	public Expression not(Expression value) {

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/CasterMember.java 查看文件

@@ -50,7 +50,7 @@ public class CasterMember extends FunctionalMember {
50 50
 
51 51
 	@Override
52 52
 	public void registerTo(TypeMembers type, TypeMemberPriority priority, GenericMapper mapper) {
53
-		type.addCaster(new CasterMemberRef(this, mapper.map(toType)), priority);
53
+		type.addCaster(new CasterMemberRef(this, mapper == null ? toType : mapper.map(toType)), priority);
54 54
 	}
55 55
 
56 56
 	@Override

+ 5
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/FieldMember.java 查看文件

@@ -64,7 +64,10 @@ public class FieldMember extends PropertyMember {
64 64
 		
65 65
 		if (autoGetterAccess != 0) {
66 66
 			this.autoGetter = new GetterMember(position, definition, autoGetterAccess, name, type, null);
67
-			this.autoGetter.setBody(new ReturnStatement(position, new GetFieldExpression(position, new ThisExpression(position, thisType), new FieldMemberRef(this, GenericMapper.EMPTY))));
67
+			this.autoGetter.setBody(new ReturnStatement(position, new GetFieldExpression(
68
+					position,
69
+					new ThisExpression(position, thisType),
70
+					new FieldMemberRef(this, null))));
68 71
 		} else {
69 72
 			this.autoGetter = null;
70 73
 		}
@@ -73,7 +76,7 @@ public class FieldMember extends PropertyMember {
73 76
 			this.autoSetter.setBody(new ExpressionStatement(position, new SetFieldExpression(
74 77
 					position,
75 78
 					new ThisExpression(position, thisType),
76
-					new FieldMemberRef(this, GenericMapper.EMPTY),
79
+					new FieldMemberRef(this, null),
77 80
 					new GetFunctionParameterExpression(position, this.autoSetter.header.parameters[0]))));
78 81
 		} else {
79 82
 			this.autoSetter = null;

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ImplementationMember.java 查看文件

@@ -38,7 +38,7 @@ public class ImplementationMember extends DefinitionMember {
38 38
 
39 39
 	@Override
40 40
 	public void registerTo(TypeMembers members, TypeMemberPriority priority, GenericMapper mapper) {
41
-		ITypeID instancedType = mapper.map(type);
41
+		ITypeID instancedType = mapper == null ? type : mapper.map(type);
42 42
 		members.addImplementation(new ImplementationMemberRef(this, instancedType), priority);
43 43
 		
44 44
 		TypeMembers interfaceTypeMembers = members.getMemberCache().get(instancedType);

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/InnerDefinitionMember.java 查看文件

@@ -32,7 +32,7 @@ public class InnerDefinitionMember extends DefinitionMember {
32 32
 
33 33
 	@Override
34 34
 	public void registerTo(TypeMembers type, TypeMemberPriority priority, GenericMapper mapper) {
35
-		if (isStatic() || mapper.getMapping().isEmpty()) {
35
+		if (isStatic() || mapper == null || mapper.getMapping().isEmpty()) {
36 36
 			type.addInnerType(innerDefinition.name, new InnerDefinition(innerDefinition));
37 37
 		} else {
38 38
 			type.addInnerType(innerDefinition.name, new InnerDefinition(innerDefinition, mapper.getMapping()));

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/ArrayIteratorKeyValues.java 查看文件

@@ -65,7 +65,7 @@ public class ArrayIteratorKeyValues extends Taggable implements IIteratorMember
65 65
 
66 66
 	@Override
67 67
 	public void registerTo(TypeMembers members, TypeMemberPriority priority, GenericMapper mapper) {
68
-		members.addIterator(new IteratorMemberRef(this, mapper.map(loopVariableTypes)), priority);
68
+		members.addIterator(new IteratorMemberRef(this, mapper == null ? loopVariableTypes : mapper.map(loopVariableTypes)), priority);
69 69
 	}
70 70
 
71 71
 	@Override

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/ArrayIteratorValues.java 查看文件

@@ -60,7 +60,7 @@ public class ArrayIteratorValues extends Taggable implements IIteratorMember {
60 60
 
61 61
 	@Override
62 62
 	public void registerTo(TypeMembers members, TypeMemberPriority priority, GenericMapper mapper) {
63
-		members.addIterator(new IteratorMemberRef(this, mapper.map(loopVariableTypes)), priority);
63
+		members.addIterator(new IteratorMemberRef(this, mapper == null ? loopVariableTypes : mapper.map(loopVariableTypes)), priority);
64 64
 	}
65 65
 
66 66
 	@Override

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/AssocIterator.java 查看文件

@@ -63,7 +63,7 @@ public class AssocIterator extends Taggable implements IIteratorMember {
63 63
 
64 64
 	@Override
65 65
 	public void registerTo(TypeMembers type, TypeMemberPriority priority, GenericMapper mapper) {
66
-		type.addIterator(new IteratorMemberRef(this, mapper.map(loopVariableTypes)), priority);
66
+		type.addIterator(new IteratorMemberRef(this, mapper == null ? loopVariableTypes : mapper.map(loopVariableTypes)), priority);
67 67
 	}
68 68
 
69 69
 	@Override

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/builtin/RangeIterator.java 查看文件

@@ -71,7 +71,7 @@ public class RangeIterator extends Taggable implements IIteratorMember {
71 71
 
72 72
 	@Override
73 73
 	public void registerTo(TypeMembers type, TypeMemberPriority priority, GenericMapper mapper) {
74
-		type.addIterator(new IteratorMemberRef(this, mapper.map(loopVariableTypes)), priority);
74
+		type.addIterator(new IteratorMemberRef(this, mapper == null ? loopVariableTypes : mapper.map(loopVariableTypes)), priority);
75 75
 	}
76 76
 
77 77
 	@Override

+ 2
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/FunctionalMemberRef.java 查看文件

@@ -41,7 +41,7 @@ public class FunctionalMemberRef implements DefinitionMemberRef {
41 41
 			header = null;
42 42
 			this.mapper = mapper;
43 43
 		} else {
44
-			header = mapper.map(target.header);
44
+			header = mapper == null ? target.header : mapper.map(target.header);
45 45
 			this.mapper = null;
46 46
 		}
47 47
 	}
@@ -56,7 +56,7 @@ public class FunctionalMemberRef implements DefinitionMemberRef {
56 56
 			if (target.header.hasUnknowns)
57 57
 				throw new IllegalStateException("member is not yet resolved!");
58 58
 			
59
-			header = mapper.map(target.header);
59
+			header = mapper == null ? target.header : mapper.map(target.header);
60 60
 			this.mapper = null;
61 61
 		}
62 62
 		

+ 0
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/GetterMemberRef.java 查看文件

@@ -6,9 +6,7 @@
6 6
 package org.openzen.zenscript.codemodel.member.ref;
7 7
 
8 8
 import org.openzen.zencode.shared.CodePosition;
9
-import org.openzen.zenscript.codemodel.FunctionHeader;
10 9
 import org.openzen.zenscript.codemodel.GenericMapper;
11
-import org.openzen.zenscript.codemodel.annotations.MemberAnnotation;
12 10
 import org.openzen.zenscript.codemodel.expression.Expression;
13 11
 import org.openzen.zenscript.codemodel.expression.GetterExpression;
14 12
 import org.openzen.zenscript.codemodel.expression.StaticGetterExpression;

+ 2
- 2
CodeModel/src/main/java/org/openzen/zenscript/codemodel/member/ref/PropertyRef.java 查看文件

@@ -30,7 +30,7 @@ public abstract class PropertyRef implements DefinitionMemberRef {
30 30
 			type = null;
31 31
 			this.mapper = mapper;
32 32
 		} else {
33
-			type = member.getType().instance(mapper);
33
+			type = mapper == null ? member.getType() : member.getType().instance(mapper);
34 34
 			this.mapper = null;
35 35
 		}
36 36
 	}
@@ -40,7 +40,7 @@ public abstract class PropertyRef implements DefinitionMemberRef {
40 40
 			if (member.getType() == BasicTypeID.UNDETERMINED)
41 41
 				throw new IllegalStateException("Property is not yet resolved!");
42 42
 			
43
-			type = member.getType().instance(mapper);
43
+			type = mapper == null ? member.getType() : member.getType().instance(mapper);
44 44
 			mapper = null;
45 45
 		}
46 46
 		

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/BlockScope.java 查看文件

@@ -10,6 +10,7 @@ import java.util.function.Function;
10 10
 import org.openzen.zencode.shared.CodePosition;
11 11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12 12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
+import org.openzen.zenscript.codemodel.GenericMapper;
13 14
 import org.openzen.zenscript.codemodel.expression.Expression;
14 15
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
15 16
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
@@ -82,4 +83,9 @@ public class BlockScope extends StatementScope {
82 83
 	public TypeMemberPreparer getPreparer() {
83 84
 		return parent.getPreparer();
84 85
 	}
86
+
87
+	@Override
88
+	public GenericMapper getLocalTypeParameters() {
89
+		return parent.getLocalTypeParameters();
90
+	}
85 91
 }

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/CompileTypeScope.java 查看文件

@@ -11,6 +11,7 @@ import java.util.Map;
11 11
 import java.util.function.Function;
12 12
 import org.openzen.zencode.shared.CodePosition;
13 13
 import org.openzen.zenscript.codemodel.FunctionHeader;
14
+import org.openzen.zenscript.codemodel.GenericMapper;
14 15
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
15 16
 import org.openzen.zenscript.codemodel.expression.Expression;
16 17
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
@@ -94,4 +95,9 @@ public class CompileTypeScope extends BaseScope {
94 95
 	public TypeMemberPreparer getPreparer() {
95 96
 		return outer.getPreparer();
96 97
 	}
98
+
99
+	@Override
100
+	public GenericMapper getLocalTypeParameters() {
101
+		return outer.getLocalTypeParameters();
102
+	}
97 103
 }

+ 11
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/DefinitionScope.java 查看文件

@@ -17,6 +17,7 @@ import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
17 17
 
18 18
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
19 19
 import org.openzen.zenscript.codemodel.FunctionHeader;
20
+import org.openzen.zenscript.codemodel.GenericMapper;
20 21
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
21 22
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
22 23
 import org.openzen.zenscript.codemodel.expression.Expression;
@@ -42,6 +43,7 @@ public class DefinitionScope extends BaseScope {
42 43
 	private final TypeMembers members;
43 44
 	private final Map<String, TypeParameter> genericParameters = new HashMap<>();
44 45
 	private final Map<String, Supplier<HighLevelDefinition>> innerTypes = new HashMap<>();
46
+	private final GenericMapper typeParameterMap;
45 47
 	
46 48
 	public DefinitionScope(BaseScope outer, HighLevelDefinition definition) {
47 49
 		this(outer, definition, true);
@@ -51,12 +53,14 @@ public class DefinitionScope extends BaseScope {
51 53
 		this.outer = outer;
52 54
 		this.definition = definition;
53 55
 		
56
+		Map<TypeParameter, ITypeID> typeParameters = new HashMap<>();
54 57
 		if (definition instanceof ExpansionDefinition) {
55 58
 			ExpansionDefinition expansion = (ExpansionDefinition)definition;
56 59
 			type = expansion.target;
57 60
 			
58 61
 			for (TypeParameter parameter : expansion.genericParameters) {
59 62
 				genericParameters.put(parameter.name, parameter);
63
+				typeParameters.put(parameter, outer.getTypeRegistry().getGeneric(parameter));
60 64
 			}
61 65
 		} else {
62 66
 			DefinitionTypeID definitionType = outer.getTypeRegistry().getForMyDefinition(definition);
@@ -65,12 +69,14 @@ public class DefinitionScope extends BaseScope {
65 69
 			while (definitionType != null) {
66 70
 				for (TypeParameter parameter : definitionType.definition.genericParameters) {
67 71
 					genericParameters.put(parameter.name, parameter);
72
+					typeParameters.put(parameter, outer.getTypeRegistry().getGeneric(parameter));
68 73
 				}
69 74
 				definitionType = definitionType.definition.isStatic() ? null : definitionType.outer;
70 75
 			}
71 76
 		}
72 77
 		
73 78
 		members = withMembers ? outer.getMemberCache().get(type) : null;
79
+		typeParameterMap = outer.getLocalTypeParameters().getInner(typeParameters);
74 80
 	}
75 81
 	
76 82
 	public void addInnerType(String name, Supplier<HighLevelDefinition> innerType) {
@@ -160,4 +166,9 @@ public class DefinitionScope extends BaseScope {
160 166
 	public TypeMemberPreparer getPreparer() {
161 167
 		return outer.getPreparer();
162 168
 	}
169
+
170
+	@Override
171
+	public GenericMapper getLocalTypeParameters() {
172
+		return typeParameterMap;
173
+	}
163 174
 }

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ExpressionScope.java 查看文件

@@ -13,6 +13,7 @@ import java.util.function.Function;
13 13
 import org.openzen.zencode.shared.CodePosition;
14 14
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
15 15
 import org.openzen.zenscript.codemodel.FunctionHeader;
16
+import org.openzen.zenscript.codemodel.GenericMapper;
16 17
 import org.openzen.zenscript.codemodel.expression.Expression;
17 18
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
18 19
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
@@ -164,4 +165,9 @@ public class ExpressionScope extends BaseScope {
164 165
 	public TypeMemberPreparer getPreparer() {
165 166
 		return outer.getPreparer();
166 167
 	}
168
+
169
+	@Override
170
+	public GenericMapper getLocalTypeParameters() {
171
+		return outer.getLocalTypeParameters();
172
+	}
167 173
 }

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FileScope.java 查看文件

@@ -14,6 +14,7 @@ import org.openzen.zencode.shared.CompileException;
14 14
 import org.openzen.zencode.shared.CompileExceptionCode;
15 15
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
16 16
 import org.openzen.zenscript.codemodel.FunctionHeader;
17
+import org.openzen.zenscript.codemodel.GenericMapper;
17 18
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
18 19
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
19 20
 import org.openzen.zenscript.codemodel.expression.Expression;
@@ -123,4 +124,9 @@ public class FileScope extends BaseScope {
123 124
 	public TypeMemberPreparer getPreparer() {
124 125
 		return preparer;
125 126
 	}
127
+
128
+	@Override
129
+	public GenericMapper getLocalTypeParameters() {
130
+		return GenericMapper.EMPTY;
131
+	}
126 132
 }

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ForeachScope.java 查看文件

@@ -10,6 +10,7 @@ import java.util.function.Function;
10 10
 import org.openzen.zencode.shared.CodePosition;
11 11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12 12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
+import org.openzen.zenscript.codemodel.GenericMapper;
13 14
 import org.openzen.zenscript.codemodel.expression.Expression;
14 15
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
15 16
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
@@ -102,4 +103,9 @@ public class ForeachScope extends StatementScope {
102 103
 	public TypeMemberPreparer getPreparer() {
103 104
 		return outer.getPreparer();
104 105
 	}
106
+
107
+	@Override
108
+	public GenericMapper getLocalTypeParameters() {
109
+		return outer.getLocalTypeParameters();
110
+	}
105 111
 }

+ 8
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/FunctionScope.java 查看文件

@@ -11,6 +11,7 @@ import org.openzen.zencode.shared.CodePosition;
11 11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12 12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13 13
 import org.openzen.zenscript.codemodel.FunctionParameter;
14
+import org.openzen.zenscript.codemodel.GenericMapper;
14 15
 import org.openzen.zenscript.codemodel.expression.Expression;
15 16
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
16 17
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
@@ -29,10 +30,12 @@ import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
29 30
 public class FunctionScope extends StatementScope {
30 31
 	private final BaseScope outer;
31 32
 	private final FunctionHeader header;
33
+	private final GenericMapper typeParameterMap;
32 34
 	
33 35
 	public FunctionScope(BaseScope outer, FunctionHeader header) {
34 36
 		this.outer = outer;
35 37
 		this.header = header;
38
+		typeParameterMap = outer.getLocalTypeParameters().getInner(outer.getTypeRegistry(), header.typeParameters);
36 39
 	}
37 40
 	
38 41
 	@Override
@@ -116,4 +119,9 @@ public class FunctionScope extends StatementScope {
116 119
 	public TypeMemberPreparer getPreparer() {
117 120
 		return outer.getPreparer();
118 121
 	}
122
+
123
+	@Override
124
+	public GenericMapper getLocalTypeParameters() {
125
+		return typeParameterMap;
126
+	}
119 127
 }

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/GenericFunctionScope.java 查看文件

@@ -12,6 +12,7 @@ import java.util.function.Function;
12 12
 import org.openzen.zencode.shared.CodePosition;
13 13
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
14 14
 import org.openzen.zenscript.codemodel.FunctionHeader;
15
+import org.openzen.zenscript.codemodel.GenericMapper;
15 16
 import org.openzen.zenscript.codemodel.expression.Expression;
16 17
 import org.openzen.zenscript.codemodel.generic.TypeParameter;
17 18
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
@@ -93,4 +94,9 @@ public class GenericFunctionScope extends BaseScope {
93 94
 	public TypeMemberPreparer getPreparer() {
94 95
 		return outer.getPreparer();
95 96
 	}
97
+
98
+	@Override
99
+	public GenericMapper getLocalTypeParameters() {
100
+		return outer.getLocalTypeParameters();
101
+	}
96 102
 }

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/GlobalScriptScope.java 查看文件

@@ -10,6 +10,7 @@ import java.util.function.Function;
10 10
 import org.openzen.zencode.shared.CodePosition;
11 11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12 12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
+import org.openzen.zenscript.codemodel.GenericMapper;
13 14
 import org.openzen.zenscript.codemodel.expression.Expression;
14 15
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
15 16
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
@@ -82,4 +83,9 @@ public class GlobalScriptScope extends StatementScope {
82 83
 	public TypeMemberPreparer getPreparer() {
83 84
 		return file.getPreparer();
84 85
 	}
86
+
87
+	@Override
88
+	public GenericMapper getLocalTypeParameters() {
89
+		return GenericMapper.EMPTY;
90
+	}
85 91
 }

+ 5
- 9
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/ImplementationScope.java 查看文件

@@ -5,7 +5,6 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.scope;
7 7
 
8
-import java.util.Collections;
9 8
 import java.util.List;
10 9
 import java.util.function.Function;
11 10
 import org.openzen.zencode.shared.CodePosition;
@@ -14,7 +13,6 @@ import org.openzen.zenscript.codemodel.FunctionHeader;
14 13
 import org.openzen.zenscript.codemodel.GenericMapper;
15 14
 import org.openzen.zenscript.codemodel.expression.Expression;
16 15
 import org.openzen.zenscript.codemodel.expression.ThisExpression;
17
-import org.openzen.zenscript.codemodel.member.IDefinitionMember;
18 16
 import org.openzen.zenscript.codemodel.member.ImplementationMember;
19 17
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
20 18
 import org.openzen.zenscript.codemodel.partial.PartialTypeExpression;
@@ -23,7 +21,6 @@ import org.openzen.zenscript.codemodel.type.GenericName;
23 21
 import org.openzen.zenscript.codemodel.type.ITypeID;
24 22
 import org.openzen.zenscript.codemodel.type.member.LocalMemberCache;
25 23
 import org.openzen.zenscript.codemodel.type.member.TypeMemberPreparer;
26
-import org.openzen.zenscript.codemodel.type.member.TypeMemberPriority;
27 24
 import org.openzen.zenscript.codemodel.type.member.TypeMembers;
28 25
 
29 26
 /**
@@ -40,12 +37,6 @@ public class ImplementationScope extends BaseScope {
40 37
 		this.implementation = implementation;
41 38
 		
42 39
 		members = outer.getTypeMembers(implementation.type);
43
-		/*members = new TypeMembers(outer.getMemberCache(), implementation.type);
44
-		interfaceMembers.copyMembersTo(implementation.position, interfaceMembers, TypeMemberPriority.INHERITED);
45
-		
46
-		for (IDefinitionMember member : implementation.members) {
47
-			member.registerTo(members, TypeMemberPriority.SPECIFIED, new GenericMapper(outer.getTypeRegistry(), Collections.emptyMap()));
48
-		}*/
49 40
 	}
50 41
 
51 42
 	@Override
@@ -110,4 +101,9 @@ public class ImplementationScope extends BaseScope {
110 101
 	public TypeMemberPreparer getPreparer() {
111 102
 		return outer.getPreparer();
112 103
 	}
104
+
105
+	@Override
106
+	public GenericMapper getLocalTypeParameters() {
107
+		return outer.getLocalTypeParameters();
108
+	}
113 109
 }

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/LambdaScope.java 查看文件

@@ -11,6 +11,7 @@ import org.openzen.zencode.shared.CodePosition;
11 11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12 12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13 13
 import org.openzen.zenscript.codemodel.FunctionParameter;
14
+import org.openzen.zenscript.codemodel.GenericMapper;
14 15
 import org.openzen.zenscript.codemodel.expression.Expression;
15 16
 import org.openzen.zenscript.codemodel.expression.GetFunctionParameterExpression;
16 17
 import org.openzen.zenscript.codemodel.expression.LambdaClosure;
@@ -101,4 +102,9 @@ public class LambdaScope extends StatementScope {
101 102
 	public TypeMemberPreparer getPreparer() {
102 103
 		return outer.getPreparer();
103 104
 	}
105
+
106
+	@Override
107
+	public GenericMapper getLocalTypeParameters() {
108
+		return outer.getLocalTypeParameters();
109
+	}
104 110
 }

+ 6
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/LoopScope.java 查看文件

@@ -10,6 +10,7 @@ import java.util.function.Function;
10 10
 import org.openzen.zencode.shared.CodePosition;
11 11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12 12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
+import org.openzen.zenscript.codemodel.GenericMapper;
13 14
 import org.openzen.zenscript.codemodel.expression.Expression;
14 15
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
15 16
 import org.openzen.zenscript.codemodel.statement.LoopStatement;
@@ -90,4 +91,9 @@ public class LoopScope extends StatementScope {
90 91
 	public TypeMemberPreparer getPreparer() {
91 92
 		return outer.getPreparer();
92 93
 	}
94
+
95
+	@Override
96
+	public GenericMapper getLocalTypeParameters() {
97
+		return outer.getLocalTypeParameters();
98
+	}
93 99
 }

+ 3
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/scope/TypeScope.java 查看文件

@@ -5,6 +5,7 @@
5 5
  */
6 6
 package org.openzen.zenscript.codemodel.scope;
7 7
 
8
+import org.openzen.zenscript.codemodel.GenericMapper;
8 9
 import org.openzen.zenscript.codemodel.context.TypeResolutionContext;
9 10
 import org.openzen.zenscript.codemodel.type.GlobalTypeRegistry;
10 11
 import org.openzen.zenscript.codemodel.type.ITypeID;
@@ -29,4 +30,6 @@ public interface TypeScope extends TypeResolutionContext {
29 30
 	}
30 31
 	
31 32
 	TypeMemberPreparer getPreparer();
33
+	
34
+	GenericMapper getLocalTypeParameters();
32 35
 }

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GlobalTypeRegistry.java 查看文件

@@ -128,7 +128,7 @@ public class GlobalTypeRegistry {
128 128
 	}
129 129
 	
130 130
 	public DefinitionTypeID getForDefinition(HighLevelDefinition definition, ITypeID[] typeParameters, DefinitionTypeID outer) {
131
-		DefinitionTypeID id = new DefinitionTypeID(this, definition, typeParameters, outer);
131
+		DefinitionTypeID id = new DefinitionTypeID(this, definition, typeParameters, definition.isStatic() ? null : outer);
132 132
 		
133 133
 		if (definitionTypes.containsKey(id)) {
134 134
 			return definitionTypes.get(id);

+ 4
- 7
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/ITypeID.java 查看文件

@@ -76,7 +76,7 @@ public interface ITypeID {
76 76
 	// Infers type parameters for this type so it matches with targetType
77 77
 	// returns false if that isn't possible
78 78
 	public default boolean inferTypeParameters(LocalMemberCache cache, ITypeID targetType, Map<TypeParameter, ITypeID> mapping) {
79
-		return accept(new MatchingTypeVisitor(cache, targetType, mapping));
79
+		return targetType.accept(new MatchingTypeVisitor(cache, this, mapping));
80 80
 	}
81 81
 	
82 82
 	public void extractTypeParameters(List<TypeParameter> typeParameters);
@@ -118,8 +118,8 @@ public interface ITypeID {
118 118
 		public Boolean visitAssoc(AssocTypeID assoc) {
119 119
 			if (type instanceof AssocTypeID) {
120 120
 				AssocTypeID assocType = (AssocTypeID) type;
121
-				return match(assoc.keyType, assocType.keyType)
122
-						&& match(assoc.valueType, assocType.valueType);
121
+				return match(assocType.keyType, assoc.keyType)
122
+						&& match(assocType.valueType, assoc.valueType);
123 123
 			} else {
124 124
 				return false;
125 125
 			}
@@ -187,7 +187,7 @@ public interface ITypeID {
187 187
 		public Boolean visitGeneric(GenericTypeID generic) {
188 188
 			if (mapping.containsKey(generic.parameter)) {
189 189
 				return mapping.get(generic.parameter) == type;
190
-			} else if (generic.matches(cache, type)) {
190
+			} else if (type == generic || generic.matches(cache, type)) {
191 191
 				mapping.put(generic.parameter, type);
192 192
 				return true;
193 193
 			} else {
@@ -216,9 +216,6 @@ public interface ITypeID {
216 216
 		}
217 217
 		
218 218
 		private boolean match(ITypeID type, ITypeID pattern) {
219
-			if (type == pattern)
220
-				return true;
221
-			
222 219
 			return pattern.accept(new MatchingTypeVisitor(cache, type, mapping));
223 220
 		}
224 221
 

+ 0
- 18
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/StaticDefinitionTypeID.java 查看文件

@@ -1,18 +0,0 @@
1
-/*
2
- * To change this license header, choose License Headers in Project Properties.
3
- * To change this template file, choose Tools | Templates
4
- * and open the template in the editor.
5
- */
6
-package org.openzen.zenscript.codemodel.type;
7
-
8
-import org.openzen.zenscript.codemodel.HighLevelDefinition;
9
-
10
-/**
11
- *
12
- * @author Hoofdgebruiker
13
- */
14
-public class StaticDefinitionTypeID extends DefinitionTypeID {
15
-	public StaticDefinitionTypeID(HighLevelDefinition definition) {
16
-		super(definition);
17
-	}
18
-}

+ 88
- 0
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeParameterCollector.java 查看文件

@@ -0,0 +1,88 @@
1
+/*
2
+ * To change this license header, choose License Headers in Project Properties.
3
+ * To change this template file, choose Tools | Templates
4
+ * and open the template in the editor.
5
+ */
6
+package org.openzen.zenscript.codemodel.type;
7
+
8
+import java.util.Map;
9
+import org.openzen.zenscript.codemodel.FunctionParameter;
10
+import org.openzen.zenscript.codemodel.generic.TypeParameter;
11
+
12
+/**
13
+ *
14
+ * @author Hoofdgebruiker
15
+ */
16
+public class TypeParameterCollector implements ITypeVisitor<Void> {
17
+	private final Map<TypeParameter, ITypeID> map;
18
+	
19
+	public TypeParameterCollector(Map<TypeParameter, ITypeID> map) {
20
+		this.map = map;
21
+	}
22
+
23
+	@Override
24
+	public Void visitBasic(BasicTypeID basic) {
25
+		return null;
26
+	}
27
+
28
+	@Override
29
+	public Void visitArray(ArrayTypeID array) {
30
+		array.elementType.accept(this);
31
+		return null;
32
+	}
33
+
34
+	@Override
35
+	public Void visitAssoc(AssocTypeID assoc) {
36
+		assoc.keyType.accept(this);
37
+		assoc.valueType.accept(this);
38
+		return null;
39
+	}
40
+
41
+	@Override
42
+	public Void visitGenericMap(GenericMapTypeID map) {
43
+		return null;
44
+	}
45
+
46
+	@Override
47
+	public Void visitIterator(IteratorTypeID iterator) {
48
+		for (ITypeID type : iterator.iteratorTypes)
49
+			type.accept(this);
50
+		return null;
51
+	}
52
+
53
+	@Override
54
+	public Void visitFunction(FunctionTypeID function) {
55
+		function.header.returnType.accept(this);
56
+		for (FunctionParameter parameter : function.header.parameters)
57
+			parameter.type.accept(this);
58
+		return null;
59
+	}
60
+
61
+	@Override
62
+	public Void visitDefinition(DefinitionTypeID definition) {
63
+		for (ITypeID argument : definition.typeParameters)
64
+			argument.accept(this);
65
+		if (definition.outer != null)
66
+			visitDefinition(definition.outer);
67
+		return null;
68
+	}
69
+
70
+	@Override
71
+	public Void visitGeneric(GenericTypeID generic) {
72
+		map.put(generic.parameter, generic);
73
+		return null;
74
+	}
75
+
76
+	@Override
77
+	public Void visitRange(RangeTypeID range) {
78
+		range.from.accept(this);
79
+		range.to.accept(this);
80
+		return null;
81
+	}
82
+
83
+	@Override
84
+	public Void visitModified(ModifiedTypeID type) {
85
+		type.baseType.accept(this);
86
+		return null;
87
+	}
88
+}

+ 3
- 3
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/DefinitionMemberGroup.java 查看文件

@@ -281,7 +281,7 @@ public class DefinitionMemberGroup {
281 281
 	
282 282
 	public Expression call(CodePosition position, TypeScope scope, Expression target, CallArguments arguments, boolean allowStaticUsage) {
283 283
 		FunctionalMemberRef method = selectMethod(position, scope, arguments, true, allowStaticUsage);
284
-		FunctionHeader instancedHeader = method.getHeader().fillGenericArguments(scope.getTypeRegistry(), arguments.typeArguments);
284
+		FunctionHeader instancedHeader = method.getHeader().fillGenericArguments(scope.getTypeRegistry(), arguments.typeArguments, scope.getLocalTypeParameters());
285 285
 		for (int i = 0; i < arguments.arguments.length; i++) {
286 286
 			arguments.arguments[i] = arguments.arguments[i].castImplicit(position, scope, instancedHeader.parameters[i].type);
287 287
 		}
@@ -309,13 +309,13 @@ public class DefinitionMemberGroup {
309 309
 			CallArguments arguments,
310 310
 			CompareType compareType) {
311 311
 		FunctionalMemberRef method = selectMethod(position, scope, arguments, true, false);
312
-		FunctionHeader instancedHeader = method.getHeader().fillGenericArguments(scope.getTypeRegistry(), arguments.typeArguments);
312
+		FunctionHeader instancedHeader = method.getHeader().fillGenericArguments(scope.getTypeRegistry(), arguments.typeArguments, scope.getLocalTypeParameters());
313 313
 		return method.callWithComparator(position, compareType, target, instancedHeader, arguments, scope);
314 314
 	}
315 315
 	
316 316
 	public Expression callStatic(CodePosition position, ITypeID target, TypeScope scope, CallArguments arguments) {
317 317
 		FunctionalMemberRef method = selectMethod(position, scope, arguments, false, true);
318
-		FunctionHeader instancedHeader = method.getHeader().fillGenericArguments(scope.getTypeRegistry(), arguments.typeArguments);
318
+		FunctionHeader instancedHeader = method.getHeader().fillGenericArguments(scope.getTypeRegistry(), arguments.typeArguments, scope.getLocalTypeParameters());
319 319
 		return method.callStatic(position, target, instancedHeader, arguments, scope);
320 320
 	}
321 321
 	

+ 47
- 51
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/TypeMemberBuilder.java 查看文件

@@ -83,13 +83,11 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
83 83
 	private final GlobalTypeRegistry registry;
84 84
 	private final TypeMembers members;
85 85
 	private final LocalMemberCache cache;
86
-	private final GenericMapper emptyMapper;
87 86
 	
88 87
 	public TypeMemberBuilder(GlobalTypeRegistry registry, TypeMembers members, LocalMemberCache cache) {
89 88
 		this.registry = registry;
90 89
 		this.members = members;
91 90
 		this.cache = cache;
92
-		emptyMapper = new GenericMapper(registry, Collections.emptyMap());
93 91
 	}
94 92
 	
95 93
 	private void processType(HighLevelDefinition definition, ITypeID type) {
@@ -98,11 +96,12 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
98 96
 				throw new CompileException(expansion.position, CompileExceptionCode.INTERNAL_ERROR, "Missing expansion target");
99 97
 			
100 98
 			Map<TypeParameter, ITypeID> mapping = matchType(type, expansion.target);
99
+			if (mapping == null)
100
+				continue;
101
+			
101 102
 			GenericMapper mapper = new GenericMapper(registry, mapping);
102
-			if (mapping != null) {
103
-				for (IDefinitionMember member : expansion.members)
104
-					member.registerTo(members, TypeMemberPriority.SPECIFIED, mapper);
105
-			}
103
+			for (IDefinitionMember member : expansion.members)
104
+				member.registerTo(members, TypeMemberPriority.SPECIFIED, mapper);
106 105
 		}
107 106
 		
108 107
 		if (members.hasOperator(OperatorType.EQUALS)) {
@@ -117,11 +116,8 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
117 116
 	}
118 117
 	
119 118
 	private Map<TypeParameter, ITypeID> matchType(ITypeID type, ITypeID pattern) {
120
-		if (type == pattern)
121
-			return Collections.emptyMap();
122
-		
123 119
 		Map<TypeParameter, ITypeID> mapping = new HashMap<>();
124
-		if (pattern.inferTypeParameters(cache, type, mapping))
120
+		if (type.inferTypeParameters(cache, pattern, mapping))
125 121
 			return mapping;
126 122
 		
127 123
 		return null;
@@ -212,7 +208,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
212 208
 					definition,
213 209
 					0,
214 210
 					new FunctionHeader(VOID, indexGetParameters),
215
-					ARRAY_CONSTRUCTOR_SIZED).ref(emptyMapper));
211
+					ARRAY_CONSTRUCTOR_SIZED).ref(null));
216 212
 		}
217 213
 
218 214
 		FunctionParameter[] initialValueConstructorParameters = new FunctionParameter[dimension + 1];
@@ -226,7 +222,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
226 222
 				0,
227 223
 				initialValueConstructorHeader,
228 224
 				ARRAY_CONSTRUCTOR_INITIAL_VALUE)
229
-				.registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
225
+				.registerTo(members, TypeMemberPriority.SPECIFIED, null);
230 226
 		
231 227
 		FunctionParameter[] lambdaConstructorParameters = new FunctionParameter[dimension + 1];
232 228
 		for (int i = 0; i < dimension; i++)
@@ -240,7 +236,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
240 236
 				definition,
241 237
 				0,
242 238
 				lambdaConstructorHeader,
243
-				ARRAY_CONSTRUCTOR_LAMBDA).ref(emptyMapper));
239
+				ARRAY_CONSTRUCTOR_LAMBDA).ref(null));
244 240
 		
245 241
 		{
246 242
 			TypeParameter mappedConstructorParameter = new TypeParameter(BUILTIN, "T");
@@ -256,7 +252,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
256 252
 					definition,
257 253
 					Modifiers.PUBLIC,
258 254
 					mappedConstructorFunctionWithoutIndex,
259
-					ARRAY_CONSTRUCTOR_PROJECTED).ref(emptyMapper));
255
+					ARRAY_CONSTRUCTOR_PROJECTED).ref(null));
260 256
 		}
261 257
 		
262 258
 		{
@@ -290,8 +286,8 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
290 286
 
291 287
 		getter(definition, ARRAY_ISEMPTY, "isEmpty", BOOL);
292 288
 		getter(definition, ARRAY_HASHCODE, "objectHashCode", INT);
293
-		new ArrayIteratorKeyValues(array).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
294
-		new ArrayIteratorValues(array).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
289
+		new ArrayIteratorKeyValues(array).registerTo(members, TypeMemberPriority.SPECIFIED, null);
290
+		new ArrayIteratorValues(array).registerTo(members, TypeMemberPriority.SPECIFIED, null);
295 291
 		
296 292
 		equals(definition, ARRAY_EQUALS, array);
297 293
 		notequals(definition, ARRAY_NOTEQUALS, array);
@@ -328,7 +324,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
328 324
 		getter(builtin, BuiltinID.ASSOC_VALUES, "values", cache.getRegistry().getArray(valueType, 1));
329 325
 		getter(builtin, BuiltinID.ASSOC_HASHCODE, "objectHashCode", BasicTypeID.INT);
330 326
 		
331
-		new AssocIterator(assoc).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
327
+		new AssocIterator(assoc).registerTo(members, TypeMemberPriority.SPECIFIED, null);
332 328
 		
333 329
 		equals(builtin, BuiltinID.ASSOC_EQUALS, assoc);
334 330
 		notequals(builtin, BuiltinID.ASSOC_NOTEQUALS, assoc);
@@ -378,7 +374,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
378 374
 	@Override
379 375
 	public Void visitFunction(FunctionTypeID function) {
380 376
 		FunctionDefinition builtin = new FunctionDefinition(BUILTIN, null, "", Modifiers.EXPORT, function.header);
381
-		new CallerMember(BUILTIN, builtin, 0, function.header, FUNCTION_CALL).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
377
+		new CallerMember(BUILTIN, builtin, 0, function.header, FUNCTION_CALL).registerTo(members, TypeMemberPriority.SPECIFIED, null);
382 378
 		
383 379
 		same(builtin, FUNCTION_SAME, function);
384 380
 		notsame(builtin, FUNCTION_NOTSAME, function);
@@ -390,7 +386,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
390 386
 	@Override
391 387
 	public Void visitDefinition(DefinitionTypeID type) {
392 388
 		HighLevelDefinition definition = type.definition;
393
-		GenericMapper mapper = emptyMapper;
389
+		GenericMapper mapper = null;
394 390
 		if (type.hasTypeParameters() || (type.outer != null && type.outer.hasTypeParameters())) {
395 391
 			Map<TypeParameter, ITypeID> mapping = type.getTypeParameterMapping();
396 392
 			mapper = new GenericMapper(registry, mapping);
@@ -435,7 +431,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
435 431
 							definition,
436 432
 							Modifiers.PUBLIC,
437 433
 							new FunctionHeader(VOID, parameters),
438
-							STRUCT_VALUE_CONSTRUCTOR).ref(emptyMapper), TypeMemberPriority.SPECIFIED);
434
+							STRUCT_VALUE_CONSTRUCTOR).ref(null), TypeMemberPriority.SPECIFIED);
439 435
 				}
440 436
 			} else if (definition instanceof EnumDefinition) {
441 437
 				// add default constructor
@@ -444,7 +440,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
444 440
 						definition,
445 441
 						Modifiers.PRIVATE,
446 442
 						new FunctionHeader(VOID),
447
-						ENUM_EMPTY_CONSTRUCTOR).ref(emptyMapper), TypeMemberPriority.SPECIFIED);
443
+						ENUM_EMPTY_CONSTRUCTOR).ref(null), TypeMemberPriority.SPECIFIED);
448 444
 			}
449 445
 		}
450 446
 		
@@ -511,7 +507,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
511 507
 				|| range.from == UINT
512 508
 				|| range.from == LONG
513 509
 				|| range.from == ULONG)) {
514
-			new RangeIterator(range).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
510
+			new RangeIterator(range).registerTo(members, TypeMemberPriority.SPECIFIED, null);
515 511
 		}
516 512
 		
517 513
 		processType(definition, range);
@@ -1120,19 +1116,19 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1120 1116
 		method(builtin, STRING_TO_LOWER_CASE, "toLowerCase", STRING);
1121 1117
 		method(builtin, STRING_TO_UPPER_CASE, "toUpperCase", STRING);
1122 1118
 		
1123
-		new StringCharIterator().registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
1119
+		new StringCharIterator().registerTo(members, TypeMemberPriority.SPECIFIED, null);
1124 1120
 		
1125 1121
 		processType(builtin, STRING);
1126 1122
 	}
1127 1123
 	
1128 1124
 	private void castedTargetCall(OperatorMember member, BuiltinID casterBuiltin) {
1129 1125
 		CasterMemberRef caster = castImplicitRef(member.definition, casterBuiltin, member.header.parameters[0].type);
1130
-		TranslatedOperatorMemberRef method = new TranslatedOperatorMemberRef(member, GenericMapper.EMPTY, call -> member.ref(emptyMapper).call(call.position, caster.cast(call.position, call.target, true), call.arguments, call.scope));
1126
+		TranslatedOperatorMemberRef method = new TranslatedOperatorMemberRef(member, GenericMapper.EMPTY, call -> member.ref(null).call(call.position, caster.cast(call.position, call.target, true), call.arguments, call.scope));
1131 1127
 		members.getOrCreateGroup(member.operator).addMethod(method, TypeMemberPriority.SPECIFIED);
1132 1128
 	}
1133 1129
 	
1134 1130
 	private void register(IDefinitionMember member) {
1135
-		member.registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
1131
+		member.registerTo(members, TypeMemberPriority.SPECIFIED, null);
1136 1132
 	}
1137 1133
 	
1138 1134
 	private void operator(
@@ -1146,7 +1142,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1146 1142
 				Modifiers.PUBLIC,
1147 1143
 				operator,
1148 1144
 				header,
1149
-				builtin).ref(emptyMapper));
1145
+				builtin).ref(null));
1150 1146
 	}
1151 1147
 	
1152 1148
 	private void not(HighLevelDefinition cls, BuiltinID id, ITypeID result) {
@@ -1180,7 +1176,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1180 1176
 	}
1181 1177
 	
1182 1178
 	private void add(HighLevelDefinition definition, BuiltinID id, ITypeID operand, ITypeID result) {
1183
-		addOp(definition, id, operand, result).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
1179
+		addOp(definition, id, operand, result).registerTo(members, TypeMemberPriority.SPECIFIED, null);
1184 1180
 	}
1185 1181
 	
1186 1182
 	private void add(HighLevelDefinition definition, BuiltinID id, ITypeID operand, ITypeID result, BuiltinID caster) {
@@ -1198,7 +1194,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1198 1194
 	}
1199 1195
 	
1200 1196
 	private void sub(HighLevelDefinition cls, BuiltinID id, ITypeID operand, ITypeID result) {
1201
-		subOp(cls, id, operand, result).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
1197
+		subOp(cls, id, operand, result).registerTo(members, TypeMemberPriority.SPECIFIED, null);
1202 1198
 	}
1203 1199
 	
1204 1200
 	private void sub(HighLevelDefinition definition, BuiltinID id, ITypeID operand, ITypeID result, BuiltinID caster) {
@@ -1216,7 +1212,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1216 1212
 	}
1217 1213
 	
1218 1214
 	private void mul(HighLevelDefinition cls, BuiltinID id, ITypeID operand, ITypeID result) {
1219
-		mulOp(cls, id, operand, result).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
1215
+		mulOp(cls, id, operand, result).registerTo(members, TypeMemberPriority.SPECIFIED, null);
1220 1216
 	}
1221 1217
 	
1222 1218
 	private void mul(HighLevelDefinition definition, BuiltinID id, ITypeID operand, ITypeID result, BuiltinID caster) {
@@ -1234,7 +1230,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1234 1230
 	}
1235 1231
 	
1236 1232
 	private void div(HighLevelDefinition cls, BuiltinID id, ITypeID operand, ITypeID result) {
1237
-		divOp(cls, id, operand, result).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
1233
+		divOp(cls, id, operand, result).registerTo(members, TypeMemberPriority.SPECIFIED, null);
1238 1234
 	}
1239 1235
 	
1240 1236
 	private void div(HighLevelDefinition definition, BuiltinID id, ITypeID operand, ITypeID result, BuiltinID caster) {
@@ -1252,7 +1248,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1252 1248
 	}
1253 1249
 	
1254 1250
 	private void mod(HighLevelDefinition cls, BuiltinID id, ITypeID operand, ITypeID result) {
1255
-		modOp(cls, id, operand, result).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
1251
+		modOp(cls, id, operand, result).registerTo(members, TypeMemberPriority.SPECIFIED, null);
1256 1252
 	}
1257 1253
 	
1258 1254
 	private void mod(HighLevelDefinition definition, BuiltinID id, ITypeID operand, ITypeID result, BuiltinID caster) {
@@ -1270,7 +1266,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1270 1266
 	}
1271 1267
 	
1272 1268
 	private void shl(HighLevelDefinition cls, BuiltinID id, ITypeID operand, ITypeID result) {
1273
-		shlOp(cls, id, operand, result).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
1269
+		shlOp(cls, id, operand, result).registerTo(members, TypeMemberPriority.SPECIFIED, null);
1274 1270
 	}
1275 1271
 	
1276 1272
 	private void shl(HighLevelDefinition definition, BuiltinID id, ITypeID operand, ITypeID result, BuiltinID caster) {
@@ -1288,7 +1284,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1288 1284
 	}
1289 1285
 	
1290 1286
 	private void shr(HighLevelDefinition cls, BuiltinID id, ITypeID operand, ITypeID result) {
1291
-		shrOp(cls, id, operand, result).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
1287
+		shrOp(cls, id, operand, result).registerTo(members, TypeMemberPriority.SPECIFIED, null);
1292 1288
 	}
1293 1289
 	
1294 1290
 	private void shr(HighLevelDefinition definition, BuiltinID id, ITypeID operand, ITypeID result, BuiltinID caster) {
@@ -1306,7 +1302,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1306 1302
 	}
1307 1303
 	
1308 1304
 	private void ushr(HighLevelDefinition cls, BuiltinID id, ITypeID operand, ITypeID result) {
1309
-		ushrOp(cls, id, operand, result).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
1305
+		ushrOp(cls, id, operand, result).registerTo(members, TypeMemberPriority.SPECIFIED, null);
1310 1306
 	}
1311 1307
 	
1312 1308
 	private void ushr(HighLevelDefinition definition, BuiltinID id, ITypeID operand, ITypeID result, BuiltinID caster) {
@@ -1324,11 +1320,11 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1324 1320
 	}
1325 1321
 	
1326 1322
 	private void or(HighLevelDefinition cls, BuiltinID id, ITypeID operand, ITypeID result) {
1327
-		orOp(cls, id, operand, result).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
1323
+		orOp(cls, id, operand, result).registerTo(members, TypeMemberPriority.SPECIFIED, null);
1328 1324
 	}
1329 1325
 	
1330 1326
 	private void or(HighLevelDefinition definition, BuiltinID id, ITypeID operand, ITypeID result, BuiltinID caster) {
1331
-		orOp(definition, id, operand, result).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
1327
+		orOp(definition, id, operand, result).registerTo(members, TypeMemberPriority.SPECIFIED, null);
1332 1328
 	}
1333 1329
 	
1334 1330
 	private OperatorMember andOp(HighLevelDefinition cls, BuiltinID id, ITypeID operand, ITypeID result) {
@@ -1342,7 +1338,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1342 1338
 	}
1343 1339
 	
1344 1340
 	private void and(HighLevelDefinition cls, BuiltinID id, ITypeID operand, ITypeID result) {
1345
-		andOp(cls, id, operand, result).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
1341
+		andOp(cls, id, operand, result).registerTo(members, TypeMemberPriority.SPECIFIED, null);
1346 1342
 	}
1347 1343
 	
1348 1344
 	private void and(HighLevelDefinition definition, BuiltinID id, ITypeID operand, ITypeID result, BuiltinID caster) {
@@ -1360,7 +1356,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1360 1356
 	}
1361 1357
 	
1362 1358
 	private void xor(HighLevelDefinition cls, BuiltinID id, ITypeID operand, ITypeID result) {
1363
-		xorOp(cls, id, operand, result).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
1359
+		xorOp(cls, id, operand, result).registerTo(members, TypeMemberPriority.SPECIFIED, null);
1364 1360
 	}
1365 1361
 	
1366 1362
 	private void xor(HighLevelDefinition definition, BuiltinID id, ITypeID operand, ITypeID result, BuiltinID caster) {
@@ -1374,7 +1370,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1374 1370
 				Modifiers.PUBLIC,
1375 1371
 				OperatorType.INDEXGET,
1376 1372
 				new FunctionHeader(result, new FunctionParameter(operand)),
1377
-				id).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
1373
+				id).registerTo(members, TypeMemberPriority.SPECIFIED, null);
1378 1374
 	}
1379 1375
 	
1380 1376
 	private void indexSet(HighLevelDefinition cls, BuiltinID id, ITypeID operand, ITypeID value) {
@@ -1384,7 +1380,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1384 1380
 				Modifiers.PUBLIC,
1385 1381
 				OperatorType.INDEXSET,
1386 1382
 				new FunctionHeader(VOID, operand, value),
1387
-				id).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
1383
+				id).registerTo(members, TypeMemberPriority.SPECIFIED, null);
1388 1384
 	}
1389 1385
 	
1390 1386
 	private OperatorMember compareOp(HighLevelDefinition cls, BuiltinID id, ITypeID operand) {
@@ -1398,7 +1394,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1398 1394
 	}
1399 1395
 	
1400 1396
 	private void compare(HighLevelDefinition cls, BuiltinID id, ITypeID operand) {
1401
-		compareOp(cls, id, operand).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
1397
+		compareOp(cls, id, operand).registerTo(members, TypeMemberPriority.SPECIFIED, null);
1402 1398
 	}
1403 1399
 	
1404 1400
 	private void compare(HighLevelDefinition definition, BuiltinID id, ITypeID operand, BuiltinID caster) {
@@ -1412,7 +1408,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1412 1408
 				Modifiers.PUBLIC,
1413 1409
 				name,
1414 1410
 				type,
1415
-				id).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
1411
+				id).registerTo(members, TypeMemberPriority.SPECIFIED, null);
1416 1412
 	}
1417 1413
 	
1418 1414
 	private void constant(HighLevelDefinition cls, BuiltinID id, String name, Expression value) {
@@ -1424,7 +1420,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1424 1420
 				value.type,
1425 1421
 				id);
1426 1422
 		result.value = value;
1427
-		result.registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
1423
+		result.registerTo(members, TypeMemberPriority.SPECIFIED, null);
1428 1424
 	}
1429 1425
 	
1430 1426
 	private void constructor(
@@ -1436,7 +1432,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1436 1432
 				definition,
1437 1433
 				Modifiers.PUBLIC,
1438 1434
 				header,
1439
-				id).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
1435
+				id).registerTo(members, TypeMemberPriority.SPECIFIED, null);
1440 1436
 	}
1441 1437
 	
1442 1438
 	private void constructor(
@@ -1448,7 +1444,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1448 1444
 				definition,
1449 1445
 				Modifiers.PUBLIC,
1450 1446
 				new FunctionHeader(VOID, arguments),
1451
-				id).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
1447
+				id).registerTo(members, TypeMemberPriority.SPECIFIED, null);
1452 1448
 	}
1453 1449
 	
1454 1450
 	private void method(
@@ -1501,7 +1497,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1501 1497
 				cls,
1502 1498
 				Modifiers.PUBLIC,
1503 1499
 				result,
1504
-				id).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
1500
+				id).registerTo(members, TypeMemberPriority.SPECIFIED, null);
1505 1501
 	}
1506 1502
 	
1507 1503
 	private void castImplicit(HighLevelDefinition cls, BuiltinID id, ITypeID result) {
@@ -1510,7 +1506,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1510 1506
 				cls,
1511 1507
 				Modifiers.PUBLIC | Modifiers.IMPLICIT,
1512 1508
 				result,
1513
-				id).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
1509
+				id).registerTo(members, TypeMemberPriority.SPECIFIED, null);
1514 1510
 	}
1515 1511
 	
1516 1512
 	private CasterMemberRef castImplicitRef(HighLevelDefinition definition, BuiltinID id, ITypeID result) {
@@ -1529,7 +1525,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1529 1525
 				Modifiers.PUBLIC,
1530 1526
 				OperatorType.EQUALS,
1531 1527
 				new FunctionHeader(BOOL, new FunctionParameter(type)),
1532
-				id).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
1528
+				id).registerTo(members, TypeMemberPriority.SPECIFIED, null);
1533 1529
 	}
1534 1530
 	
1535 1531
 	private void same(HighLevelDefinition cls, BuiltinID id, ITypeID type) {
@@ -1539,7 +1535,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1539 1535
 				Modifiers.PUBLIC,
1540 1536
 				OperatorType.SAME,
1541 1537
 				new FunctionHeader(BOOL, new FunctionParameter(type)),
1542
-				id).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
1538
+				id).registerTo(members, TypeMemberPriority.SPECIFIED, null);
1543 1539
 	}
1544 1540
 	
1545 1541
 	private void notequals(HighLevelDefinition cls, BuiltinID id, ITypeID type) {
@@ -1549,7 +1545,7 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1549 1545
 				Modifiers.PUBLIC,
1550 1546
 				OperatorType.NOTEQUALS,
1551 1547
 				new FunctionHeader(BOOL, new FunctionParameter(type)),
1552
-				id).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
1548
+				id).registerTo(members, TypeMemberPriority.SPECIFIED, null);
1553 1549
 	}
1554 1550
 	
1555 1551
 	private void notsame(HighLevelDefinition cls, BuiltinID id, ITypeID type) {
@@ -1559,6 +1555,6 @@ public class TypeMemberBuilder implements ITypeVisitor<Void> {
1559 1555
 				Modifiers.PUBLIC,
1560 1556
 				OperatorType.NOTSAME,
1561 1557
 				new FunctionHeader(BOOL, new FunctionParameter(type)),
1562
-				id).registerTo(members, TypeMemberPriority.SPECIFIED, emptyMapper);
1558
+				id).registerTo(members, TypeMemberPriority.SPECIFIED, null);
1563 1559
 	}
1564 1560
 }

+ 6
- 0
CompilerShared/src/main/java/org/openzen/zenscript/compiler/CompileScope.java 查看文件

@@ -9,6 +9,7 @@ import java.util.HashMap;
9 9
 import java.util.List;
10 10
 import java.util.Map;
11 11
 import org.openzen.zencode.shared.CodePosition;
12
+import org.openzen.zenscript.codemodel.GenericMapper;
12 13
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
13 14
 import org.openzen.zenscript.codemodel.definition.ExpansionDefinition;
14 15
 import org.openzen.zenscript.codemodel.scope.TypeScope;
@@ -73,4 +74,9 @@ public class CompileScope implements TypeScope {
73 74
 	public TypeMemberPreparer getPreparer() {
74 75
 		return member -> {};
75 76
 	}
77
+
78
+	@Override
79
+	public GenericMapper getLocalTypeParameters() {
80
+		return GenericMapper.EMPTY;
81
+	}
76 82
 }

+ 1
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedNewExpression.java 查看文件

@@ -61,6 +61,6 @@ public class ParsedNewExpression extends ParsedExpression{
61 61
 				type,
62 62
 				member,
63 63
 				compiledArguments,
64
-				member.getHeader().fillGenericArguments(scope.getTypeRegistry(), compiledArguments.typeArguments));
64
+				member.getHeader().fillGenericArguments(scope.getTypeRegistry(), compiledArguments.typeArguments, scope.getLocalTypeParameters()));
65 65
 	}
66 66
 }

+ 6
- 0
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedCatchClause.java 查看文件

@@ -10,6 +10,7 @@ import java.util.function.Function;
10 10
 import org.openzen.zencode.shared.CodePosition;
11 11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12 12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
+import org.openzen.zenscript.codemodel.GenericMapper;
13 14
 import org.openzen.zenscript.codemodel.expression.Expression;
14 15
 import org.openzen.zenscript.codemodel.expression.GetLocalVariableExpression;
15 16
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
@@ -107,5 +108,10 @@ public class ParsedCatchClause {
107 108
 		public TypeMemberPreparer getPreparer() {
108 109
 			return outer.getPreparer();
109 110
 		}
111
+
112
+		@Override
113
+		public GenericMapper getLocalTypeParameters() {
114
+			return outer.getLocalTypeParameters();
115
+		}
110 116
 	}
111 117
 }

+ 6
- 0
Parser/src/main/java/org/openzen/zenscript/parser/statements/ParsedStatementSwitch.java 查看文件

@@ -10,6 +10,7 @@ import java.util.function.Function;
10 10
 import org.openzen.zencode.shared.CodePosition;
11 11
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
12 12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
+import org.openzen.zenscript.codemodel.GenericMapper;
13 14
 import org.openzen.zenscript.codemodel.WhitespaceInfo;
14 15
 import org.openzen.zenscript.codemodel.expression.Expression;
15 16
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
@@ -117,5 +118,10 @@ public class ParsedStatementSwitch extends ParsedStatement {
117 118
 		public TypeMemberPreparer getPreparer() {
118 119
 			return outer.getPreparer();
119 120
 		}
121
+
122
+		@Override
123
+		public GenericMapper getLocalTypeParameters() {
124
+			return outer.getLocalTypeParameters();
125
+		}
120 126
 	}
121 127
 }

+ 6
- 0
Validator/src/main/java/org/openzen/zenscript/validator/visitors/DefinitionValidator.java 查看文件

@@ -10,6 +10,7 @@ import java.util.List;
10 10
 import java.util.Map;
11 11
 import org.openzen.zencode.shared.CodePosition;
12 12
 import org.openzen.zenscript.codemodel.FunctionHeader;
13
+import org.openzen.zenscript.codemodel.GenericMapper;
13 14
 import org.openzen.zenscript.codemodel.HighLevelDefinition;
14 15
 import static org.openzen.zenscript.codemodel.Modifiers.*;
15 16
 import org.openzen.zenscript.codemodel.annotations.AnnotationDefinition;
@@ -232,6 +233,11 @@ public class DefinitionValidator implements DefinitionVisitor<Void> {
232 233
 		public TypeMemberPreparer getPreparer() {
233 234
 			return member -> {};
234 235
 		}
236
+
237
+		@Override
238
+		public GenericMapper getLocalTypeParameters() {
239
+			throw new UnsupportedOperationException();
240
+		}
235 241
 	}
236 242
 	
237 243
 	private class FunctionStatementScope implements StatementScope {

Loading…
取消
儲存