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

feat: Location information in extension inference error #464

Merged
merged 2 commits into from
Aug 29, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions src/extension/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@ pub enum InferExtensionError {
/// The incompatible solution that we found was already there
actual: ExtensionSet,
},
#[error("Solved extensions {expected} at {expected_loc:?} and {actual} at {actual_loc:?} should be equal.")]
/// A version of the above with info about which nodes failed to unify
MismatchedConcreteWithLocations {
/// Where the solution we want to insert came from
expected_loc: (Node, Direction),
/// The solution we were trying to insert for this meta
expected: ExtensionSet,
/// Which node we're trying to add a solution for
actual_loc: (Node, Direction),
/// The incompatible solution that we found was already there
actual: ExtensionSet,
},
/// A variable went unsolved that wasn't related to a parameter
#[error("Unsolved variable at location {:?}", location)]
Unsolved {
Expand Down Expand Up @@ -375,10 +387,19 @@ impl UnificationContext {
} else {
None
};
err.unwrap_or(InferExtensionError::MismatchedConcrete {
expected: rs1,
actual: rs2,
})
if let (Some(loc1), Some(loc2)) = (loc1, loc2) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the doc for this function needs updating?

Try to turn mismatches into ExtensionError when possible

err.unwrap_or(InferExtensionError::MismatchedConcreteWithLocations {
expected_loc: *loc1,
expected: rs1,
actual_loc: *loc2,
actual: rs2,
})
} else {
err.unwrap_or(InferExtensionError::MismatchedConcrete {
expected: rs1,
actual: rs2,
})
}
}

/// Take a group of equal metas and merge them into a new, single meta.
Expand Down