-
Notifications
You must be signed in to change notification settings - Fork 181
Update error span for call argument type mismatch #3287
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
Draft
amcasey
wants to merge
10
commits into
main
Choose a base branch
from
amcasey/ErrorSpan
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b78d529
Update error span for call argument type mismatch
amcasey bab1ea6
Rename input_expr to input
amcasey dc1531d
Rename some variables for clarity
amcasey 76b5a95
Handle single tuple argument
amcasey ad06aea
Fix wasm test
amcasey 6737375
Clean up diff
amcasey 7789feb
Add more tests
amcasey 4fb95cc
Associate a span with tuple args too
amcasey 94b6bce
Remove unused parameter
amcasey 0ecbb60
Update baselines
amcasey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -308,69 +308,67 @@ impl TySource { | |
| #[derive(Clone, Debug)] | ||
| pub(super) enum ArgTy { | ||
| /// A missing argument, indicating partial application. | ||
| Hole(Ty), | ||
| Hole(Ty, Span), | ||
| /// A given argument. | ||
| Given(Ty), | ||
| Given(Ty, Span), | ||
| /// A list of arguments. This corresponds literally to tuple syntax, not to any expression of a tuple type. | ||
| Tuple(Vec<ArgTy>), | ||
| Tuple(Vec<ArgTy>, Span), | ||
| } | ||
|
|
||
| impl ArgTy { | ||
| /// Applies a function `f` to each type in the argument type. | ||
| fn map(self, f: &mut impl FnMut(Ty) -> Ty) -> Self { | ||
| match self { | ||
| Self::Hole(ty) => Self::Hole(f(ty)), | ||
| Self::Given(ty) => Self::Given(f(ty)), | ||
| Self::Tuple(items) => Self::Tuple(items.into_iter().map(|i| i.map(f)).collect()), | ||
| Self::Hole(ty, span) => Self::Hole(f(ty), span), | ||
| Self::Given(ty, span) => Self::Given(f(ty), span), | ||
| Self::Tuple(items, span) => { | ||
| Self::Tuple(items.into_iter().map(|i| i.map(f)).collect(), span) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Applies the argument type to a parameter type, generating constraints and errors. | ||
| fn apply(&self, param: &Ty, span: Span) -> App { | ||
| fn apply(&self, param: &Ty) -> App { | ||
| match (self, param) { | ||
| // If `arg` is a hole, then it doesn't matter what the param is, | ||
| // because the hole can be anything. | ||
| // However, we do know that the type of Arg must be Eq to the type of Param, so we | ||
| // add that to the constraints. | ||
| // Preserve the hole. | ||
| (Self::Hole(arg), _) => App { | ||
| (Self::Hole(arg, arg_span), _) => App { | ||
| holes: vec![param.clone()], | ||
| constraints: vec![Constraint::Eq { | ||
| expected: param.clone(), | ||
| actual: arg.clone(), | ||
| span, | ||
| span: *arg_span, | ||
| }], | ||
| errors: Vec::new(), | ||
| }, | ||
| // If `arg` is a hole, then it doesn't matter what the param is, | ||
| // because the hole can be anything. | ||
| // However, we do know that the type of Arg must be Eq to the type of Param, so we | ||
| // add that to the constraints. | ||
| (Self::Given(arg), _) => App { | ||
| (Self::Given(arg, arg_span), _) => App { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think a |
||
| holes: Vec::new(), | ||
| constraints: vec![Constraint::Eq { | ||
| expected: param.clone(), | ||
| actual: arg.clone(), | ||
| span, | ||
| span: *arg_span, | ||
| }], | ||
| errors: Vec::new(), | ||
| }, | ||
| // if both the arg and the param are tuples, then we must check | ||
| // the types of each element in the tuple and generate iterative applications. | ||
| (Self::Tuple(args), Ty::Tuple(params)) => { | ||
| (Self::Tuple(args, tuple_span), Ty::Tuple(params)) => { | ||
| let mut errors = Vec::new(); | ||
| if args.len() != params.len() { | ||
| errors.push(Error(ErrorKind::TyMismatch( | ||
| Ty::Tuple(params.clone()).display(), | ||
| self.to_ty().display(), | ||
| span, | ||
| *tuple_span, | ||
| ))); | ||
| } | ||
|
|
||
| let mut holes = Vec::new(); | ||
| let mut constraints = Vec::new(); | ||
| for (arg, param) in args.iter().zip(params) { | ||
| let mut app = arg.apply(param, span); | ||
| let mut app = arg.apply(param); | ||
| constraints.append(&mut app.constraints); | ||
| errors.append(&mut app.errors); | ||
| if app.holes.len() > 1 { | ||
|
|
@@ -387,31 +385,31 @@ impl ArgTy { | |
| } | ||
| } | ||
|
|
||
| (Self::Tuple(_), Ty::Infer(_)) => App { | ||
| (Self::Tuple(_, tuple_span), Ty::Infer(_)) => App { | ||
| holes: Vec::new(), | ||
| constraints: vec![Constraint::Eq { | ||
| expected: param.clone(), | ||
| actual: self.to_ty(), | ||
| span, | ||
| span: *tuple_span, | ||
| }], | ||
| errors: Vec::new(), | ||
| }, | ||
| (Self::Tuple(_), _) => App { | ||
| (Self::Tuple(_, tuple_span), _) => App { | ||
| holes: Vec::new(), | ||
| constraints: Vec::new(), | ||
| errors: vec![Error(ErrorKind::TyMismatch( | ||
| param.display(), | ||
| self.to_ty().display(), | ||
| span, | ||
| *tuple_span, | ||
| ))], | ||
| }, | ||
| } | ||
| } | ||
|
|
||
| pub(super) fn to_ty(&self) -> Ty { | ||
| match self { | ||
| ArgTy::Hole(ty) | ArgTy::Given(ty) => ty.clone(), | ||
| ArgTy::Tuple(items) => Ty::Tuple(items.iter().map(Self::to_ty).collect()), | ||
| ArgTy::Hole(ty, _) | ArgTy::Given(ty, _) => ty.clone(), | ||
| ArgTy::Tuple(items, _) => Ty::Tuple(items.iter().map(Self::to_ty).collect()), | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -1039,7 +1037,7 @@ fn check_call(callee: Ty, input: &ArgTy, output: Ty, span: Span) -> (Vec<Constra | |
| // generate constraints for the arg ty that correspond to any class constraints specified in | ||
| // the parameters | ||
|
|
||
| let mut app = input.apply(&arrow.input.borrow(), span); | ||
| let mut app = input.apply(&arrow.input.borrow()); | ||
| let expected = if app.holes.len() > 1 { | ||
| Ty::Arrow(Rc::new(Arrow { | ||
| kind: arrow.kind, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing that might help me read this is if you renamed the
spanargument to this function (can't highlight the line since it's outside the diff) to reflect whose span it is. Now that we have two spans getting passed around, it'd be good to disambiguate.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I genuinely can't tell what that span is. I'm pretty sure it's the span of the whole call. I think it effectively means "here's the span where you should report an error if you find one".