From a6e98c30d772550e4ac39bb050e1612de258ab2e Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Mon, 23 Oct 2017 16:07:26 +0300 Subject: [PATCH] JS: fix crash when `js` function contains assignment with bad LHS Fix KT-20905 --- .../diagnostics/testsWithJsStdLib/jsCode/badAssignment.kt | 4 ++++ .../testsWithJsStdLib/jsCode/badAssignment.txt | 3 +++ .../checkers/DiagnosticsTestWithJsStdLibGenerated.java | 6 ++++++ .../src/com/google/gwt/dev/js/rhino/IRFactory.java | 8 +------- 4 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 compiler/testData/diagnostics/testsWithJsStdLib/jsCode/badAssignment.kt create mode 100644 compiler/testData/diagnostics/testsWithJsStdLib/jsCode/badAssignment.txt diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/jsCode/badAssignment.kt b/compiler/testData/diagnostics/testsWithJsStdLib/jsCode/badAssignment.kt new file mode 100644 index 00000000000..5bcc2563c3d --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/jsCode/badAssignment.kt @@ -0,0 +1,4 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER +fun Int.foo(x: Int) { + js("this = x;") +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/jsCode/badAssignment.txt b/compiler/testData/diagnostics/testsWithJsStdLib/jsCode/badAssignment.txt new file mode 100644 index 00000000000..ab9bbc52dd6 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithJsStdLib/jsCode/badAssignment.txt @@ -0,0 +1,3 @@ +package + +public fun kotlin.Int.foo(/*0*/ x: kotlin.Int): kotlin.Unit diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java index 533112b4840..66704460283 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithJsStdLibGenerated.java @@ -374,6 +374,12 @@ public class DiagnosticsTestWithJsStdLibGenerated extends AbstractDiagnosticsTes doTest(fileName); } + @TestMetadata("badAssignment.kt") + public void testBadAssignment() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/jsCode/badAssignment.kt"); + doTest(fileName); + } + @TestMetadata("deleteOperation.kt") public void testDeleteOperation() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/jsCode/deleteOperation.kt"); diff --git a/js/js.parser/src/com/google/gwt/dev/js/rhino/IRFactory.java b/js/js.parser/src/com/google/gwt/dev/js/rhino/IRFactory.java index 32b66fda0fb..1ab1de0aff1 100644 --- a/js/js.parser/src/com/google/gwt/dev/js/rhino/IRFactory.java +++ b/js/js.parser/src/com/google/gwt/dev/js/rhino/IRFactory.java @@ -341,18 +341,12 @@ public class IRFactory { default: // TODO: This should be a ReferenceError--but that's a runtime // exception. Should we compile an exception into the code? - reportError("msg.bad.lhs.assign"); + ts.reportSyntaxError("msg.bad.lhs.assign", null); } return new Node(TokenStream.ASSIGN, left, right, nodeOp, location); } - private void reportError(String msgResource) { - - String message = Context.getMessage0(msgResource); - ts.reportSyntaxError(message, null); - } - // Only needed to get file/line information. Could create an interface // that TokenStream implements if we want to make the connection less // direct.