FIR checker: honor DSL marker annotation on the function type

It seems the original function type gets lost during resolution. Hence
thie change added a custom attribute to recover the original function
type on an anonymous function
This commit is contained in:
Tianyu Geng
2021-09-15 21:36:32 -07:00
committed by TeamCityServer
parent 826ea122a9
commit c572bf05b5
11 changed files with 65 additions and 190 deletions
@@ -21,7 +21,7 @@ fun baz4(x: @MyDsl B.() -> Unit) {}
fun @MyDsl A.baz5() {
baz4 {
bar()
foo()
<!DSL_SCOPE_VIOLATION!>foo<!>()
}
}
@@ -36,21 +36,21 @@ fun main() {
baz3 {
baz2 {
bar()
foo()
<!DSL_SCOPE_VIOLATION!>foo<!>()
}
}
baz1 {
baz4 {
bar()
foo()
<!DSL_SCOPE_VIOLATION!>foo<!>()
}
}
baz3 {
baz4 {
bar()
foo()
<!DSL_SCOPE_VIOLATION!>foo<!>()
}
}
@@ -1,57 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !LANGUAGE: +DslMarkerOnFunctionTypeReceiver
@Target(AnnotationTarget.TYPE)
@DslMarker
annotation class MyDsl
interface A {
fun foo()
}
interface B {
fun bar()
}
fun baz1(x: (@MyDsl A).() -> Unit) {}
fun baz2(x: (@MyDsl B).() -> Unit) {}
fun baz3(x: @MyDsl A.() -> Unit) {}
fun baz4(x: @MyDsl B.() -> Unit) {}
fun @MyDsl A.baz5() {
baz4 {
bar()
foo()
}
}
fun main() {
baz1 {
baz2 {
bar()
<!DSL_SCOPE_VIOLATION!>foo<!>()
}
}
baz3 {
baz2 {
bar()
foo()
}
}
baz1 {
baz4 {
bar()
foo()
}
}
baz3 {
baz4 {
bar()
foo()
}
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !LANGUAGE: +DslMarkerOnFunctionTypeReceiver
@@ -1,92 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
@DslMarker
@Target(AnnotationTarget.TYPE)
annotation class L1
@DslMarker
@Target(AnnotationTarget.TYPE)
annotation class L2
class A {
fun a() = 1
}
class B {
fun b() = 2
}
fun foo1(x: (@L1 A).() -> Unit) {}
fun foo2(x: (@L2 A).() -> Unit) {}
fun foo12(x: (@L1 @L2 A).() -> Unit) {}
fun bar1(x: (@L1 B).() -> Unit) {}
fun bar2(x: (@L2 B).() -> Unit) {}
fun <T> bar1t(q: T, x: (@L1 T).() -> Unit) {}
fun test() {
foo12 {
a()
bar1 {
<!DSL_SCOPE_VIOLATION!>a<!>()
b()
}
bar2 {
<!DSL_SCOPE_VIOLATION!>a<!>()
b()
}
}
bar1 {
b()
foo12 {
a()
<!DSL_SCOPE_VIOLATION!>b<!>()
}
}
bar2 {
b()
foo12 {
a()
<!DSL_SCOPE_VIOLATION!>b<!>()
}
}
foo2 {
bar1t(this) {
a()
bar1 {
a()
b()
}
bar2 {
<!DSL_SCOPE_VIOLATION!>a<!>()
b()
}
}
}
bar1 {
b()
foo2 {
bar1t(this) {
a()
b()
}
}
}
bar2 {
b()
foo2 {
bar1t(this) {
a()
<!DSL_SCOPE_VIOLATION!>b<!>()
}
}
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
@DslMarker
@Target(AnnotationTarget.TYPE)
@@ -1,26 +0,0 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
@DslMarker
@Target(AnnotationTarget.TYPE)
annotation class Ann
class A {
fun a() = 1
}
class B {
fun b() = 2
}
fun <T> foo(x: (@Ann T).() -> Unit) {}
fun <E> bar(x: (@Ann E).() -> Unit) {}
fun test() {
foo<A> {
a()
bar<B> {
a()
this@foo.a()
b()
}
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
@DslMarker
@Target(AnnotationTarget.TYPE)