Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propagate location to resolution errors #9025

Merged
merged 1 commit into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"));
}
}
}
Loading