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

Improve errors for calls with unexpected arguments #350

Merged
merged 8 commits into from
Aug 14, 2024

Conversation

irh
Copy link
Contributor

@irh irh commented Aug 14, 2024

Following on from #345 and #347, this PR improves error messages when Koto functions are called with unexpected arguments.

The aim here is to introduce a standard format for error messages that reduces ambiguity regardless of how the function was called (as an instance method or as a standalone function), or in how the arguments are incorrect (correct instance but missing args, superfluous args, etc).

For example, before:

» number.max 1
error: Expected 'two Numbers', but found 'no args'
--- 1:8
   |
 1 | number.max 1
   |        ^^^

» [1, 2, 3].reverse 'hello'
error: Expected 'a List', but found 'String'
--- 1:11
   |
 1 | [1, 2, 3].reverse 'hello'
   |           ^^^^^^^

...and after:

error: Unexpected arguments.
  Expected: |Number, Number|
  Provided: |Number|
--- 1:8
   |
 1 | number.max 1
   |        ^^^

» [1, 2, 3].reverse 'hello'
error: Unexpected arguments.
  Expected: |List|
  Provided: |List, String|
--- 1:11
   |
 1 | [1, 2, 3].reverse 'hello'
   |           ^^^^^^^

@irh irh force-pushed the better-errors-for-unexpected-args branch from 0fe94c2 to b2c9f1e Compare August 14, 2024 09:16
@irh irh merged commit b042d25 into main Aug 14, 2024
8 checks passed
@irh irh deleted the better-errors-for-unexpected-args branch August 14, 2024 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant