diff --git a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/Patterns.scala b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/Patterns.scala index 8c4d55806cf7..72e242db9c2c 100644 --- a/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/Patterns.scala +++ b/engine/runtime-compiler/src/main/scala/org/enso/compiler/pass/resolve/Patterns.scala @@ -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)) @@ -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) diff --git a/engine/runtime/src/test/java/org/enso/compiler/ExecStrictCompilerTest.java b/engine/runtime/src/test/java/org/enso/compiler/ExecStrictCompilerTest.java index 0b90ba1bada6..5189b1f50047 100644 --- a/engine/runtime/src/test/java/org/enso/compiler/ExecStrictCompilerTest.java +++ b/engine/runtime/src/test/java/org/enso/compiler/ExecStrictCompilerTest.java @@ -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; @@ -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")); + } + } }