Просмотр исходного кода

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

kindlich 6 лет назад
Родитель
Сommit
40ba457de7
Не найден GPG ключ соответствующий данной подписи

+ 1
- 1
CodeModel/src/main/java/org/openzen/zenscript/codemodel/type/GlobalTypeRegistry.java Просмотреть файл

@@ -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 Просмотреть файл

@@ -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
 

Загрузка…
Отмена
Сохранить