Generate as check for inline classes using wrapper

Should be improved when inline class is based on non-null reference
This commit is contained in:
Mikhail Zarechenskiy
2018-02-12 05:07:59 +03:00
parent a88dbefcd9
commit 6687751cf5
8 changed files with 75 additions and 9 deletions
@@ -4322,29 +4322,29 @@ The "returned" value of try expression with no finally is either the last expres
KtExpression left = expression.getLeft();
IElementType opToken = expression.getOperationReference().getReferencedNameElementType();
KotlinType rightType = bindingContext.get(TYPE, expression.getRight());
assert rightType != null;
KotlinType rightKotlinType = bindingContext.get(TYPE, expression.getRight());
assert rightKotlinType != null;
StackValue value = genQualified(receiver, left);
return StackValue.operation(boxType(asmType(rightType)), v -> {
value.put(boxType(value.type), null, v);
Type boxedRightType = boxType(typeMapper.mapTypeAsDeclaration(rightKotlinType));
return StackValue.operation(boxedRightType, rightKotlinType, v -> {
value.put(boxType(value.type), value.kotlinType, v);
if (value.type == Type.VOID_TYPE) {
StackValue.putUnitInstance(v);
}
boolean safeAs = opToken == KtTokens.AS_SAFE;
Type type = boxType(asmType(rightType));
if (TypeUtils.isReifiedTypeParameter(rightType)) {
putReifiedOperationMarkerIfTypeIsReifiedParameter(rightType,
if (TypeUtils.isReifiedTypeParameter(rightKotlinType)) {
putReifiedOperationMarkerIfTypeIsReifiedParameter(rightKotlinType,
safeAs ? ReifiedTypeInliner.OperationKind.SAFE_AS
: ReifiedTypeInliner.OperationKind.AS);
v.checkcast(type);
v.checkcast(boxedRightType);
return Unit.INSTANCE;
}
CodegenUtilKt.generateAsCast(v, rightType, type, safeAs);
CodegenUtilKt.generateAsCast(v, rightKotlinType, boxedRightType, safeAs);
return Unit.INSTANCE;
});