diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/binding/CodegenAnnotatingVisitor.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/binding/CodegenAnnotatingVisitor.java index 555341df84b..e0531b8abea 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/binding/CodegenAnnotatingVisitor.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/binding/CodegenAnnotatingVisitor.java @@ -193,8 +193,15 @@ class CodegenAnnotatingVisitor extends KtVisitorVoid { @Override public void visitScript(@NotNull KtScript script) { - classStack.push(bindingContext.get(SCRIPT, script)); - nameStack.push(AsmUtil.internalNameByFqNameWithoutInnerClasses(script.getFqName())); + ClassDescriptor scriptDescriptor = bindingContext.get(SCRIPT, script); + // working around a problem with shallow analysis + if (scriptDescriptor == null) return; + + String scriptInternalName = AsmUtil.internalNameByFqNameWithoutInnerClasses(script.getFqName()); + recordClosure(scriptDescriptor, scriptInternalName); + + classStack.push(scriptDescriptor); + nameStack.push(scriptInternalName); script.acceptChildren(this); nameStack.pop(); classStack.pop(); diff --git a/compiler/testData/codegen/script/kt20707.kts b/compiler/testData/codegen/script/kt20707.kts new file mode 100644 index 00000000000..3ddef76bccc --- /dev/null +++ b/compiler/testData/codegen/script/kt20707.kts @@ -0,0 +1,10 @@ +enum class Build { Debug, Release } + +fun applySomething(build: Build) = when (build) { + Build.Debug -> "OK" + Build.Release -> "fail" +} + +val rv = applySomething(Build.Debug) + +// expected: rv: OK \ No newline at end of file diff --git a/compiler/testData/repl/controlFlow/kt15407.repl b/compiler/testData/repl/controlFlow/kt15407.repl new file mode 100644 index 00000000000..8d1934bd62b --- /dev/null +++ b/compiler/testData/repl/controlFlow/kt15407.repl @@ -0,0 +1,8 @@ +>>> enum class Build { Debug, Release } + +>>> fun applySomething(build: Build) = when (build) { +... Build.Debug -> "OK" +... Build.Release -> "fail" +...} +>>> applySomething(Build.Debug) +OK diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ScriptCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ScriptCodegenTestGenerated.java index 428119fff92..01d8844329f 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ScriptCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ScriptCodegenTestGenerated.java @@ -78,6 +78,12 @@ public class ScriptCodegenTestGenerated extends AbstractScriptCodegenTest { doTest(fileName); } + @TestMetadata("kt20707.kts") + public void testKt20707() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/script/kt20707.kts"); + doTest(fileName); + } + @TestMetadata("localDelegatedProperty.kts") public void testLocalDelegatedProperty() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/script/localDelegatedProperty.kts"); diff --git a/compiler/tests/org/jetbrains/kotlin/repl/ReplInterpreterTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/repl/ReplInterpreterTestGenerated.java index 9f6902d0f48..970148ca827 100644 --- a/compiler/tests/org/jetbrains/kotlin/repl/ReplInterpreterTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/repl/ReplInterpreterTestGenerated.java @@ -245,6 +245,12 @@ public class ReplInterpreterTestGenerated extends AbstractReplInterpreterTest { doTest(fileName); } + @TestMetadata("kt15407.repl") + public void testKt15407() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/repl/controlFlow/kt15407.repl"); + doTest(fileName); + } + @TestMetadata("loopWithWrongLabel.repl") public void testLoopWithWrongLabel() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/repl/controlFlow/loopWithWrongLabel.repl");