Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw panic on "no currying for conversions" #6940

Merged
merged 3 commits into from
Jun 5, 2023

Conversation

hubertp
Copy link
Collaborator

@hubertp hubertp commented Jun 2, 2023

Pull Request Description

Previously, a RuntimeException would be thrown when an attempt would be made to curry a conversion function. That is problematic for IDE where executionFailed means we can't enter functions due to lack of method pointers info.

Closes #6897.

Screenshot from 2023-06-02 20-31-03

Important Notes

A more generic solution that allows to recover from execution failures will need a follow up.

Checklist

Please ensure that the following checklist has been satisfied before submitting the PR:

  • Screenshots/screencasts have been attached, if there are any visual changes. For interactive or animated visual changes, a screencast is preferred.
  • All code follows the
    Scala,
    Java,
    and
    Rust
    style guides. In case you are using a language not listed above, follow the Rust style guide.
  • All code has been tested:
    • Unit tests have been written where possible.
    • If GUI codebase was changed, the GUI was tested when built using ./run ide build.

Previously, a `RuntimeException` would be thrown when an attempt would be
made to curry a conversion function. That is problematic for IDE where
`executionFailed` means we can't enter functions due to lack of method
pointers info.

A more generic solution that allows to recover from execution failures
will need a follow up.

Closes #6897.
Copy link
Contributor

@4e6 4e6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

throw new RuntimeException(
"Conversion currying without `this` or `that` argument is not supported.");
var ctx = EnsoContext.get(this);
throw new PanicException(ctx.getBuiltins().error().makeNoConversionCurrying(canApplyThis, canApplyThat, conversion), this);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RuntimeException is completely inappropriate for reporting errors in user code. Throwing PanicException is certainly more desirable for such situations.

Copy link
Member

@JaroslavTulach JaroslavTulach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoiding RuntimeException is good. Some TCAs inline...

@@ -112,4 +112,7 @@ spec =
meta_from.rename "foo" 123 . should_equal "foo called"
meta_from.rename "foo" . should_equal .foo

Test.specify "should not allow currying" <|
Panic.recover Any (Foo.from) . catch Any .to_display_text . should_equal "Conversion currying without `that` argument is not supported."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't should_fail_with be better suited for the test? Or do you want the test to pass even when no exception happen?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wanted to test the actual message. But checking the error is sufficient, I guess.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't should_fail_with be better suited for the test?

Actually that won't work with Panics.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would appreciate if we do test the message.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should_fail_with will work if you first do Panic.recover - recover will convert the Panic into dataflow error and then should_fail_with can handle it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And using catch you can then check the error message. Like this:

Suggested change
Panic.recover Any (Foo.from) . catch Any .to_display_text . should_equal "Conversion currying without `that` argument is not supported."
r = Panic.recover Any (Foo.from)
r.should_fail_with No_Conversion_Currying
r.catch . to_display_text . should_equal "Conversion currying without `that` argument is not supported."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, you can use Test.expect_panic_with directly - this is a function meant for testing panics. But it won't allow you to check the error message and I think checking it is good - we had lots of places where to_display_text would crash because of typos and that went undetected only until the IDE was unable to display error properly. We want to go in the direction of having to_display_text of every error unit tested to ensure no regressions of error display can get into the IDE.

@hubertp hubertp added CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge labels Jun 5, 2023
@mergify mergify bot merged commit e9a92a1 into develop Jun 5, 2023
@mergify mergify bot deleted the wip/hubert/6897-no-conversion-currying branch June 5, 2023 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI: No changelog needed Do not require a changelog entry for this PR. CI: Ready to merge This PR is eligible for automatic merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot enter collapsed function that failed the execution
6 participants