JVM: do not lose default parameter values during enhancement
The change in signatureEnhancement.kt in 432f581cb2 was incorrect. Contrary to its name, the removed method `hasDefaultValueInAnnotation` checked not only if the enhancement annotation has default value (which is what the removed feature was about), but also if the parameter itself declares default value. This was mistakenly substituted by just `false` on line 234. The correct change is to use the `declaresDefaultValue` flag of the original parameter. It's kind of weird though that in case there's a nullability annotation on the whole package (like in KT-48316) type enhancement is being done on everything, including annotation constructors, whose parameter types can't have any enhancement information. Maybe this should be improved independently. #KT-48316 Fixed
This commit is contained in:
+6
@@ -92,6 +92,12 @@ public class FirOldFrontendForeignAnnotationsCompiledJavaTestGenerated extends A
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt47920.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt48316_multiModuleAnnotationDefault.kt")
|
||||
public void testKt48316_multiModuleAnnotationDefault() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt48316_multiModuleAnnotationDefault.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lombokSimple.kt")
|
||||
public void testLombokSimple() throws Exception {
|
||||
|
||||
+6
@@ -92,6 +92,12 @@ public class FirOldFrontendForeignAnnotationsCompiledJavaWithPsiClassReadingTest
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt47920.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt48316_multiModuleAnnotationDefault.kt")
|
||||
public void testKt48316_multiModuleAnnotationDefault() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt48316_multiModuleAnnotationDefault.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lombokSimple.kt")
|
||||
public void testLombokSimple() throws Exception {
|
||||
|
||||
+6
@@ -92,6 +92,12 @@ public class FirOldFrontendForeignAnnotationsSourceJavaTestGenerated extends Abs
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt47920.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt48316_multiModuleAnnotationDefault.kt")
|
||||
public void testKt48316_multiModuleAnnotationDefault() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt48316_multiModuleAnnotationDefault.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lombokSimple.kt")
|
||||
public void testLombokSimple() throws Exception {
|
||||
|
||||
Vendored
+34
@@ -0,0 +1,34 @@
|
||||
// FIR_IDENTICAL
|
||||
// FILE: lib/NonNullApi.java
|
||||
|
||||
package lib;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.meta.TypeQualifierDefault;
|
||||
|
||||
@Target(ElementType.PACKAGE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Nonnull
|
||||
@TypeQualifierDefault({ElementType.METHOD, ElementType.PARAMETER})
|
||||
public @interface NonNullApi {}
|
||||
|
||||
// FILE: lib/package-info.java
|
||||
|
||||
@NonNullApi
|
||||
package lib;
|
||||
|
||||
// FILE: lib/A.java
|
||||
|
||||
package lib;
|
||||
|
||||
public @interface A {
|
||||
Class value() default String.class;
|
||||
}
|
||||
|
||||
// FILE: test.kt
|
||||
|
||||
import lib.A
|
||||
|
||||
@A
|
||||
fun test() {}
|
||||
compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt48316_multiModuleAnnotationDefault.txt
Vendored
+21
@@ -0,0 +1,21 @@
|
||||
package
|
||||
|
||||
@lib.A public fun test(): kotlin.Unit
|
||||
|
||||
package lib {
|
||||
|
||||
public final annotation class A : kotlin.Annotation {
|
||||
public constructor A(/*0*/ value: kotlin.reflect.KClass<(raw) kotlin.Any> = ...)
|
||||
public final val value: kotlin.reflect.KClass<(raw) kotlin.Any>
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
@kotlin.annotation.Target(allowedTargets = {}) @kotlin.annotation.Retention(value = AnnotationRetention.RUNTIME) @javax.annotation.Nonnull @javax.annotation.meta.TypeQualifierDefault(value = {ElementType.METHOD, ElementType.PARAMETER}) public final annotation class NonNullApi : kotlin.Annotation {
|
||||
public constructor NonNullApi()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
}
|
||||
+6
@@ -92,6 +92,12 @@ public class ForeignAnnotationsCompiledJavaTestGenerated extends AbstractForeign
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt47920.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt48316_multiModuleAnnotationDefault.kt")
|
||||
public void testKt48316_multiModuleAnnotationDefault() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt48316_multiModuleAnnotationDefault.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lombokSimple.kt")
|
||||
public void testLombokSimple() throws Exception {
|
||||
|
||||
+6
@@ -92,6 +92,12 @@ public class ForeignAnnotationsCompiledJavaWithPsiClassReadingTestGenerated exte
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt47920.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt48316_multiModuleAnnotationDefault.kt")
|
||||
public void testKt48316_multiModuleAnnotationDefault() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt48316_multiModuleAnnotationDefault.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lombokSimple.kt")
|
||||
public void testLombokSimple() throws Exception {
|
||||
|
||||
+6
@@ -92,6 +92,12 @@ public class ForeignAnnotationsSourceJavaTestGenerated extends AbstractForeignAn
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt47920.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("kt48316_multiModuleAnnotationDefault.kt")
|
||||
public void testKt48316_multiModuleAnnotationDefault() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/foreignAnnotationsTests/tests/kt48316_multiModuleAnnotationDefault.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("lombokSimple.kt")
|
||||
public void testLombokSimple() throws Exception {
|
||||
|
||||
+12
-3
@@ -21,7 +21,10 @@ import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotated
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.load.java.*
|
||||
import org.jetbrains.kotlin.load.java.AnnotationQualifierApplicabilityType
|
||||
import org.jetbrains.kotlin.load.java.AnnotationTypeQualifierResolver
|
||||
import org.jetbrains.kotlin.load.java.DeprecationCausedByFunctionNInfo
|
||||
import org.jetbrains.kotlin.load.java.JavaTypeQualifiersByElementType
|
||||
import org.jetbrains.kotlin.load.java.descriptors.*
|
||||
import org.jetbrains.kotlin.load.java.lazy.LazyJavaResolverContext
|
||||
import org.jetbrains.kotlin.load.java.lazy.copyWithNewDefaultTypeQualifiers
|
||||
@@ -36,8 +39,11 @@ import org.jetbrains.kotlin.name.FqNameUnsafe
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DEPRECATED_FUNCTION_KEY
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameOrNull
|
||||
import org.jetbrains.kotlin.types.*
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.RawType
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext
|
||||
import org.jetbrains.kotlin.types.getEnhancement
|
||||
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
||||
import org.jetbrains.kotlin.types.model.TypeParameterMarker
|
||||
import org.jetbrains.kotlin.types.model.TypeSystemInferenceExtensionContext
|
||||
@@ -135,7 +141,10 @@ class SignatureEnhancement(private val typeEnhancement: JavaTypeEnhancement) {
|
||||
return this.enhance(
|
||||
receiverTypeEnhancement ?: extensionReceiverParameter?.type,
|
||||
valueParameterEnhancements.mapIndexed { index, enhanced ->
|
||||
ValueParameterData(enhanced ?: valueParameters[index].type, false)
|
||||
ValueParameterData(
|
||||
enhanced ?: valueParameters[index].type,
|
||||
annotationOwnerForMember.valueParameters[index].declaresDefaultValue()
|
||||
)
|
||||
},
|
||||
returnTypeEnhancement ?: returnType!!,
|
||||
additionalUserData
|
||||
|
||||
Reference in New Issue
Block a user