FIR: Adjust diagnostics test data after resolution of context receivers

This commit is contained in:
Denis.Zharkov
2022-03-09 14:32:56 +03:00
committed by teamcity
parent ef84dddc88
commit b2d5bf3eae
40 changed files with 106 additions and 311 deletions
@@ -19,9 +19,9 @@ fun supertypeContextual() {}
context(C1, C2)
fun test() {
<!UNRESOLVED_REFERENCE!>supertypeMember<!>()
<!UNRESOLVED_REFERENCE!>member<!>()
<!UNRESOLVED_REFERENCE!>supertypeExtension<!>()
<!UNRESOLVED_REFERENCE!>supertypeExtensionGeneric<!>()
supertypeContextual()
}
supertypeMember()
<!OVERLOAD_RESOLUTION_AMBIGUITY!>member<!>()
<!AMBIGUOUS_CALL_WITH_IMPLICIT_CONTEXT_RECEIVER!>supertypeExtension<!>()
<!AMBIGUOUS_CALL_WITH_IMPLICIT_CONTEXT_RECEIVER!>supertypeExtensionGeneric<!>()
<!MULTIPLE_ARGUMENTS_APPLICABLE_FOR_CONTEXT_RECEIVER!>supertypeContextual<!>()
}
@@ -4,10 +4,10 @@ class A
class B
fun expectAB(f: context(A, B) () -> Unit) {
f(A(), <!TOO_MANY_ARGUMENTS!>B()<!>)
f(A(), B())
}
fun test() {
val l: context(B, A) () -> Unit = { }
expectAB(l)
}
expectAB(<!ARGUMENT_TYPE_MISMATCH!>l<!>)
}
@@ -1,34 +0,0 @@
// !LANGUAGE: +ContextReceivers
class File(name: String)
interface InputStream
interface AutoCloseScope {
fun defer(closeBlock: () -> Unit)
fun close()
}
class AutoCloseScopeImpl : AutoCloseScope {
override fun defer(closeBlock: () -> Unit) = TODO()
override fun close() = TODO()
}
context(AutoCloseScope)
fun File.open(): InputStream = TODO()
fun withAutoClose(block: context(AutoCloseScope) () -> Unit) {
val scope = AutoCloseScopeImpl() // Not shown here
try {
with(scope) { block() }
} finally {
scope.close()
}
}
fun test() {
withAutoClose {
val input = File("input.txt").open()
val config = File("config.txt").open()
// Work
// All files are closed at the end
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +ContextReceivers
class File(name: String)
@@ -1,18 +0,0 @@
// !LANGUAGE: +ContextReceivers
data class Pair<A, B>(val first: A, val second: B)
context(Comparator<T>)
infix <!INAPPLICABLE_OPERATOR_MODIFIER!>operator<!> fun <T> T.compareTo(other: T) = <!UNRESOLVED_REFERENCE!>compare<!>(this, other)
context(Comparator<T>)
val <T> Pair<T, T>.max get() = if (first > second) first else second
fun test() {
val comparator = Comparator<String> { a, b ->
if (a == null || b == null) 0 else a.length.compareTo(b.length)
}
with(comparator) {
Pair("OK", "fail").max
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +ContextReceivers
data class Pair<A, B>(val first: A, val second: B)
@@ -1,22 +0,0 @@
// !LANGUAGE: +ContextReceivers
class View
context(View) val Int.dp get() = 42 * this
fun View.f() {
123.dp
with(123) {
dp
}
}
fun Int.g(v: View) {
with(v) {
dp
}
}
fun h() {
123.dp
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +ContextReceivers
class View
@@ -19,4 +20,4 @@ fun Int.g(v: View) {
fun h() {
123.<!NO_CONTEXT_RECEIVER!>dp<!>
}
}
@@ -15,7 +15,7 @@ fun Receiver.baz(p: Param) {}
fun main() {
var g: context(Context) Receiver.(Param) -> Unit
g = ::<!UNRESOLVED_REFERENCE!>foo<!> // OK
g = ::bar // OK
g = Receiver::baz // OK
}
g = ::foo // OK
g = ::<!UNRESOLVED_REFERENCE!>bar<!> // OK
g = Receiver::<!UNRESOLVED_REFERENCE!>baz<!> // OK
}
@@ -3,7 +3,7 @@
typealias IterableClass<C, T> = (C) -> Iterator<T>
context(IterableClass<C, T>)
fun <C, T> C.iterator(any: Any?): Iterator<T> = this<!UNRESOLVED_LABEL!>@IterableClass<!>.invoke(this)
fun <C, T> C.iterator(any: Any?): Iterator<T> = this@IterableClass.invoke(this)
fun <T> listOf(vararg items: T): List<T> = null!!
@@ -11,8 +11,8 @@ fun test() {
val f: IterableClass<List<Int>, Int> = {
it.listIterator()
}
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER, NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>with<!>(f) {
with(f) {
listOf(1, 2, 3).iterator(null)
}
listOf(1, 2, 3).<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>iterator<!>(null)
}
listOf(1, 2, 3).<!NO_CONTEXT_RECEIVER!>iterator<!>(null)
}
@@ -1,26 +0,0 @@
// !LANGUAGE: +ContextReceivers
class JSONObject {
fun build(): JSONObject = TODO()
fun put(key: String, any: Any): Unit = TODO()
}
fun json(build: JSONObject.() -> Unit) = JSONObject().apply { build() }
context(JSONObject)
infix fun String.by(build: JSONObject.() -> Unit) = <!UNRESOLVED_REFERENCE!>put<!>(this, JSONObject().build())
context(JSONObject)
infix fun String.by(value: Any) = <!UNRESOLVED_REFERENCE!>put<!>(this, value)
fun test() {
val json = json {
"name" by "Kotlin"
"age" by 10
"creator" by {
"name" by "JetBrains"
"age" by "21"
}
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +ContextReceivers
class JSONObject {
@@ -1,14 +0,0 @@
// !LANGUAGE: +ContextReceivers
interface Params
interface Logger {
fun info(message: String)
}
interface LoggingContext {
val log: Logger // this context provides reference to logger
}
context(LoggingContext)
fun performSomeBusinessOperation(withParams: Params) {
<!UNRESOLVED_REFERENCE!>log<!>.info("Operation has started")
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +ContextReceivers
interface Params
@@ -19,7 +19,7 @@ object StringMonoid : Monoid<String> {
public inline fun <T, R> Iterable<T>.fold(initial: R, operation: (acc: R, T) -> R): R = TODO()
context(Monoid<T>)
fun <T> List<T>.sum(): T = fold(<!ARGUMENT_TYPE_MISMATCH, UNRESOLVED_REFERENCE!>unit<!>) { acc, e -> acc.<!UNRESOLVED_REFERENCE!>combine<!>(e) }
fun <T> List<T>.sum(): T = fold(unit) { acc, e -> acc.combine(e) }
fun <T> listOf(vararg items: T): List<T> = null!!
@@ -28,7 +28,7 @@ fun test() {
listOf(1, 2, 3).sum()
}
with(StringMonoid) {
listOf(1, 2, 3).sum()
listOf(1, 2, 3).<!NO_CONTEXT_RECEIVER!>sum<!>()
listOf("1", "2", "3").sum()
}
}
}
@@ -1,16 +0,0 @@
// !LANGUAGE: +ContextReceivers
class Session(var lastAccess: Any?)
interface Transaction {
fun loadSession(): Session
fun storeSession(session: Session)
}
fun now(): Any? = null
context(Transaction)
fun updateUserSession() {
val session = <!UNRESOLVED_REFERENCE!>loadSession<!>()
session.<!UNRESOLVED_REFERENCE!>lastAccess<!> = now()
<!UNRESOLVED_REFERENCE!>storeSession<!>(session)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +ContextReceivers
class Session(var lastAccess: Any?)
@@ -1,17 +0,0 @@
// !LANGUAGE: +ContextReceivers
class Storage<T> {
inner class Info
fun info(name: String) = Info()
}
class User
class Logger {
fun info(message: String) {}
}
context(Logger, Storage<User>)
fun userInfo(name: String): Storage<User>.Info? {
this<!UNRESOLVED_LABEL!>@Logger<!>.info("Retrieving info about $name")
return this<!UNRESOLVED_LABEL!>@Storage<!>.info(name)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +ContextReceivers
class Storage<T> {
@@ -10,38 +10,38 @@ class R {
context(C)
fun R.f1(g: context(C) R.(Param) -> Unit) {
g(this<!UNRESOLVED_LABEL!>@C<!>, this<!UNRESOLVED_LABEL!>@R<!>, <!TOO_MANY_ARGUMENTS!>Param()<!>)
g(this@C, this<!UNRESOLVED_LABEL!>@R<!>, Param())
}
context(C)
fun f2(g: context(C) (Param) -> Unit) {
g(this<!UNRESOLVED_LABEL!>@C<!>, Param())
g(this@C, Param())
}
context(C)
fun R.f3(g: context(C) R.() -> Unit) {
g(this<!UNRESOLVED_LABEL!>@C<!>, <!TOO_MANY_ARGUMENTS!>this<!UNRESOLVED_LABEL!>@R<!><!>)
g(this@C, this<!UNRESOLVED_LABEL!>@R<!>)
}
context(C)
fun f4(g: context(C) () -> Unit) {
g(this<!UNRESOLVED_LABEL!>@C<!>)
g(this@C)
}
fun test() {
val lf1: context(C) R.(Param) -> Unit = { _ ->
r
<!UNRESOLVED_REFERENCE!>c<!>
c
}
val lf2: context(C) (Param) -> Unit = { _ ->
<!UNRESOLVED_REFERENCE!>c<!>
c
}
val lf3: context(C) R.() -> Unit = {
r
<!UNRESOLVED_REFERENCE!>c<!>
c
}
val lf4: context(C) () -> Unit = {
<!UNRESOLVED_REFERENCE!>c<!>
c
}
with(C()) {
@@ -69,4 +69,4 @@ fun test() {
}
}
}
}
}
@@ -6,10 +6,10 @@ context(Collection<P>) class B<P>
fun Int.foo() {
A<Int>()
<!NO_CONTEXT_RECEIVER!>A<String>()<!>
<!NO_CONTEXT_RECEIVER!>A<!><String>()
}
fun Collection<Int>.bar() {
B<Int>()
<!NO_CONTEXT_RECEIVER!>B<String>()<!>
}
<!NO_CONTEXT_RECEIVER!>B<!><String>()
}
@@ -1,20 +0,0 @@
// !LANGUAGE: +ContextReceivers
class A {
fun h1() {}
}
class B {
fun h2() {}
}
fun B.foo() {
<!UNRESOLVED_REFERENCE!>h1<!>()
h2()
}
context(A)
fun B.bar() {
<!UNRESOLVED_REFERENCE!>h1<!>()
h2()
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +ContextReceivers
class A {
@@ -4,9 +4,9 @@ fun List<Int>.f() {
context(String)
fun Int.f() {
this<!UNRESOLVED_LABEL!>@String<!>.length
this@String.length
this<!UNRESOLVED_LABEL!>@Int<!>.toDouble()
}
context(String)
val p: String get() = this<!UNRESOLVED_LABEL!>@String<!>
val p: String get() = this@String
@@ -15,36 +15,36 @@ fun <T> f(lazy1: Lazy<Int>, lazy2: Lazy<CharSequence>, lazyT: Lazy<T>, lazyLazyT
with(lazy1) {
with(lazy2) {
test1()
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>test2<!>()
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>test3<!>()
test2()
<!NO_CONTEXT_RECEIVER!>test3<!>()
}
}
with(lazy2) {
with(lazy1) {
test1()
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>test2<!>()
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>test3<!>()
test2()
<!NO_CONTEXT_RECEIVER!>test3<!>()
}
}
with(lazyT) {
with(lazy1) {
test1()
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>test2<!>()
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>test3<!>()
<!NO_CONTEXT_RECEIVER!>test1<!>()
test2()
<!NO_CONTEXT_RECEIVER!>test3<!>()
}
}
with(lazyLazyT) {
with(lazy1) {
test1()
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>test2<!>()
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>test3<!>()
<!NO_CONTEXT_RECEIVER!>test1<!>()
test2()
test3()
}
}
with(lazy1) {
with(lazyLazyT) {
test1()
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>test2<!>()
<!NEW_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>test3<!>()
<!NO_CONTEXT_RECEIVER!>test1<!>()
test2()
test3()
}
}
}
}
@@ -1,37 +0,0 @@
// !LANGUAGE: +ContextReceivers
class A {
val a = 1
}
class B {
val b = 2
}
class C {
val c = 3
}
context(A, B) fun C.f() {}
fun main(a: A, b: B, c: C) {
with(a) {
with(b) {
with(c) {
f()
}
}
}
with(b) {
with(c) {
with(a) {
f()
}
}
}
with(a) {
with(c) {
f()
}
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +ContextReceivers
class A {
@@ -31,7 +32,7 @@ fun main(a: A, b: B, c: C) {
}
with(a) {
with(c) {
<!NO_CONTEXT_RECEIVER!>f()<!>
<!NO_CONTEXT_RECEIVER!>f<!>()
}
}
}
}
@@ -14,4 +14,4 @@ context(A, B)
var b = 2
context(A, B)
val c get() = <!UNRESOLVED_REFERENCE!>a<!>() + <!UNRESOLVED_REFERENCE!>b<!>()
val c get() = a() + b()
@@ -7,7 +7,7 @@ class Outer {
context(Outer)
class Inner(arg: Any) {
fun bar() = <!UNRESOLVED_REFERENCE!>x<!>
fun bar() = x
}
fun f(outer: Outer) {
@@ -15,4 +15,4 @@ fun f(outer: Outer) {
with(outer) {
Inner(3)
}
}
}
@@ -11,8 +11,8 @@ class Inner(arg: Any) {
}
fun f(outer: Outer) {
<!NO_CONTEXT_RECEIVER!>Inner(1)<!>
<!NO_CONTEXT_RECEIVER!>Inner<!>(1)
with(outer) {
Inner(3)
}
}
}
@@ -2,16 +2,16 @@
<!CONFLICTING_OVERLOADS!>context(Int, String)
fun foo(): Int<!> {
return <!RETURN_TYPE_MISMATCH!>this<!UNRESOLVED_LABEL!>@Int<!> + 42<!>
return this@Int + 42
}
<!CONFLICTING_OVERLOADS!>context(Int)
fun foo(): Int<!> {
return <!RETURN_TYPE_MISMATCH!>this<!UNRESOLVED_LABEL!>@Int<!> + 42<!>
return this@Int + 42
}
fun test() {
with(42) {
foo()
}
}
}
@@ -3,6 +3,6 @@
class A(val a: String?)
context(A) fun f() {
if (this<!UNRESOLVED_LABEL!>@A<!>.a == null) return
this<!UNRESOLVED_LABEL!>@A<!>.a.length
}
if (this@A.a == null) return
this@A.a.length
}
@@ -5,20 +5,20 @@ class B(val b: Any)
class C(val c: Any)
context(labelAInt@A<Int>, A<String>, labelB@B) fun f() {
this<!UNRESOLVED_LABEL!>@labelAInt<!>.a.toFloat()
this<!UNRESOLVED_LABEL!>@A<!>.a.length
this<!UNRESOLVED_LABEL!>@labelB<!>.b
this@labelAInt.a.toFloat()
this@A.a.length
this@labelB.b
this<!UNRESOLVED_LABEL!>@B<!>
}
context(labelAInt@A<Int>, A<String>, labelB@B) val C.p: Int
get() {
this<!UNRESOLVED_LABEL!>@labelAInt<!>.a.toFloat()
this<!UNRESOLVED_LABEL!>@A<!>.a.length
this@labelAInt.a.toFloat()
this@A.a.length
this<!UNRESOLVED_LABEL!>@B<!>
this<!UNRESOLVED_LABEL!>@labelB<!>.b
this@labelB.b
this<!UNRESOLVED_LABEL!>@C<!>.c
this@p.c
this.c
return 1
}
}
@@ -1,11 +0,0 @@
// !LANGUAGE: +ContextReceivers
class A {
val x = 1
}
context(A) class B {
val prop = <!UNRESOLVED_REFERENCE!>x<!> + this<!UNRESOLVED_LABEL!>@A<!>.x
fun f() = <!UNRESOLVED_REFERENCE!>x<!> + this<!UNRESOLVED_LABEL!>@A<!>.x
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +ContextReceivers
class A {
@@ -5,25 +5,25 @@ class B(val b: Any)
class C(val c: Any)
context(A<String>) fun A<Int>.f() {
this<!UNRESOLVED_LABEL!>@A<!>.a.length
this@A.a.length
}
<!CONFLICTING_OVERLOADS!>context(A<String>, B) fun f()<!> {
this<!UNRESOLVED_LABEL!>@A<!>.a.length
this<!UNRESOLVED_LABEL!>@B<!>.b
this@A.a.length
this@B.b
<!NO_THIS!>this<!>
}
<!CONFLICTING_OVERLOADS!>context(A<Int>, A<String>, B) fun f()<!> {
this<!UNRESOLVED_LABEL!>@A<!>.a.length
this<!UNRESOLVED_LABEL!>@B<!>.b
this@A.a.length
this@B.b
<!NO_THIS!>this<!>
}
context(A<Int>, A<String>, B) fun C.f() {
this<!UNRESOLVED_LABEL!>@A<!>.a.length
this<!UNRESOLVED_LABEL!>@B<!>.b
this@A.a.length
this@B.b
this<!UNRESOLVED_LABEL!>@C<!>.c
this@f.c
this.c
}
}
@@ -6,39 +6,39 @@ class C(val c: Any)
<!MUST_BE_INITIALIZED!>context(A<String>, B) var <!REDECLARATION!>p<!>: Int<!>
get() {
this<!UNRESOLVED_LABEL!>@A<!>.a.length
this<!UNRESOLVED_LABEL!>@B<!>.b
this@A.a.length
this@B.b
<!NO_THIS!>this<!>
return 1
}
set(value) {
this<!UNRESOLVED_LABEL!>@A<!>.a.length
this<!UNRESOLVED_LABEL!>@B<!>.b
this@A.a.length
this@B.b
<!NO_THIS!>this<!>
field = value
}
<!MUST_BE_INITIALIZED!>context(A<Int>, A<String>, B) var <!REDECLARATION!>p<!>: Int<!>
get() {
this<!UNRESOLVED_LABEL!>@A<!>.a.toDouble()
this<!UNRESOLVED_LABEL!>@A<!>.a.length
this<!UNRESOLVED_LABEL!>@B<!>.b
this@A.a.<!UNRESOLVED_REFERENCE!>toDouble<!>()
this@A.a.length
this@B.b
<!NO_THIS!>this<!>
return 1
}
set(value) {
this<!UNRESOLVED_LABEL!>@A<!>.a.length
this<!UNRESOLVED_LABEL!>@B<!>.b
this@A.a.length
this@B.b
<!NO_THIS!>this<!>
field = value
}
context(A<Int>, A<String>, B) val C.p: Int
get() {
this<!UNRESOLVED_LABEL!>@A<!>.a.length
this<!UNRESOLVED_LABEL!>@B<!>.b
this@A.a.length
this@B.b
this<!UNRESOLVED_LABEL!>@C<!>.c
this@p.c
this.c
return 1
}
}
@@ -13,6 +13,6 @@ fun main() {
A<Int>().f()
}
with(listOf("1", "2", "3")) {
A<Int>().f()
A<Int>().<!NO_CONTEXT_RECEIVER!>f<!>()
}
}
}
@@ -10,11 +10,11 @@ fun B.f() {}
fun main() {
val b = B()
b.f()
b.<!NO_CONTEXT_RECEIVER!>f<!>()
with(A()) {
b.f()
}
with(C()) {
b.f()
}
}
}
@@ -10,11 +10,11 @@ fun B.f() {}
fun main() {
val b = B()
b.f()
b.<!NO_CONTEXT_RECEIVER!>f<!>()
with(A()) {
b.f()
}
with(C()) {
b.f()
b.<!NO_CONTEXT_RECEIVER!>f<!>()
}
}
}