More detailed No_Such_Method error message for function like objects (#10328)

This commit is contained in:
Jaroslav Tulach 2024-06-25 11:36:56 +02:00 committed by GitHub
parent 8fba4b7f23
commit 0cde0e7f96
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 63 additions and 4 deletions

View File

@ -197,8 +197,13 @@ type No_Such_Method
Convert the No_Such_Method error to a human-readable format.
to_display_text : Text
to_display_text self =
target_type_name = if Meta.is_polyglot self.target then self.target.to_display_text else (Meta.type_of self.target).to_display_text
"Method `"+self.method_name+"` of type "+target_type_name+" could not be found."
target_name =
is_poly = Meta.is_polyglot self.target
is_fn = Meta.type_of self.target == Function
if is_poly then "type " + self.target.to_display_text else
if is_fn then self.target.to_text else
"type " + (Meta.type_of self.target).to_display_text
"Method `"+self.method_name+"` of "+target_name+" could not be found."
@Builtin_Type
type No_Such_Field

View File

@ -336,7 +336,7 @@ get_polyglot_language value = @Builtin_Method "Meta.get_polyglot_language"
## PRIVATE
Creates an unresolved symbol for the name name in the scope.
Creates an unresolved symbol for the name in the scope.
Arguments:
- name: The name of the unresolved symbol.

View File

@ -21,6 +21,7 @@ import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.PolyglotException;
import org.graalvm.polyglot.Source;
import org.graalvm.polyglot.io.IOAccess;
import org.hamcrest.core.AllOf;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Ignore;
@ -111,7 +112,12 @@ public class ExecCompilerTest {
var run = module.invokeMember("eval_expression", "main");
fail("Unexpected result: " + run);
} catch (PolyglotException ex) {
assertEquals("Method `+` of type Function could not be found.", ex.getMessage());
assertThat(
ex.getMessage(),
AllOf.allOf(
containsString("Method `+` of"),
containsString("Unnamed.main.Unnamed.main"),
containsString("could not be found.")));
}
}

View File

@ -1,7 +1,21 @@
from Standard.Base import all
import Standard.Base.Errors.Common.No_Such_Method
from Standard.Test import all
type Abeceda
private A
private B
private C
sample self = case self of
Abeceda.A -> 'astronaut'
Abeceda.B -> 'bicycle'
Abeceda.C -> 'center'
as x converge:Boolean =
t = if converge then (x : Abeceda) else x
t.sample
add_specs suite_builder =
suite_builder.group "identity" group_builder->
@ -38,6 +52,40 @@ add_specs suite_builder =
times = uncurry (*)
times [6, 7] . should_equal 42
suite_builder.group "No_Such_Method" group_builder->
group_builder.specify "conversion of ..B" <|
Abeceda.as ..B True . should_equal "bicycle"
group_builder.specify "no conversion of ..B" <|
p = Panic.recover No_Such_Method <|
Abeceda.as ..B False
p . should_fail_with No_Such_Method
p.to_display_text . should_contain "Method `sample`"
p.to_display_text . should_contain "of ..B"
p.to_display_text . should_contain "not be found"
group_builder.specify "no conversion of Integer value" <|
p = Panic.recover No_Such_Method <|
Abeceda.as 10 False
p . should_fail_with No_Such_Method
p.to_display_text . should_contain "Method `sample`"
p.to_display_text . should_contain "of type Integer"
p.to_display_text . should_contain "not be found"
group_builder.specify "no conversion of function value" <|
p = Panic.recover No_Such_Method <|
Abeceda.as add_specs False
p . should_fail_with No_Such_Method
p.to_display_text . should_contain "Method `sample`"
p.to_display_text . should_contain "of Function_Spec.add_specs"
p.to_display_text . should_contain "[Function_Spec.enso:"
p.to_display_text . should_contain "self=Function_Spec"
p.to_display_text . should_contain "suite_builder=_"
p.to_display_text . should_contain "not be found"
main filter=Nothing =
suite = Test.build suite_builder->
add_specs suite_builder