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