diff --git a/compiler/conditional-preprocessor/src/org.jetbrains.kotlin.preprocessor/logging.kt b/compiler/conditional-preprocessor/src/org.jetbrains.kotlin.preprocessor/logging.kt index 5f3e25dfd63..25067bfd85d 100644 --- a/compiler/conditional-preprocessor/src/org.jetbrains.kotlin.preprocessor/logging.kt +++ b/compiler/conditional-preprocessor/src/org.jetbrains.kotlin.preprocessor/logging.kt @@ -27,7 +27,9 @@ public object SystemOutLogger : Logger { private fun out(level: String, msg: CharSequence) = println("[$level] $msg") public var isDebugEnabled: Boolean = true - override fun debug(msg: CharSequence) = if (isDebugEnabled) out("DEBUG", msg) + override fun debug(msg: CharSequence) { + if (isDebugEnabled) out("DEBUG", msg) + } override fun info(msg: CharSequence) = out("INFO", msg) override fun warn(msg: CharSequence) = out("WARN", msg) override fun error(msg: CharSequence) = out("ERROR", msg) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index bff465edb6b..a6a6dd973be 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -610,6 +610,8 @@ public interface Errors { DiagnosticFactory0 SENSELESS_NULL_IN_WHEN = DiagnosticFactory0.create(WARNING); + DiagnosticFactory0 INVALID_IF_AS_EXPRESSION = DiagnosticFactory0.create(ERROR); + // Nullability DiagnosticFactory1 UNSAFE_CALL = DiagnosticFactory1.create(ERROR); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java index f7d56efe498..ce6ae995e63 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/rendering/DefaultErrorMessages.java @@ -537,6 +537,8 @@ public class DefaultErrorMessages { MAP.put(SENSELESS_COMPARISON, "Condition ''{0}'' is always ''{1}''", ELEMENT_TEXT, TO_STRING); MAP.put(SENSELESS_NULL_IN_WHEN, "Expression under 'when' is never equal to null"); + MAP.put(INVALID_IF_AS_EXPRESSION, "'if' must have both main and 'else' branches if used as an expression"); + MAP.put(OVERRIDING_FINAL_MEMBER, "''{0}'' in ''{1}'' is final and cannot be overridden", NAME, NAME); MAP.put(CANNOT_WEAKEN_ACCESS_PRIVILEGE, "Cannot weaken access privilege ''{0}'' for ''{1}'' in ''{2}''", TO_STRING, NAME, NAME); MAP.put(CANNOT_CHANGE_ACCESS_PRIVILEGE, "Cannot change access privilege ''{0}'' for ''{1}'' in ''{2}''", TO_STRING, NAME, NAME); diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt index e1c08420441..7b8ccafbb53 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CandidateResolver.kt @@ -504,8 +504,11 @@ public class CandidateResolver( private fun CallCandidateResolutionContext.shouldContinue() = candidateResolveMode == CandidateResolveMode.FULLY || candidateCall.getStatus().possibleTransformToSuccess() - private inline fun CallCandidateResolutionContext - .check(checker: CallCandidateResolutionContext.() -> Unit): Unit = if (shouldContinue()) checker() + private inline fun CallCandidateResolutionContext.check( + checker: CallCandidateResolutionContext.() -> Unit + ) { + if (shouldContinue()) checker() + } private inline fun CallCandidateResolutionContext. checkAndReport(checker: CallCandidateResolutionContext.() -> ResolutionStatus) { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DataFlowAnalyzer.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DataFlowAnalyzer.java index 266efa0bdf9..780e7a970fd 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DataFlowAnalyzer.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/DataFlowAnalyzer.java @@ -256,10 +256,21 @@ public class DataFlowAnalyzer { @Nullable public JetType checkImplicitCast(@Nullable JetType expressionType, @NotNull JetExpression expression, @NotNull ResolutionContext context, boolean isStatement) { - if (expressionType != null && context.expectedType == NO_EXPECTED_TYPE && context.contextDependency == INDEPENDENT && !isStatement + boolean isIfExpression = expression instanceof JetIfExpression; + if (expressionType != null && (context.expectedType == NO_EXPECTED_TYPE || isIfExpression) + && context.contextDependency == INDEPENDENT && !isStatement && (KotlinBuiltIns.isUnit(expressionType) || KotlinBuiltIns.isAnyOrNullableAny(expressionType)) && !DynamicTypesKt.isDynamic(expressionType)) { - context.trace.report(IMPLICIT_CAST_TO_UNIT_OR_ANY.on(expression, expressionType)); + if (isIfExpression && KotlinBuiltIns.isUnit(expressionType)) { + JetIfExpression ifExpression = (JetIfExpression) expression; + if (ifExpression.getThen() == null || ifExpression.getElse() == null) { + context.trace.report(INVALID_IF_AS_EXPRESSION.on((JetIfExpression) expression)); + return expressionType; + } + } + else { + context.trace.report(IMPLICIT_CAST_TO_UNIT_OR_ANY.on(expression, expressionType)); + } } return expressionType; } diff --git a/compiler/testData/codegen/box/controlStructures/emptyIf.kt b/compiler/testData/codegen/box/controlStructures/emptyIf.kt deleted file mode 100644 index 0a251a74017..00000000000 --- a/compiler/testData/codegen/box/controlStructures/emptyIf.kt +++ /dev/null @@ -1,12 +0,0 @@ -fun box(): String { - if (true); - if (false); - val iftrue = if (true); - val iffalse = if (false); - - var state = 0 - val k = if (state++==1); - if (state != 1) return "Fail: $state" - - return "OK" -} diff --git a/compiler/testData/codegen/box/controlStructures/kt2062.kt b/compiler/testData/codegen/box/controlStructures/kt2062.kt deleted file mode 100644 index cd44f191da7..00000000000 --- a/compiler/testData/codegen/box/controlStructures/kt2062.kt +++ /dev/null @@ -1,5 +0,0 @@ -fun box(): String { - val a = if(true) { - } - return if (a.toString() == "kotlin.Unit") "OK" else "fail" -} diff --git a/compiler/testData/codegen/box/controlStructures/kt2598.kt b/compiler/testData/codegen/box/controlStructures/kt2598.kt deleted file mode 100644 index 133f6f42cae..00000000000 --- a/compiler/testData/codegen/box/controlStructures/kt2598.kt +++ /dev/null @@ -1,9 +0,0 @@ -fun foo(condition: Boolean): String { - val u = if (condition) { - "OK" - } else { - } - return u.toString() -} - -fun box() = foo(true) diff --git a/compiler/testData/codegen/box/finally/notChainCatch.kt b/compiler/testData/codegen/box/finally/notChainCatch.kt index 2c54d7501b6..18e5573b318 100644 --- a/compiler/testData/codegen/box/finally/notChainCatch.kt +++ b/compiler/testData/codegen/box/finally/notChainCatch.kt @@ -1,5 +1,10 @@ -fun unsupportedEx() = if (true) throw UnsupportedOperationException() -fun runtimeEx() = if (true) throw RuntimeException() +fun unsupportedEx() { + if (true) throw UnsupportedOperationException() +} + +fun runtimeEx() { + if (true) throw RuntimeException() +} fun test1() : String { var s = ""; diff --git a/compiler/testData/codegen/box/finally/tryFinally.kt b/compiler/testData/codegen/box/finally/tryFinally.kt index 8fd7f620eeb..39928fbec60 100644 --- a/compiler/testData/codegen/box/finally/tryFinally.kt +++ b/compiler/testData/codegen/box/finally/tryFinally.kt @@ -1,5 +1,10 @@ -fun unsupportedEx() = if (true) throw UnsupportedOperationException() -fun runtimeEx() = if (true) throw RuntimeException() +fun unsupportedEx() { + if (true) throw UnsupportedOperationException() +} + +fun runtimeEx() { + if (true) throw RuntimeException() +} fun test1WithFinally() : String { var s = ""; diff --git a/compiler/testData/codegen/box/primitiveTypes/comparisonWithNaN.kt b/compiler/testData/codegen/box/primitiveTypes/comparisonWithNaN.kt index 4acf18bf4cb..d9aa65dfa92 100644 --- a/compiler/testData/codegen/box/primitiveTypes/comparisonWithNaN.kt +++ b/compiler/testData/codegen/box/primitiveTypes/comparisonWithNaN.kt @@ -1,7 +1,8 @@ // This test checks that our bytecode is consistent with javac bytecode -fun _assert(condition: Boolean): Unit = +fun _assert(condition: Boolean) { if (!condition) throw AssertionError("Fail") +} fun _assertFalse(condition: Boolean) = _assert(!condition) diff --git a/compiler/testData/codegen/box/unit/ifElse.kt b/compiler/testData/codegen/box/unit/ifElse.kt index 58f2d8910b6..171b2b2fdeb 100644 --- a/compiler/testData/codegen/box/unit/ifElse.kt +++ b/compiler/testData/codegen/box/unit/ifElse.kt @@ -4,9 +4,9 @@ class A (val p: String, p1: String, p2: String) { var cond2: String = "" - val prop1 = if (cond1(p)) p1 + val prop1 = if (cond1(p)) p1 else null - val prop2 = if (cond2(p)) else; + val prop2 = if (cond2(p)) p2 else null; fun cond1(p: String): Boolean { diff --git a/compiler/testData/codegen/boxWithStdlib/lazyCodegen/ifElse.kt b/compiler/testData/codegen/boxWithStdlib/lazyCodegen/ifElse.kt index 3a316055ece..0f683860b24 100644 --- a/compiler/testData/codegen/boxWithStdlib/lazyCodegen/ifElse.kt +++ b/compiler/testData/codegen/boxWithStdlib/lazyCodegen/ifElse.kt @@ -6,9 +6,9 @@ class A (val p: String, p1: String, p2: String) { val prop: String = if (p == "test") p1 else p2 - val prop1 = if (cond1(p)) p1 + val prop1 = if (cond1(p)) p1 else false - val prop2 = if (cond2(p)) else; + val prop2 = if (cond2(p)) true else false fun cond1(p: String): Boolean { cond1 = "cond1" diff --git a/compiler/testData/diagnostics/tests/FunctionReturnTypes.kt b/compiler/testData/diagnostics/tests/FunctionReturnTypes.kt index f659243e884..4743893d877 100644 --- a/compiler/testData/diagnostics/tests/FunctionReturnTypes.kt +++ b/compiler/testData/diagnostics/tests/FunctionReturnTypes.kt @@ -69,10 +69,10 @@ fun blockReturnValueTypeMatch1() : Int { return if (1 > 2) 1.0 else 2.0 } fun blockReturnValueTypeMatch2() : Int { - return if (1 > 2) 1 + return if (1 > 2) 1 } fun blockReturnValueTypeMatch3() : Int { - return if (1 > 2) else 1 + return if (1 > 2) else 1 } fun blockReturnValueTypeMatch4() : Int { if (1 > 2) @@ -105,7 +105,7 @@ fun blockReturnValueTypeMatch9() : Int { 1.0 } fun blockReturnValueTypeMatch10() : Int { - return if (1 > 2) + return if (1 > 2) 1 } fun blockReturnValueTypeMatch11() : Int { diff --git a/compiler/testData/diagnostics/tests/controlStructures/emptyIf.kt b/compiler/testData/diagnostics/tests/controlStructures/emptyIf.kt index 919ca8d6b3b..bf67e7d5a44 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/emptyIf.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/emptyIf.kt @@ -4,13 +4,13 @@ fun test() { if (false); if (true); - val x = if (false); + val x = if (false); foo(x) - val y: Unit = if (false); + val y: Unit = if (false); foo(y) foo({if (1==1);}()) - return if (true); + return if (true); } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/improperElseInExpression.kt b/compiler/testData/diagnostics/tests/controlStructures/improperElseInExpression.kt new file mode 100644 index 00000000000..f50df7b02d7 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/improperElseInExpression.kt @@ -0,0 +1,33 @@ +// !DIAGNOSTICS: -UNUSED_VARIABLE + +fun example() { + val a = if (true) true else false + val b = if (true) else false + val c = if (true) true + val d = if (true) true else; + val e = if (true) {} else false + val f = if (true) true else {} + + { + if (true) true + }(); + + { + if (true) true else false + }(); + + { + if (true) {} else false + }(); + + + { + if (true) true else {} + }() + + fun t(): Boolean { + return if (true) true + } + + return if (true) true else {} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/improperElseInExpression.txt b/compiler/testData/diagnostics/tests/controlStructures/improperElseInExpression.txt new file mode 100644 index 00000000000..5949b692924 --- /dev/null +++ b/compiler/testData/diagnostics/tests/controlStructures/improperElseInExpression.txt @@ -0,0 +1,3 @@ +package + +public fun example(): kotlin.Unit diff --git a/compiler/testData/diagnostics/tests/controlStructures/kt4310.kt b/compiler/testData/diagnostics/tests/controlStructures/kt4310.kt index f8666c5985c..a66e432c47c 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/kt4310.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/kt4310.kt @@ -7,5 +7,5 @@ fun test(a: Boolean, b: Boolean): Int { if (b) { 3 } - } // no error, but must be + } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/kt770.kt351.kt735_StatementType.kt b/compiler/testData/diagnostics/tests/controlStructures/kt770.kt351.kt735_StatementType.kt index 8b117ebbd33..f4324f58781 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/kt770.kt351.kt735_StatementType.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/kt770.kt351.kt735_StatementType.kt @@ -34,7 +34,7 @@ fun foo() { fun box() : Int { val d = 2 var z = 0 - when(d) { + when(d) { 5, 3 -> z++ else -> z = -1000 } @@ -100,10 +100,10 @@ fun testImplicitCoercion() { else -> z-- } - var iff = if (true) { + var iff = if (true) { z = 34 } - val g = if (true) 4 + val g = if (true) 4 val h = if (false) 4 else {} bar(if (true) { diff --git a/compiler/testData/diagnostics/tests/dataFlow/EmptyIf.kt b/compiler/testData/diagnostics/tests/dataFlow/EmptyIf.kt index 203d46f8e9c..e54c9a7ae6c 100644 --- a/compiler/testData/diagnostics/tests/dataFlow/EmptyIf.kt +++ b/compiler/testData/diagnostics/tests/dataFlow/EmptyIf.kt @@ -18,7 +18,7 @@ fun f3(s: Number?) { } fun f4(s: Int?) { - var u = if (s!! == 42); - if (u == Unit) u = if (s == 239); + var u = if (s!! == 42); + if (u == Unit) u = if (s == 239); return u -} +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElse.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElse.kt index a05c2ba1558..5492702c75d 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElse.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElse.kt @@ -1,7 +1,7 @@ val flag = true // type of a was checked by txt -val a/*: () -> Any*/ = l@ { // commonSupertype(Int, Unit) = Any +val a/*: () -> Any*/ = l@ { if (flag) return@l 4 } diff --git a/compiler/testData/lineNumber/custom/ifThen.kt b/compiler/testData/lineNumber/custom/ifThen.kt index 97edac1faad..ddb3b7c7ae6 100644 --- a/compiler/testData/lineNumber/custom/ifThen.kt +++ b/compiler/testData/lineNumber/custom/ifThen.kt @@ -2,10 +2,6 @@ fun foo() { if (0 < 1) { return } - - val u: Unit = if (0 < 1) { - return - } } -// 2 3 6 7 6 9 +// 2 3 5 diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index e786ce79821..fc5ac6a97cc 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -3258,6 +3258,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("improperElseInExpression.kt") + public void testImproperElseInExpression() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/controlStructures/improperElseInExpression.kt"); + doTest(fileName); + } + @TestMetadata("jumpAcrossFunctionBoundary.kt") public void testJumpAcrossFunctionBoundary() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/controlStructures/jumpAcrossFunctionBoundary.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java index 0a7f761608a..69adc8f5afe 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/generated/BlackBoxCodegenTestGenerated.java @@ -2053,12 +2053,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } - @TestMetadata("emptyIf.kt") - public void testEmptyIf() throws Exception { - String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/emptyIf.kt"); - doTest(fileName); - } - @TestMetadata("emptyWhile.kt") public void testEmptyWhile() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/emptyWhile.kt"); @@ -2149,12 +2143,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } - @TestMetadata("kt2062.kt") - public void testKt2062() throws Exception { - String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/kt2062.kt"); - doTest(fileName); - } - @TestMetadata("kt2147.kt") public void testKt2147() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/kt2147.kt"); @@ -2197,12 +2185,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } - @TestMetadata("kt2598.kt") - public void testKt2598() throws Exception { - String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/kt2598.kt"); - doTest(fileName); - } - @TestMetadata("kt299.kt") public void testKt299() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/kt299.kt"); diff --git a/generators/src/org/jetbrains/kotlin/generators/builtins/generateBuiltIns.kt b/generators/src/org/jetbrains/kotlin/generators/builtins/generateBuiltIns.kt index 6a3a8fa150e..06fca1650b6 100644 --- a/generators/src/org/jetbrains/kotlin/generators/builtins/generateBuiltIns.kt +++ b/generators/src/org/jetbrains/kotlin/generators/builtins/generateBuiltIns.kt @@ -28,8 +28,9 @@ import org.jetbrains.kotlin.generators.builtins.ranges.GenerateRanges import java.io.File import java.io.PrintWriter -fun assertExists(file: File): Unit = - if (!file.exists()) error("Output dir does not exist: ${file.getAbsolutePath()}") +fun assertExists(file: File) { + if (!file.exists()) error("Output dir does not exist: ${file.getAbsolutePath()}") +} val BUILT_INS_NATIVE_DIR = File("core/builtins/native/") val BUILT_INS_SRC_DIR = File("core/builtins/src/") diff --git a/idea/testData/intentions/swapBinaryExpression/is.kt b/idea/testData/intentions/swapBinaryExpression/is.kt index b94334880a8..b10f9235e3b 100644 --- a/idea/testData/intentions/swapBinaryExpression/is.kt +++ b/idea/testData/intentions/swapBinaryExpression/is.kt @@ -1,4 +1,5 @@ // IS_APPLICABLE: false +// ERROR: 'if' must have both main and 'else' branches if used as an expression // ERROR: Expression 'if "test" is String' of type 'kotlin.Unit' cannot be invoked as a function. The function invoke() is not found fun doSomething(a: T) {} diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt index 5aceafc6d9e..6282478f645 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt @@ -320,7 +320,9 @@ public class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR val compilerServices = Services.Builder() .register(javaClass(), IncrementalCompilationComponentsImpl(incrementalCaches, lookupTracker)) .register(javaClass(), object : CompilationCanceledStatus { - override fun checkCanceled(): Unit = if (context.getCancelStatus().isCanceled()) throw CompilationCanceledException() + override fun checkCanceled() { + if (context.getCancelStatus().isCanceled()) throw CompilationCanceledException() + } }) .build() diff --git a/js/js.parser/src/org/jetbrains/kotlin/js/parser/parserUtils.kt b/js/js.parser/src/org/jetbrains/kotlin/js/parser/parserUtils.kt index 2e87039ee68..72206de2fe9 100644 --- a/js/js.parser/src/org/jetbrains/kotlin/js/parser/parserUtils.kt +++ b/js/js.parser/src/org/jetbrains/kotlin/js/parser/parserUtils.kt @@ -42,19 +42,20 @@ public fun parseFunction(code: String, offset: Int, reporter: ErrorReporter, sco private class FunctionParsingObserver : Observer { var functionsStarted = 0 - override fun update(o: Observable?, arg: Any?): Unit = - when (arg) { - is ParserEvents.OnFunctionParsingStart -> { - functionsStarted++ - } - is ParserEvents.OnFunctionParsingEnd -> { - functionsStarted-- + override fun update(o: Observable?, arg: Any?) { + when (arg) { + is ParserEvents.OnFunctionParsingStart -> { + functionsStarted++ + } + is ParserEvents.OnFunctionParsingEnd -> { + functionsStarted-- - if (functionsStarted == 0) { - arg.tokenStream.ungetToken(TokenStream.EOF) - } + if (functionsStarted == 0) { + arg.tokenStream.ungetToken(TokenStream.EOF) } } + } + } } inline diff --git a/js/js.translator/testData/expression/evaluationOrder/cases/orOrWithSideEffect.kt b/js/js.translator/testData/expression/evaluationOrder/cases/orOrWithSideEffect.kt index 6528e3deadd..02596d0706e 100644 --- a/js/js.translator/testData/expression/evaluationOrder/cases/orOrWithSideEffect.kt +++ b/js/js.translator/testData/expression/evaluationOrder/cases/orOrWithSideEffect.kt @@ -8,7 +8,7 @@ fun bar(s: String, value: Boolean): Boolean { } fun box(): String { - val a = if (true || if(bar("A", false)) {2} else {3} == 0) { } + val a = if (true || if(bar("A", false)) {2} else {3} == 0) true else false assertEquals("", global) true || if(bar("A", false)) {2} else {3} == 0