Files
kotlin-fork/compiler/testData/codegen/box/annotations/singleAssignmentToVarargInAnnotation.kt
T
Tianyu Geng e95de0a778 FIR checker: report type mismatch for named vararg arguement
ProhibitAssigningSingleElementsToVarargsInNamedForm is enabled from 1.3
so there is no need to make FIR accepting single element passed through
named arguments.

In addition, we may want to report only
ASSIGNING_SINGLE_ELEMENT_TO_VARARG_IN_NAMED_FORM_FUNCTION and not arg
type mismatch. But FE1.0 is reporting both so I am following it. If we
want to remove the redundant report, we will probably want to remove
FirNamedVarargChecker and report during resolution as a cone diagnostic.
2021-09-15 12:11:36 +03:00

29 lines
646 B
Kotlin
Vendored

// IGNORE_BACKEND_FIR: JVM_IR
// !LANGUAGE: -ProhibitAssigningSingleElementsToVarargsInNamedForm
// TARGET_BACKEND: JVM
// WITH_RUNTIME
annotation class Ann(vararg val p: Int)
@Ann(p = 1) class MyClass
fun box(): String {
test(MyClass::class.java, "1")
return "OK"
}
fun test(klass: Class<*>, expected: String) {
val ann = klass.getAnnotation(Ann::class.java)
if (ann == null) throw AssertionError("fail: cannot find Ann on ${klass}")
var result = ""
for (i in ann.p) {
result += i
}
if (result != expected) {
throw AssertionError("fail: expected = ${expected}, actual = ${result}")
}
}