Skip to content

Commit 032f53e

Browse files
committed
Improved naming + fix wildcard casting test
1 parent 43c21b0 commit 032f53e

File tree

8 files changed

+20
-15
lines changed

8 files changed

+20
-15
lines changed

CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/DefinitionTypeID.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,23 +118,23 @@ public Optional<Expression> castImplicitFrom(CodePosition position, Expression v
118118
}
119119

120120
@Override
121-
public boolean isEquivalentTo(TypeID other, List<ExpansionSymbol> expansions) {
122-
if (other instanceof DefinitionTypeID) {
123-
DefinitionTypeID otherType = (DefinitionTypeID) other;
121+
public boolean canCastToBecauseOfWildcardGenerics(TypeID to, List<ExpansionSymbol> expansions) {
122+
if (to instanceof DefinitionTypeID) {
123+
DefinitionTypeID otherType = (DefinitionTypeID) to;
124124
if (definition.equals(otherType.definition)) {
125125
if (typeArguments.length != otherType.typeArguments.length)
126-
throw new IllegalArgumentException("Type arguments do not match: " + this + " -> " + other);
126+
throw new IllegalArgumentException("Type arguments do not match: " + this + " -> " + to);
127127

128128
for (int i = 0; i < typeArguments.length; i++) {
129129
if (!otherType.typeArguments[i].canCastGenericFrom(typeArguments[i], expansions))
130-
return TypeID.super.isEquivalentTo(other, expansions);
130+
return TypeID.super.canCastToBecauseOfWildcardGenerics(to, expansions);
131131
}
132132

133133
return true;
134134
}
135135
}
136136

137-
return TypeID.super.isEquivalentTo(other, expansions);
137+
return TypeID.super.canCastToBecauseOfWildcardGenerics(to, expansions);
138138
}
139139

140140
@Override

CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/TypeID.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,12 @@ default boolean extendsOrImplements(TypeID type, List<ExpansionSymbol> expansion
155155
/**
156156
* Similar to equals, but takes into account wildcard generics.
157157
*
158-
* @param type
158+
* @param to
159159
* @param expansions
160160
* @return
161161
*/
162-
default boolean isEquivalentTo(TypeID type, List<ExpansionSymbol> expansions) {
163-
return this.equals(type);
162+
default boolean canCastToBecauseOfWildcardGenerics(TypeID to, List<ExpansionSymbol> expansions) {
163+
return this.equals(to);
164164
}
165165

166166
/**

CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/MemberSet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public List<MethodSymbol> getInterfaceMethodsToImplement() {
132132

133133
@Override
134134
public boolean extendsOrImplements(TypeID type, List<ExpansionSymbol> expansions) {
135-
return this.type.isEquivalentTo(type, expansions);
135+
return this.type.canCastToBecauseOfWildcardGenerics(type, expansions);
136136
}
137137

138138
@Override

CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/member/OptionalResolvedType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,6 @@ public List<MethodSymbol> getInterfaceMethodsToImplement() {
155155

156156
@Override
157157
public boolean extendsOrImplements(TypeID type, List<ExpansionSymbol> expansions) {
158-
return this.type.isEquivalentTo(type, expansions);
158+
return this.type.canCastToBecauseOfWildcardGenerics(type, expansions);
159159
}
160160
}

JavaIntegration/src/main/java/org/openzen/zencode/java/module/JavaNativeTypeMembers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public List<MethodSymbol> getInterfaceMethodsToImplement() {
114114

115115
@Override
116116
public boolean extendsOrImplements(TypeID type, List<ExpansionSymbol> expansions) {
117-
return this.type.isEquivalentTo(type, expansions);
117+
return this.type.canCastToBecauseOfWildcardGenerics(type, expansions);
118118
}
119119

120120
@Override

Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionVariable.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ public Expression eval() {
125125

126126
@Override
127127
public CastedExpression cast(CastedEval cast) {
128-
TypeID type = cast.type.simplified();
129128
return resolved.cast(cast);
130129
}
131130

ScriptingExample/src/test/java/org/openzen/zenscript/scriptingexample/tests/actual_test/generics/WildcardCastingTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ void testPrinter() {
1313
//TODO Should this work? We couldn't decide
1414
ScriptBuilder.create()
1515
.add("import test_module.Generator;")
16+
.add("import test_module.Singleton;")
1617
.add("var generator = new Generator();")
1718
.add("var stuff = generator.generate();")
18-
.add("generator.print<string>(stuff);")
19+
.add("var morestuff = stuff as Singleton<string>;")
20+
.add("generator.print<string>(morestuff);")
1921
.execute(this);
2022
}
2123

@@ -50,5 +52,10 @@ public static class Singleton<T> {
5052
public Singleton(T value) {
5153
this.value = value;
5254
}
55+
56+
/*@ZenCodeType.Caster(implicit = true)
57+
public <U> Singleton<U> cast(Class<U> clazz) {
58+
return new Singleton<>(clazz.cast(value));
59+
}*/
5360
}
5461
}

Shared/src/main/java/org/openzen/zencode/shared/SourceFile.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import java.io.IOException;
44
import java.io.Reader;
5-
import java.nio.file.Path;
65
import java.nio.file.Paths;
76
import java.util.ArrayList;
87
import java.util.List;

0 commit comments

Comments
 (0)