mirror of
https://github.com/enso-org/enso.git
synced 2024-11-22 22:10:15 +03:00
Use proper Java class name in error message (#9996)
Better error message when static method cannot be found on a Java class.
This commit is contained in:
parent
643b66d0b7
commit
befd938dbf
@ -422,4 +422,26 @@ public class ExecCompilerTest {
|
||||
assertEquals("Compile error: NO_FIELD is not visible in this scope.", ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertlyIdentifyNameOfJavaClassInError() throws Exception {
|
||||
var module =
|
||||
ctx.eval(
|
||||
"enso",
|
||||
"""
|
||||
from Standard.Base.Errors.Common import all
|
||||
polyglot java import java.lang.Runnable
|
||||
|
||||
run value =
|
||||
Runnable.invoke value
|
||||
""");
|
||||
var run = module.invokeMember(MethodNames.Module.EVAL_EXPRESSION, "run");
|
||||
try {
|
||||
var never = run.execute(-1);
|
||||
fail("Unexpected result: " + never);
|
||||
} catch (PolyglotException ex) {
|
||||
assertEquals(
|
||||
"Method `invoke` of type java.lang.Runnable could not be found.", ex.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package org.enso.interpreter.node.expression.builtin.text;
|
||||
|
||||
import com.oracle.truffle.api.CompilerDirectives;
|
||||
import com.oracle.truffle.api.dsl.Cached;
|
||||
import com.oracle.truffle.api.dsl.Cached.Shared;
|
||||
import com.oracle.truffle.api.dsl.Fallback;
|
||||
import com.oracle.truffle.api.dsl.Specialization;
|
||||
import com.oracle.truffle.api.interop.InteropLibrary;
|
||||
@ -26,15 +27,12 @@ public abstract class AnyToDisplayTextNode extends Node {
|
||||
|
||||
abstract Text execute(Object self);
|
||||
|
||||
@Specialization(guards = {"displays.isException(self)", "displays.hasExceptionMessage(self)"})
|
||||
Text showExceptions(
|
||||
Object self,
|
||||
@CachedLibrary(limit = "3") InteropLibrary strings,
|
||||
@CachedLibrary(limit = "3") InteropLibrary displays) {
|
||||
@Specialization(guards = {"iop.isException(self)", "iop.hasExceptionMessage(self)"})
|
||||
Text showExceptions(Object self, @Shared("iop") @CachedLibrary(limit = "3") InteropLibrary iop) {
|
||||
try {
|
||||
return Text.create(strings.asString(displays.getExceptionMessage(self)));
|
||||
return Text.create(iop.asString(iop.getExceptionMessage(self)));
|
||||
} catch (UnsupportedMessageException e) {
|
||||
throw EnsoContext.get(strings).raiseAssertionPanic(strings, null, e);
|
||||
throw EnsoContext.get(iop).raiseAssertionPanic(iop, null, e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -85,6 +83,16 @@ public abstract class AnyToDisplayTextNode extends Node {
|
||||
return Text.create(self.getName());
|
||||
}
|
||||
|
||||
@Specialization(
|
||||
guards = {"iop.isMetaObject(self)"},
|
||||
rewriteOn = UnsupportedMessageException.class)
|
||||
Text convertMetaObject(Object self, @Shared("iop") @CachedLibrary(limit = "3") InteropLibrary iop)
|
||||
throws UnsupportedMessageException {
|
||||
var maybeName = iop.getMetaQualifiedName(self);
|
||||
var name = iop.asString(maybeName);
|
||||
return Text.create(name);
|
||||
}
|
||||
|
||||
@CompilerDirectives.TruffleBoundary
|
||||
private static Text takePrefix(Text self, final int limit) {
|
||||
var prefix = Core_Text_Utils.take_prefix(self.toString(), limit - 2);
|
||||
|
Loading…
Reference in New Issue
Block a user