JS: fix crash when js function contains assignment with bad LHS

Fix KT-20905
This commit is contained in:
Alexey Andreev
2017-10-23 16:07:26 +03:00
parent a11cf253df
commit a6e98c30d7
4 changed files with 14 additions and 7 deletions
@@ -0,0 +1,4 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
fun Int.foo(x: Int) {
js("this = x<!JSCODE_ERROR!><!>;")
}
@@ -0,0 +1,3 @@
package
public fun kotlin.Int.foo(/*0*/ x: kotlin.Int): kotlin.Unit
@@ -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");
@@ -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.