Skip to content

Commit

Permalink
More detailed No_Such_Method error message for function like objects (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach authored Jun 25, 2024
1 parent 8fba4b7 commit 0cde0e7
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion distribution/lib/Standard/Base/0.0.0-dev/src/Meta.enso
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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;
Expand Down Expand Up @@ -111,7 +112,12 @@ public void testDesugarOperatorsRightLeft() throws Exception {
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.")));
}
}

Expand Down
48 changes: 48 additions & 0 deletions test/Base_Tests/src/Data/Function_Spec.enso
Original file line number Diff line number Diff line change
@@ -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->
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0cde0e7

Please sign in to comment.