mirror of
https://github.com/enso-org/enso.git
synced 2024-12-23 14:52:01 +03:00
Treat null Tree.OprApp.getRhs() as UnexpectedExpression syntax error (#3882)
Fixes `NullPointerException` in `TreeToIr` by detecting the case and raising `UnexpectedExpression` syntax error. # Important Notes This PR prevents the `NullPointerException`. It doesn't change the meaning of `x.` (followed by space) `length`. It just detects when `Tree.OprApp.getRhs() == null` and treats that as an error.
This commit is contained in:
parent
3d6f2b04f3
commit
79329ef00f
@ -550,7 +550,14 @@ final class TreeToIr {
|
||||
yield switch (op.codeRepr()) {
|
||||
case "." -> {
|
||||
final Option<IdentifiedLocation> loc = getIdentifiedLocation(tree);
|
||||
yield buildQualifiedName(app, loc, false);
|
||||
try {
|
||||
yield buildQualifiedName(app, loc, false);
|
||||
} catch (UnhandledEntity ex) {
|
||||
if (ex.entity() instanceof IR.Expression expr) {
|
||||
yield expr;
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
case "->" -> {
|
||||
@ -1161,7 +1168,12 @@ final class TreeToIr {
|
||||
if (app.getOpr().getRight() == null || !operator.equals(app.getOpr().getRight().codeRepr())) {
|
||||
break;
|
||||
}
|
||||
segments.add(app.getRhs());
|
||||
if (app.getRhs() != null) {
|
||||
segments.add(app.getRhs());
|
||||
} else {
|
||||
var ir = translateSyntaxError(app, IR$Error$Syntax$UnexpectedExpression$.MODULE$);
|
||||
throw new UnhandledEntity(ir, "unrollOprRhs");
|
||||
}
|
||||
list = app.getLhs();
|
||||
}
|
||||
segments.add(list);
|
||||
|
@ -326,6 +326,19 @@ public class ErrorCompilerTest {
|
||||
assertSingleSyntaxError(ir, IR$Error$Syntax$InvalidEscapeSequence$.MODULE$.apply("wrong sequence"), "Invalid escape sequence wrong sequence.", 9, 28);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNPE183814303() throws Exception {
|
||||
var ir = parseTest("""
|
||||
from Standard.Base import all
|
||||
|
||||
main =
|
||||
x = "foo"
|
||||
z = x. length
|
||||
IO.println z
|
||||
""");
|
||||
assertSingleSyntaxError(ir, IR$Error$Syntax$UnexpectedExpression$.MODULE$, "Unexpected expression.", 60, 62);
|
||||
}
|
||||
|
||||
private void assertSingleSyntaxError(
|
||||
IR.Module ir, IR$Error$Syntax$Reason type,
|
||||
String msg, int start, int end
|
||||
|
Loading…
Reference in New Issue
Block a user