Skip to content

Commit 8c84717

Browse files
committed
Kotlin Facet: Reset all coroutine support flags before importing them frm Gradle
1 parent a2e429a commit 8c84717

File tree

2 files changed

+60
-3
lines changed

2 files changed

+60
-3
lines changed

idea/src/org/jetbrains/kotlin/idea/facet/facetUtils.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,11 +231,16 @@ fun parseCompilerArgumentsToFacet(arguments: List<String>, defaultArguments: Lis
231231
commonCompilerArguments.coroutinesWarn = false
232232
commonCompilerArguments.coroutinesError = false
233233

234+
if (compilerArguments != commonCompilerArguments) {
235+
compilerArguments.coroutinesEnable = false
236+
compilerArguments.coroutinesWarn = false
237+
compilerArguments.coroutinesError = false
238+
}
239+
234240
parseArguments(argumentArray, compilerArguments, true)
235241

236-
if (!compilerArguments.coroutinesEnable && !compilerArguments.coroutinesWarn && !compilerArguments.coroutinesError) {
237-
compilerInfo.coroutineSupport = oldCoroutineSupport
238-
}
242+
val restoreCoroutineSupport =
243+
!compilerArguments.coroutinesEnable && !compilerArguments.coroutinesWarn && !compilerArguments.coroutinesError
239244

240245
versionInfo.apiLevel = LanguageVersion.fromVersionString(compilerArguments.apiVersion)
241246
versionInfo.languageLevel = LanguageVersion.fromVersionString(compilerArguments.languageVersion)
@@ -268,5 +273,9 @@ fun parseCompilerArgumentsToFacet(arguments: List<String>, defaultArguments: Lis
268273
}
269274

270275
copyInheritedFields(compilerArguments, commonCompilerArguments)
276+
277+
if (restoreCoroutineSupport) {
278+
compilerInfo.coroutineSupport = oldCoroutineSupport
279+
}
271280
}
272281
}

idea/tests/org/jetbrains/kotlin/idea/codeInsight/gradle/GradleFacetImportTest.kt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,54 @@ class GradleFacetImportTest : GradleImportingTestCase() {
109109
}
110110
}
111111

112+
@Test
113+
fun testFixCorruptedCoroutines() {
114+
createProjectSubFile("build.gradle", """
115+
group 'Again'
116+
version '1.0-SNAPSHOT'
117+
118+
buildscript {
119+
repositories {
120+
mavenCentral()
121+
maven {
122+
url 'http://dl.bintray.com/kotlin/kotlin-eap-1.1'
123+
}
124+
}
125+
126+
dependencies {
127+
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.0-beta-38")
128+
}
129+
}
130+
131+
apply plugin: 'kotlin'
132+
133+
dependencies {
134+
compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.0-beta-38"
135+
}
136+
137+
kotlin {
138+
experimental {
139+
coroutines 'enable'
140+
}
141+
}
142+
""")
143+
144+
importProject()
145+
146+
with (facetSettings) {
147+
compilerInfo.k2jvmCompilerArguments!!.coroutinesEnable = true
148+
compilerInfo.k2jvmCompilerArguments!!.coroutinesWarn = true
149+
compilerInfo.k2jvmCompilerArguments!!.coroutinesError = true
150+
151+
importProject()
152+
153+
Assert.assertEquals(CoroutineSupport.ENABLED, compilerInfo.coroutineSupport)
154+
Assert.assertEquals(true, compilerInfo.k2jvmCompilerArguments!!.coroutinesEnable)
155+
Assert.assertEquals(false, compilerInfo.k2jvmCompilerArguments!!.coroutinesWarn)
156+
Assert.assertEquals(false, compilerInfo.k2jvmCompilerArguments!!.coroutinesError)
157+
}
158+
}
159+
112160
@Test
113161
fun testCoroutineImportByProperties() {
114162
createProjectSubFile("gradle.properties", "kotlin.coroutines=enable")

0 commit comments

Comments
 (0)