-
-
Notifications
You must be signed in to change notification settings - Fork 46
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
Check for excess generic arguments #160
Conversation
Awesome, thanks for the addition! Tests are great and passing. The final part is adding a position to the new error. You should be able to create a range for the excess type parameter diagnostic using Span::union in something like: let first_excess_type_parameter = &call_site_type_arguments[expected_parameters_length];
let last_excess_type_parameter = call_site_type_arguments.last();
let error_position = first_excess_type_parameter.1.union(&last_excess_type_parameter.1); Then in diagnostics you can change the TypeCheckError => Diagnostic to build a Diagnostic::Position After that change it will be good to merge! Another two to the test count! |
Thank you for the guidance! I was wracking my brain trying to figure out how to get the position info lmao. |
Do you think it would make sense to have a specific error type for when the function isn't generic in the first place? |
I wondered about that. I checked and TSC doesn't actually have a specific error for that. I think that would be a good idea if it is not too hard to add! Also in the other diagnostic could the count be printed (it is being calculated but not put in the diagnostic). So "n excess type arguments". After that good to merge! |
Would you prefer to match closer to what tsc does? e.g.
|
not sure 😅 I like "n excess ..." as it is cleaner. But maybe the expected count would be helpful? Up to you :) |
Haha it's your project, it's your call :) I personally feel like knowing how many types the function could accept would be helpful so I don't need to do that math in my head. I'm also inclined to say that using BUT I do it could be useful to have distinct errors for each and the non-generic function case could still benefit from having a specific message (though the message could also technically be inferred by the count fields too, to limit the match clauses required since it is technically the same problem) 🤔 |
Okay I updated it to do both and conditionally use a more specific error message when the function is not generic. If you're not a fan, I'm happy to pull that back out and simplify it either direction. |
Have made a quick tweak to avoid |
Closes #149