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:
Alexander Udalov
2021-09-06 22:59:35 +02:00
parent e28d4a1877
commit 7e43000d9b
9 changed files with 103 additions and 3 deletions
@@ -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() {}