From 87b0670bbb8b4ec36e459ecc39f660c942af4bec Mon Sep 17 00:00:00 2001 From: "Anastasia.Shadrina" Date: Fri, 21 Jan 2022 16:37:37 +0700 Subject: [PATCH] [Tests] Add CompileKotlinAgainstCustomBinaries test for CR --- .../contextualDeclarationUse.kt | 12 ++++++++++++ .../library/source.kt | 19 +++++++++++++++++++ .../contextualDeclarationUse/output.txt | 16 ++++++++++++++++ .../CompileKotlinAgainstCustomBinariesTest.kt | 5 +++++ 4 files changed, 52 insertions(+) create mode 100644 compiler/testData/compileKotlinAgainstCustomBinaries/contextualDeclarationUse/contextualDeclarationUse.kt create mode 100644 compiler/testData/compileKotlinAgainstCustomBinaries/contextualDeclarationUse/library/source.kt create mode 100644 compiler/testData/compileKotlinAgainstCustomBinaries/contextualDeclarationUse/output.txt diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/contextualDeclarationUse/contextualDeclarationUse.kt b/compiler/testData/compileKotlinAgainstCustomBinaries/contextualDeclarationUse/contextualDeclarationUse.kt new file mode 100644 index 00000000000..4394f31fb9b --- /dev/null +++ b/compiler/testData/compileKotlinAgainstCustomBinaries/contextualDeclarationUse/contextualDeclarationUse.kt @@ -0,0 +1,12 @@ +package test + +fun callOrdinaryAndContextualDeclaration() { + ordinary() + with(42) { + f() + val a = A() + a.p + a.m() + p + } +} \ No newline at end of file diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/contextualDeclarationUse/library/source.kt b/compiler/testData/compileKotlinAgainstCustomBinaries/contextualDeclarationUse/library/source.kt new file mode 100644 index 00000000000..b90d0ca72dc --- /dev/null +++ b/compiler/testData/compileKotlinAgainstCustomBinaries/contextualDeclarationUse/library/source.kt @@ -0,0 +1,19 @@ +package test + +context(Int) val p get() = 42 + +context(Int) +class A { + context(Int) val p get() = 42 + + context(Int) fun m() {} +} + +context(String) +fun f() { + println(this@String) +} + +fun ordinary() { + println("I do not require context receivers!") +} \ No newline at end of file diff --git a/compiler/testData/compileKotlinAgainstCustomBinaries/contextualDeclarationUse/output.txt b/compiler/testData/compileKotlinAgainstCustomBinaries/contextualDeclarationUse/output.txt new file mode 100644 index 00000000000..f5cfab5d1f5 --- /dev/null +++ b/compiler/testData/compileKotlinAgainstCustomBinaries/contextualDeclarationUse/output.txt @@ -0,0 +1,16 @@ +compiler/testData/compileKotlinAgainstCustomBinaries/contextualDeclarationUse/contextualDeclarationUse.kt:6:9: error: to use contextual declarations, specify the `-Xcontext-receivers` compiler option + f() + ^ +compiler/testData/compileKotlinAgainstCustomBinaries/contextualDeclarationUse/contextualDeclarationUse.kt:7:17: error: to use contextual declarations, specify the `-Xcontext-receivers` compiler option + val a = A() + ^ +compiler/testData/compileKotlinAgainstCustomBinaries/contextualDeclarationUse/contextualDeclarationUse.kt:8:11: error: to use contextual declarations, specify the `-Xcontext-receivers` compiler option + a.p + ^ +compiler/testData/compileKotlinAgainstCustomBinaries/contextualDeclarationUse/contextualDeclarationUse.kt:9:11: error: to use contextual declarations, specify the `-Xcontext-receivers` compiler option + a.m() + ^ +compiler/testData/compileKotlinAgainstCustomBinaries/contextualDeclarationUse/contextualDeclarationUse.kt:10:9: error: to use contextual declarations, specify the `-Xcontext-receivers` compiler option + p + ^ +COMPILATION_ERROR diff --git a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.kt b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.kt index ca014cbf036..f8c7c369510 100644 --- a/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/jvm/compiler/CompileKotlinAgainstCustomBinariesTest.kt @@ -542,6 +542,11 @@ class CompileKotlinAgainstCustomBinariesTest : AbstractKotlinCompilerIntegration compileKotlin("source.kt", tmpdir, listOf(library), additionalOptions = listOf("-jvm-target", "1.8", "-Xjvm-default=all")) } + fun testContextualDeclarationUse() { + val library = compileLibrary("library", additionalOptions = listOf("-Xcontext-receivers")) + compileKotlin("contextualDeclarationUse.kt", tmpdir, listOf(library), additionalOptions = listOf("-Xskip-prerelease-check")) + } + fun testJvmDefaultClashWithNoCompatibility() { val library = compileLibrary("library", additionalOptions = listOf("-Xjvm-default=disable")) compileKotlin("source.kt", tmpdir, listOf(library), additionalOptions = listOf("-jvm-target", "1.8", "-Xjvm-default=all-compatibility"))