Function literal is now expression and function simultaneously for purposes of annotation target checking
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
@Target(AnnotationTarget.FUNCTION)
|
||||
annotation class FunAnn
|
||||
|
||||
fun bar(arg: () -> Int) = arg()
|
||||
|
||||
@FunAnn fun gav() = 13
|
||||
|
||||
fun foo(arg: Int) {
|
||||
// Literal is annotatable
|
||||
bar @FunAnn { arg }
|
||||
// Function expression too
|
||||
val f = @FunAnn fun(): Int { return 42 }
|
||||
// But here, f and gav should be annotated instead
|
||||
bar(<!WRONG_ANNOTATION_TARGET!>@FunAnn<!> f)
|
||||
bar(<!WRONG_ANNOTATION_TARGET!>@FunAnn<!> ::gav)
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package
|
||||
|
||||
public fun bar(/*0*/ arg: () -> kotlin.Int): kotlin.Int
|
||||
public fun foo(/*0*/ arg: kotlin.Int): kotlin.Unit
|
||||
@FunAnn() public fun gav(): kotlin.Int
|
||||
|
||||
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.FUNCTION}) @kotlin.annotation.annotation() public final class FunAnn : kotlin.Annotation {
|
||||
public constructor FunAnn()
|
||||
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
|
||||
}
|
||||
@@ -7,5 +7,5 @@ fun transform(i: Int, tr: (Int) -> Int): Int = <!WRONG_ANNOTATION_TARGET!>@base<
|
||||
@base <!WRONG_ANNOTATION_TARGET!>@special<!> fun foo(i: Int): Int {
|
||||
val j = <!WRONG_ANNOTATION_TARGET!>@base<!> @special i + 1
|
||||
if (j == 1) return foo(@special <!WRONG_ANNOTATION_TARGET!>@base<!> 42)
|
||||
return transform(@special j, <!WRONG_ANNOTATION_TARGET!>@base<!> @special { @special it * 2 })
|
||||
return transform(@special j, @base @special { @special it * 2 })
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user