-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ClassCastException when builtin is invoked with wrong args (#12033)
* Add failing test * Error.catch_primitive throws type error on wrong self arg * Move Error.catch_primitive to a private internal module * error message contains just single string
- Loading branch information
Showing
4 changed files
with
79 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
distribution/lib/Standard/Base/0.0.0-dev/src/Internal/Error_Builtins.enso
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
private | ||
|
||
import project.Any.Any | ||
import project.Error.Error | ||
|
||
## PRIVATE | ||
|
||
Executes the provided handler on a dataflow error, or executes as | ||
identity on a non-error value. | ||
|
||
Arguments: | ||
- handler: The function to call on this if it is an error value. | ||
Error.catch_primitive : (Error -> Any) -> Any | ||
Error.catch_primitive self handler = @Builtin_Method "Error.catch_primitive" |
44 changes: 44 additions & 0 deletions
44
...ration-tests/src/test/java/org/enso/interpreter/test/builtins/BuiltinsInvocationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.enso.interpreter.test.builtins; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.containsString; | ||
|
||
import org.enso.test.utils.ContextUtils; | ||
import org.graalvm.polyglot.Context; | ||
import org.graalvm.polyglot.PolyglotException; | ||
import org.junit.AfterClass; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
|
||
public class BuiltinsInvocationTest { | ||
private static Context ctx; | ||
|
||
@BeforeClass | ||
public static void prepareCtx() { | ||
ctx = ContextUtils.createDefaultContext(); | ||
} | ||
|
||
@AfterClass | ||
public static void disposeCtx() { | ||
ctx.close(); | ||
ctx = null; | ||
} | ||
|
||
@Test | ||
public void invokeBuiltinWithWrongArguments_ShouldNotCrash() { | ||
var src = | ||
""" | ||
from Standard.Base import all | ||
main = | ||
(Error.catch_primitive self=(y->y)) (x->x) | ||
"""; | ||
try { | ||
ContextUtils.evalModule(ctx, src); | ||
} catch (PolyglotException e) { | ||
var panic = e.getGuestObject(); | ||
assertThat("Should be panic", panic.isException()); | ||
assertThat("Should have Type error as payload", e.getMessage(), containsString("Type error")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters