Procházet zdrojové kódy

Merge remote-tracking branch 'Stan/development' into development

kindlich před 6 roky
rodič
revize
40ba457de7
No known key found for this signature in database

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GlobalTypeRegistry.java Zobrazit soubor

@@ -125,7 +125,7 @@ public class GlobalTypeRegistry {
125 125
 		}
126 126
 	}
127 127
 	
128
-	private OptionalTypeID getOptional(ITypeID original) {
128
+	public OptionalTypeID getOptional(ITypeID original) {
129 129
 		if (optionalTypes.containsKey(original)) {
130 130
 			return optionalTypes.get(original);
131 131
 		} else {

+ 9
- 1
Parser/src/main/java/org/openzen/zenscript/parser/expression/ParsedExpressionCoalesce.java Zobrazit soubor

@@ -9,6 +9,8 @@ import org.openzen.zenscript.codemodel.expression.CoalesceExpression;
9 9
 import org.openzen.zenscript.codemodel.expression.Expression;
10 10
 import org.openzen.zenscript.codemodel.partial.IPartialExpression;
11 11
 import org.openzen.zenscript.codemodel.type.ITypeID;
12
+import org.openzen.zenscript.codemodel.type.OptionalTypeID;
13
+import org.openzen.zenscript.codemodel.type.member.TypeMembers;
12 14
 import org.openzen.zenscript.linker.ExpressionScope;
13 15
 import org.openzen.zenscript.shared.CodePosition;
14 16
 import org.openzen.zenscript.shared.CompileException;
@@ -37,7 +39,13 @@ public class ParsedExpressionCoalesce extends ParsedExpression {
37 39
 			throw new CompileException(position, CompileExceptionCode.COALESCE_TARGET_NOT_OPTIONAL, "Type of the first expression is not optional");
38 40
 		
39 41
 		ITypeID resultType = cLeftType.getOptionalBase();
40
-		Expression cRight = right.compile(scope.withHint(resultType)).eval().castImplicit(position, scope, resultType);
42
+		Expression cRight = right.compile(scope.withHint(resultType)).eval();
43
+		
44
+		TypeMembers resultTypeMembers = scope.getTypeMembers(resultType);
45
+		resultType = resultTypeMembers.union(cRight.type);
46
+		cLeft = cLeft.castImplicit(position, scope, resultType.isOptional() ? resultType : scope.getTypeRegistry().getOptional(resultType));
47
+		cRight = cRight.castImplicit(position, scope, resultType);
48
+		
41 49
 		return new CoalesceExpression(position, cLeft, cRight);
42 50
 	}
43 51
 

Loading…
Zrušit
Uložit