Skip to content

Commit

Permalink
Fix the type of Type_Error's name field (#1504)
Browse files Browse the repository at this point in the history
  • Loading branch information
kustosz authored Feb 24, 2021
1 parent 7aba8ff commit 299c598
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ static NotInvokableErrorToDisplayTextNode build() {
@Specialization
Text doAtom(Atom _this, @Cached TypeToDisplayTextNode displayTypeNode) {
return Text.create("Type error: expected a function, but got ")
.add(displayTypeNode.execute(_this.getFields()[0]));
.add(displayTypeNode.execute(_this.getFields()[0]))
.add(".");
}

@Specialization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ static TypeErrorToDisplayTextNode build() {
@Specialization
Text doAtom(Atom _this, @Cached TypeToDisplayTextNode displayTypeNode) {
try {
return Text.create("Type error: expected ")
return Text.create("Type error: expected `")
.add(TypesGen.expectText(_this.getFields()[2]))
.add(" to be ")
.add("` to be ")
.add(displayTypeNode.execute(_this.getFields()[0]))
.add(", but got ")
.add(displayTypeNode.execute(_this.getFields()[1]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public Error(Language language, ModuleScope scope) {
.initializeFields(
new ArgumentDefinition(0, "name", ArgumentDefinition.ExecutionMode.EXECUTE));
notInvokableError =
new AtomConstructor("Not_Invokable", scope)
new AtomConstructor("Not_Invokable_Error", scope)
.initializeFields(
new ArgumentDefinition(0, "target", ArgumentDefinition.ExecutionMode.EXECUTE));

Expand Down Expand Up @@ -155,6 +155,11 @@ public Error(Language language, ModuleScope scope) {
unsupportedArgumentsError,
"to_display_text",
UnsupportedArgumentTypesToDisplayTextMethodGen.makeFunction(language));
scope.registerConstructor(notInvokableError);
scope.registerMethod(
notInvokableError,
"to_display_text",
NotInvokableErrorToDisplayTextMethodGen.makeFunction(language));
}

/** @return the builtin {@code Syntax_Error} atom constructor. */
Expand Down Expand Up @@ -207,7 +212,7 @@ public Atom makeNoSuchMethodError(Object target, UnresolvedSymbol symbol) {
* @return a runtime representation of the error.
*/
public Atom makeTypeError(Object expected, Object actual, String name) {
return typeError.newInstance(expected, actual, name);
return typeError.newInstance(expected, actual, Text.create(name));
}

/**
Expand Down
8 changes: 8 additions & 0 deletions engine/runtime/src/main/resources/Builtins.enso
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,14 @@ type Arithmetic_Error message
@Builtin_Type
type Invalid_Array_Index_Error array index

## An error that occurs when an object is used as a function in a function
call, but it cannot be called.

Arguments:
- target: The called object.
@Builtin_Type
type Not_Invokable_Error target

## Panics.
type Panic

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3001,7 +3001,7 @@ class RuntimeServerTest
contextId,
Seq(
Api.ExecutionResult.Diagnostic.error(
"Not_Invokable 42",
"Not_Invokable_Error 42",
Some(mainFile),
Some(model.Range(model.Position(0, 7), model.Position(0, 24))),
None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,20 @@ class TextTest extends InterpreterTest {
| IO.println (Compile_Error "error :(").to_display_text
| IO.println (Inexhaustive_Pattern_Match_Error 32).to_display_text
| IO.println (Arithmetic_Error "cannot frobnicate quaternions").to_display_text
| IO.println ((Panic.recover (1 + "foo")).catch_primitive .to_display_text)
| IO.println ((Panic.recover (7 1)).catch_primitive .to_display_text)
| IO.println (Arity_Error 10 20).to_display_text
|""".stripMargin
eval(code)
consumeOut shouldEqual List(
"Cons",
"Syntax error: foo",
"Type error: expected myvar to be Nothing, but got Text.",
"Type error: expected `myvar` to be Nothing, but got Text.",
"Compile error: error :(",
"Inexhaustive pattern match: no branch matches 32 (Integer).",
"Arithmetic error: cannot frobnicate quaternions",
"Type error: expected `that` to be Number, but got Text.",
"Type error: expected a function, but got 7 (Integer).",
"Wrong number of arguments. Expected 10, but got 20."
)
}
Expand Down

0 comments on commit 299c598

Please sign in to comment.