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

Better error messages in tupleassign #134

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ForgottenGensym
Copy link

@ForgottenGensym ForgottenGensym commented May 31, 2021

Right now, if a user passes the wrong number of arguments, one of two things can happen:

  1. Too few arguments provided: a somewhat confusing BoundsError without context.
  2. Too many arguments provided: the remaining ones will be ignored, which can cause a ton of subtle issues.

This is what I came up with:

  1. In addition to showing the BoundsError, it also gives the error below.
"""
@rec: [tupleassign] Wrong number of arguments passed in tail-recursive calls
    (Tuple8...) = (Tuple7...)
    (a, b, c, d, e, f, g, h) = (1, 2, 3, 4, 5, 6, 7)
"""
  1. I didn't want to break backwards compatibility, because some people might actually use this feature. This will still work, but it will give a (hopefully) helpful warning explaining what is going on and that this is probably a bad idea.
@warn """
@rec: [tupleassign] Extra arguments passed in recursive calls will be ignored
  > `Lazy.@rec` keeps track of arguments in a tuple, and your recursive
  > call passed extra arguments to the function. This will result (after
  > macro expansion) in a snippet like `(arg1, arg2) = (rec1, rec2, rec3)`
  > Julia allows you to do this (`rec3` will be ignored), but in this case
  > it is most likely a mistake.
"""

It took me forever to figure out what was going on when I made this mistake, and so hopefully this can help out.

Note: The warning bit does require the Logging dependency:

import Logging.@warn

@ForgottenGensym ForgottenGensym marked this pull request as ready for review May 31, 2021 17:10
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