Avoid NPE on missing @anno name (#11224)

This commit is contained in:
Jaroslav Tulach 2024-10-02 11:15:41 +02:00 committed by GitHub
parent a23b66925d
commit 837a4d53b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 4 deletions

View File

@ -24,6 +24,17 @@ public class ErrorCompilerTest extends CompilerTests {
ir, Syntax.UnclosedTextLiteral$.MODULE$, "Unclosed text literal", 6, 28);
}
@Test
public void brokenAnnotation() throws Exception {
var ir = parse("""
@anno
fn = 10
""");
assertSingleSyntaxError(
ir, Syntax.UnexpectedExpression$.MODULE$, "Unexpected expression", 0, 13);
}
@Test
public void dotUnderscore() throws Exception {
var ir = parse("""

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Map;
import java.util.UUID;
import org.enso.compiler.core.ir.CallArgument;
import org.enso.compiler.core.ir.DefinitionArgument;
import org.enso.compiler.core.ir.Diagnostic;
@ -42,6 +43,7 @@ import org.enso.syntax2.Token;
import org.enso.syntax2.Tree;
import org.enso.syntax2.Tree.Invalid;
import org.enso.syntax2.Tree.Private;
import scala.Option;
import scala.collection.immutable.LinearSeq;
import scala.collection.immutable.List;
@ -318,10 +320,14 @@ final class TreeToIr {
}
case Tree.Annotated anno -> {
var annotationArgument = translateExpression(anno.getArgument());
var annotation = new Name.GenericAnnotation(anno.getAnnotation().codeRepr(),
annotationArgument, getIdentifiedLocation(anno), meta());
yield translateModuleSymbol(anno.getExpression(), join(annotation, appendTo));
if (anno.getArgument() == null) {
yield join(translateSyntaxError(anno, Syntax.UnexpectedExpression$.MODULE$), appendTo);
} else {
var annotationArgument = translateExpression(anno.getArgument());
var annotation = new Name.GenericAnnotation(anno.getAnnotation().codeRepr(),
annotationArgument, getIdentifiedLocation(anno), meta());
yield translateModuleSymbol(anno.getExpression(), join(annotation, appendTo));
}
}
case Tree.Documented doc -> {