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

Misleading error message for overloaded function arity #520

Closed
nex3 opened this issue Nov 7, 2018 · 7 comments · Fixed by #883
Closed

Misleading error message for overloaded function arity #520

nex3 opened this issue Nov 7, 2018 · 7 comments · Fixed by #883

Comments

@nex3
Copy link
Contributor

nex3 commented Nov 7, 2018

When the wrong number of arguments are passed to a function with overloads, Dart Sass's error message sometimes claims that the function accepts fewer arguments than it actually does. For example:

$ sass --interactive
>> hsla(1, 2, 3, 4, 5)
   ^^^^^^^^^^^^^^^^^^^
Error: Only 1 argument allowed, but 5 were passed.

hsla() allows up to 4 arguments, so this error message is confusing and incorrect.

@DreamSpinner22
Copy link

Hey, @nex3, has this one been solved yet? I'd like to work on it, if possible. I may need some direction in doing so. Mainly, just where to find the code in the files. I see multiple color.dart files in different directories. Can you help out with this?

Thanks!

@nex3
Copy link
Contributor Author

nex3 commented Oct 18, 2019

This is still up for grabs! I think you actually want to look at _AsyncEvaluator._runBuiltInCallable() or maybe ArgumentDeclaration.verify()—the problem is that there are multiple possible overloads of the function with different numbers of arguments, and we should be throwing an error for the one with the most arguments.

@Awjin
Copy link
Contributor

Awjin commented Nov 14, 2019

How do we know which overloaded function to use for argument validity?

Currently with 4 args, hsla gets overloaded as hsla(hue, saturation, lightness, alpha).
But with 1 arg it becomes hsla(channels).

If we use hsla(hue, saturation, lightness, alpha) we would get the desired error,

>> hsla(1, 2, 3, 4, 5)
   ^^^^^^^^^^^^^^^^^^^
Error: Only 4 arguments allowed, but 5 were passed.

but we would also get the undesired

>> hsla()
   ^^^^^^^^^^^^^^^^^^^
Error: Missing argument $hue.  // Should be "Error: Missing argument $channels"

@nex3
Copy link
Contributor Author

nex3 commented Nov 14, 2019

That's kind of the core question here, and it may come down to finding a heuristic that best matches the failure cases we know of. I think a good starting point is choosing the overload that's closest to the number of (positional?) arguments that were actually passed.

@Awjin
Copy link
Contributor

Awjin commented Nov 14, 2019

@DreamSpinner22 Would you mind if I worked on this?

@DreamSpinner22
Copy link

@Awjin I do not mind you working on this. I haven't had much spare time to work on this, unfortunately. If you do figure it out before me, please let me know how because I'm still new to Dart and want to learn as much as possible.

Awjin added a commit to sass/sass-spec that referenced this issue Nov 14, 2019
Awjin added a commit that referenced this issue Nov 14, 2019
When overloaded functions receive an incorrect number of positional
arguments, determine which overload has the most similar number of
arguments, and then correctly display that number in the error.

Closes #520
sass/sass-spec#1496
Awjin added a commit that referenced this issue Nov 14, 2019
When overloaded functions receive an incorrect number of positional
arguments, determine which overload has the most similar number of
arguments, and then correctly display that number in the error.

Closes #520
sass/sass-spec#1496
Awjin added a commit to sass/sass-spec that referenced this issue Nov 15, 2019
Awjin added a commit that referenced this issue Nov 15, 2019
When overloaded functions receive an incorrect number of positional
arguments, determine which overload has the most similar number of
arguments, and then correctly display that number in the error.

Closes #520
sass/sass-spec#1496
@Awjin
Copy link
Contributor

Awjin commented Nov 18, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants