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
@@ -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> {