Fix KotlinType of constructor call for inline classes

This commit is contained in:
Mikhail Zarechenskiy
2018-02-19 20:31:35 +03:00
parent 530dd01ca6
commit 413e2d7fa1
4 changed files with 59 additions and 13 deletions
@@ -2107,19 +2107,7 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
if (descriptor instanceof ConstructorDescriptor) {
if (InlineClassesUtilsKt.isInlineClass(descriptor.getContainingDeclaration())) {
KtValueArgument valueArgument = CollectionsKt.firstOrNull(expression.getValueArguments());
if (valueArgument == null) return null;
SimpleType inlineClassType = ((ClassDescriptor) descriptor.getContainingDeclaration()).getDefaultType();
Type underlyingType = typeMapper.mapType(inlineClassType);
KotlinType underlyingKotlinType = InlineClassesUtilsKt.unsubstitutedUnderlyingType(inlineClassType);
StackValue argumentValue = gen(valueArgument.getArgumentExpression());
return StackValue.coercionValueForArgumentOfInlineClassConstructor(
argumentValue, underlyingType, inlineClassType, underlyingKotlinType
);
return generateInlineClassConstructorCall(expression);
}
return generateNewCall(expression, resolvedCall);
@@ -2134,6 +2122,24 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
return invokeFunction(resolvedCall, receiver);
}
private StackValue generateInlineClassConstructorCall(@NotNull KtCallExpression expression) {
KtValueArgument valueArgument = CollectionsKt.singleOrNull(expression.getValueArguments());
assert valueArgument != null : "Inline class constructor call should have single argument";
KotlinType inlineClassType = kotlinType(expression);
assert inlineClassType != null && InlineClassesUtilsKt.isInlineClassType(inlineClassType) :
"Constructor call expression of inline class should have inline class type, but have: " + inlineClassType;
Type underlyingType = typeMapper.mapType(inlineClassType);
KotlinType underlyingKotlinType = InlineClassesUtilsKt.unsubstitutedUnderlyingType(inlineClassType);
StackValue argumentValue = gen(valueArgument.getArgumentExpression());
return StackValue.coercionValueForArgumentOfInlineClassConstructor(
argumentValue, underlyingType, inlineClassType, underlyingKotlinType
);
}
@Override
public StackValue visitCollectionLiteralExpression(
@NotNull KtCollectionLiteralExpression expression, StackValue data