Skip to content

Commit

Permalink
Propagate location to resolution errors
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Feb 12, 2024
1 parent b00dc9e commit 08c4e76
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,11 @@ object Patterns extends IRPass {
val resolvedName = resolution
.map {
case Left(err) =>
errors.Resolution(
val r = errors.Resolution(
consPat.constructor,
errors.Resolution.ResolverError(err)
)
r.setLocation(consPat.location)
case Right(value: BindingsMap.ResolvedConstructor) =>
consName.updateMetadata(
new MetadataPair(this, BindingsMap.Resolution(value))
Expand All @@ -140,12 +141,13 @@ object Patterns extends IRPass {
)

case Right(_: BindingsMap.ResolvedMethod) =>
errors.Resolution(
val r = errors.Resolution(
consName,
errors.Resolution.UnexpectedMethod(
"a pattern match"
)
)
r.setLocation(consName.location)
}
.getOrElse(consName)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.enso.polyglot.RuntimeOptions;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.PolyglotException;
import org.graalvm.polyglot.Source;
import org.graalvm.polyglot.io.IOAccess;
import org.junit.AfterClass;
import org.junit.Before;
Expand Down Expand Up @@ -75,4 +76,34 @@ public void redefinedArgument() throws Exception {
"Identifier recognized in " + errors, -1, errors.indexOf("a is defined multiple times"));
}
}

@Test
public void testUnknownConstructorLocation() throws Exception {
var code =
Source.newBuilder(
"enso",
"""
foo x = case x of
Index_Sub_Range.Sample _ _ -> 1
_ -> 2
""",
"wrong_cons.enso")
.build();
var module = ctx.eval(code);
try {
var run = module.invokeMember("eval_expression", "foo 10");
fail("Expecting no returned value: " + run);
} catch (PolyglotException ex) {
assertEquals("Compilation aborted due to errors.", ex.getMessage());
assertTrue("Syntax error", ex.isSyntaxError());
assertTrue("Guest exception", ex.isGuestException());

var errors = new String(MESSAGES.toByteArray(), StandardCharsets.UTF_8);
assertNotEquals(
"Errors reported in " + errors,
-1,
errors.indexOf("The name `Index_Sub_Range.Sample` could not be found"));
assertNotEquals("Location defined " + errors, -1, errors.indexOf("wrong_cons:2:5"));
}
}
}

0 comments on commit 08c4e76

Please sign in to comment.