diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/declarationCheckers.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/declarationCheckers.kt index e94ae2f8303..2aed16152c8 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/declarationCheckers.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/declarationCheckers.kt @@ -233,7 +233,7 @@ class ReifiedTypeParameterAnnotationChecker : SimpleDeclarationChecker { diagnosticHolder: DiagnosticSink, bindingContext: BindingContext ) { - if (descriptor is CallableDescriptor && !InlineUtil.isInline(descriptor)) { + if (descriptor is CallableDescriptor && !InlineUtil.isInlineFunctionOrProperty(descriptor)) { checkTypeParameterDescriptorsAreNotReified(descriptor.typeParameters, diagnosticHolder) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/inline/InlineUtil.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/inline/InlineUtil.java index cf5dcd4f9bf..10aed6dd47e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/inline/InlineUtil.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/inline/InlineUtil.java @@ -39,10 +39,28 @@ public class InlineUtil { FunctionTypesKt.isFunctionType(valueParameterOrReceiver.getOriginal().getType()); } + public static boolean isInlineFunctionOrProperty(@Nullable DeclarationDescriptor descriptor) { + return isInline(descriptor) || isInlineProperty(descriptor); + } + public static boolean isInline(@Nullable DeclarationDescriptor descriptor) { return descriptor instanceof FunctionDescriptor && getInlineStrategy((FunctionDescriptor) descriptor).isInline(); } + public static boolean isInlineProperty(@Nullable DeclarationDescriptor descriptor) { + if (!(descriptor instanceof PropertyDescriptor)) return false; + + PropertyGetterDescriptor getter = ((PropertyDescriptor) descriptor).getGetter(); + if (getter == null || !getter.isInline()) return false; + + if (((PropertyDescriptor) descriptor).isVar()) { + PropertySetterDescriptor setter = ((PropertyDescriptor) descriptor).getSetter(); + return setter != null && setter.isInline(); + } + + return true; + } + public static boolean isInlineOrContainingInline(@Nullable DeclarationDescriptor descriptor) { if (isInline(descriptor)) return true; if (descriptor == null) return false; diff --git a/compiler/testData/codegen/boxInline/property/reifiedVal.kt b/compiler/testData/codegen/boxInline/property/reifiedVal.kt new file mode 100644 index 00000000000..42a045ec916 --- /dev/null +++ b/compiler/testData/codegen/boxInline/property/reifiedVal.kt @@ -0,0 +1,15 @@ +// WITH_RUNTIME +// FILE: 1.kt +package test + +inline val T.value: String + get() = T::class.java.name + +// FILE: 2.kt +import test.* + +class OK + +fun box(): String { + return OK().value +} \ No newline at end of file diff --git a/compiler/testData/codegen/boxInline/property/reifiedVar.kt b/compiler/testData/codegen/boxInline/property/reifiedVar.kt new file mode 100644 index 00000000000..ca7b8731d0e --- /dev/null +++ b/compiler/testData/codegen/boxInline/property/reifiedVar.kt @@ -0,0 +1,25 @@ +// WITH_RUNTIME +// FILE: 1.kt +package test + +var bvalue: String = "" + +inline var T.value: String + get() = T::class.java.name + bvalue + set(p: String) { + bvalue = p + } + +// FILE: 2.kt +import test.* + +class O + +fun box(): String { + val o = O() + val value1 = o.value + if (value1 != "O") return "fail 1: $value1" + + o.value = "K" + return o.value +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java index 9a982eb3b3b..b5f8ce02f5f 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxInlineCodegenTestGenerated.java @@ -1522,6 +1522,18 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/property"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("reifiedVal.kt") + public void testReifiedVal() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/property/reifiedVal.kt"); + doTest(fileName); + } + + @TestMetadata("reifiedVar.kt") + public void testReifiedVar() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/property/reifiedVar.kt"); + doTest(fileName); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/property/simple.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java index ca0f47d7a67..62b573df4d0 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/CompileKotlinAgainstInlineKotlinTestGenerated.java @@ -1522,6 +1522,18 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/boxInline/property"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("reifiedVal.kt") + public void testReifiedVal() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/property/reifiedVal.kt"); + doTest(fileName); + } + + @TestMetadata("reifiedVar.kt") + public void testReifiedVar() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/property/reifiedVar.kt"); + doTest(fileName); + } + @TestMetadata("simple.kt") public void testSimple() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxInline/property/simple.kt");