-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IC & Coroutines: Do not box suspend operator fun invoke receiver
if it is called using parens and not by calling 'invoke' method. Use underlying type when calling continuation constructor if suspend function is method inside inline class. #KT-43505 Fixed #KT-39437 Fixed
- Loading branch information
Showing
12 changed files
with
331 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
...ler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
62 changes: 62 additions & 0 deletions
62
compiler/testData/codegen/box/coroutines/inlineClasses/direct/invokeOperator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// WITH_RUNTIME | ||
|
||
import kotlin.coroutines.* | ||
|
||
fun builder(c: suspend () -> Unit) { | ||
c.startCoroutine(Continuation(EmptyCoroutineContext) { | ||
it.getOrThrow() | ||
}) | ||
} | ||
|
||
inline class IC(val a: Any?) | ||
|
||
class GetResult { | ||
suspend operator fun invoke() = IC("OK") | ||
} | ||
|
||
inline class IC1(val a: String) { | ||
suspend operator fun invoke() = IC(a) | ||
} | ||
|
||
fun box(): String { | ||
var res = "FAIL 1" | ||
builder { | ||
val getResult = GetResult() | ||
res = getResult().a as String | ||
} | ||
if (res != "OK") return "FAIL 1 $res" | ||
|
||
res = "FAIL 2" | ||
builder { | ||
val getResult = GetResult() | ||
res = getResult.invoke().a as String | ||
} | ||
if (res != "OK") return "FAIL 2 $res" | ||
|
||
res = "FAIL 3" | ||
builder { | ||
res = GetResult()().a as String | ||
} | ||
if (res != "OK") return "FAIL 3 $res" | ||
|
||
res = "FAIL 4" | ||
builder { | ||
val getResult = IC1("OK") | ||
res = getResult().a as String | ||
} | ||
if (res != "OK") return "FAIL 4 $res" | ||
|
||
res = "FAIL 5" | ||
builder { | ||
val getResult = IC1("OK") | ||
res = getResult.invoke().a as String | ||
} | ||
if (res != "OK") return "FAIL 5 $res" | ||
|
||
res = "FAIL 6" | ||
builder { | ||
res = IC1("OK")().a as String | ||
} | ||
if (res != "OK") return "FAIL 6 $res" | ||
return res | ||
} |
75 changes: 75 additions & 0 deletions
75
compiler/testData/codegen/box/coroutines/inlineClasses/resume/invokeOperator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// WITH_RUNTIME | ||
|
||
import kotlin.coroutines.* | ||
|
||
fun builder(c: suspend () -> Unit) { | ||
c.startCoroutine(Continuation(EmptyCoroutineContext) { | ||
it.getOrThrow() | ||
}) | ||
} | ||
|
||
inline class IC(val a: Any?) | ||
|
||
var c: Continuation<Any>? = null | ||
|
||
suspend fun <T> suspendMe(): T = suspendCoroutine { | ||
@Suppress("UNCHECKED_CAST") | ||
c = it as Continuation<Any> | ||
} | ||
|
||
class GetResult { | ||
suspend operator fun invoke(): IC = suspendMe() | ||
} | ||
|
||
inline class IC1(val a: String) { | ||
suspend operator fun invoke(): IC = suspendMe() | ||
} | ||
|
||
fun box(): String { | ||
var res = "FAIL 1" | ||
builder { | ||
val getResult = GetResult() | ||
res = getResult().a as String | ||
} | ||
c?.resume(IC("OK")) | ||
if (res != "OK") return "FAIL 1 $res" | ||
|
||
res = "FAIL 2" | ||
builder { | ||
val getResult = GetResult() | ||
res = getResult.invoke().a as String | ||
} | ||
c?.resume(IC("OK")) | ||
if (res != "OK") return "FAIL 2 $res" | ||
|
||
res = "FAIL 3" | ||
builder { | ||
res = GetResult()().a as String | ||
} | ||
c?.resume(IC("OK")) | ||
if (res != "OK") return "FAIL 3 $res" | ||
|
||
res = "FAIL 4" | ||
builder { | ||
val getResult = IC1("OK") | ||
res = getResult().a as String | ||
} | ||
c?.resume(IC("OK")) | ||
if (res != "OK") return "FAIL 4 $res" | ||
|
||
res = "FAIL 5" | ||
builder { | ||
val getResult = IC1("OK") | ||
res = getResult.invoke().a as String | ||
} | ||
c?.resume(IC("OK")) | ||
if (res != "OK") return "FAIL 5 $res" | ||
|
||
res = "FAIL 6" | ||
builder { | ||
res = IC1("OK")().a as String | ||
} | ||
c?.resume(IC("OK")) | ||
if (res != "OK") return "FAIL 6 $res" | ||
return res | ||
} |
78 changes: 78 additions & 0 deletions
78
compiler/testData/codegen/box/coroutines/inlineClasses/resumeWithException/invokeOperator.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// WITH_RUNTIME | ||
// WITH_COROUTINES | ||
|
||
import kotlin.coroutines.* | ||
import helpers.* | ||
|
||
var result = "FAIL" | ||
|
||
fun builder(c: suspend () -> Unit) { | ||
c.startCoroutine(handleExceptionContinuation { | ||
result = it.message!! | ||
}) | ||
} | ||
|
||
inline class IC(val a: Any?) | ||
|
||
var c: Continuation<Any>? = null | ||
|
||
suspend fun <T> suspendMe(): T = suspendCoroutine { | ||
@Suppress("UNCHECKED_CAST") | ||
c = it as Continuation<Any> | ||
} | ||
|
||
class GetResult { | ||
suspend operator fun invoke(): IC = suspendMe() | ||
} | ||
|
||
inline class IC1(val a: String) { | ||
suspend operator fun invoke(): IC = suspendMe() | ||
} | ||
|
||
fun box(): String { | ||
builder { | ||
val getResult = GetResult() | ||
getResult() | ||
} | ||
c?.resumeWithException(IllegalStateException("OK")) | ||
if (result != "OK") return "FAIL 1 $result" | ||
|
||
result = "FAIL 2" | ||
builder { | ||
val getResult = GetResult() | ||
getResult.invoke() | ||
} | ||
c?.resumeWithException(IllegalStateException("OK")) | ||
if (result != "OK") return "FAIL 2 $result" | ||
|
||
result = "FAIL 3" | ||
builder { | ||
GetResult()() | ||
} | ||
c?.resumeWithException(IllegalStateException("OK")) | ||
if (result != "OK") return "FAIL 3 $result" | ||
|
||
result = "FAIL 4" | ||
builder { | ||
val getResult = IC1("OK") | ||
getResult() | ||
} | ||
c?.resumeWithException(IllegalStateException("OK")) | ||
if (result != "OK") return "FAIL 4 $result" | ||
|
||
result = "FAIL 5" | ||
builder { | ||
val getResult = IC1("OK") | ||
getResult.invoke() | ||
} | ||
c?.resumeWithException(IllegalStateException("OK")) | ||
if (result != "OK") return "FAIL 5 $result" | ||
|
||
result = "FAIL 6" | ||
builder { | ||
IC1("OK")() | ||
} | ||
c?.resumeWithException(IllegalStateException("OK")) | ||
if (result != "OK") return "FAIL 6 $result" | ||
return result | ||
} |
15 changes: 15 additions & 0 deletions
15
compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
15 changes: 15 additions & 0 deletions
15
compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.