Conversation
Operator selection unified arguments and result type in one shot and dropped every rejected candidate, so a failure was always reported as "no matching operator for the parameters' type" — even when the parameters matched and only the result type (or a single argument, or the arity) was wrong. Rework selection to classify failures: - EcUnify.classify_application unifies a candidate against the expected arguments one at a time (head-normalising to see through type abbreviations), pinpointing the first argument / result / arity failure. select_op now returns OK / KO outcomes carrying the reason, the declared type and the inferred partial instantiation. - The same classification is applied to program variables (select_pv) and to local variables (in form_of_opselect, where a local that shadows an operator fails to apply). The new UnappliedOp error and its printer describe each failing candidate (operator, program variable or local), the argument types, and for operators the declared polymorphic type with the inferred type-parameter instantiation. Genuinely unknown names keep the previous UnknownVarOrOp message. Also add an "expect fail \"...\"" command that asserts a command fails with a given error message, and use it in a new regression test covering result/argument/arity mismatches, partial instantiation, multiple and mixed-kind candidates, formula context and unknown names.
oskgo
reviewed
Jun 17, 2026
oskgo
approved these changes
Jun 17, 2026
Contributor
There was a problem hiding this comment.
Indeed I was missing such a case. One example is the following:
theory T1.
op x: int -> 'a.
end T1.
theory T2.
op x: 'a -> int.
end T2.
import T1 T2.
op y: unit = x true.
Here one candidate fails because true has the wrong type, while the other fails because of the expected return type. It's not obvious to me how one should consolidate information about what was expected while handling cases such as these.
LGTM.
Member
Author
|
You have been faster than me to answer your own question :) |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Operator selection unified arguments and result type in one shot and
dropped every rejected candidate, so a failure was always reported as
"no matching operator for the parameters' type" — even when the
parameters matched and only the result type (or a single argument, or
the arity) was wrong.
Rework selection to classify failures:
EcUnify.classify_application unifies a candidate against the expected
arguments one at a time (head-normalising to see through type
abbreviations), pinpointing the first argument / result / arity
failure. select_op now returns OK / KO outcomes carrying the reason,
the declared type and the inferred partial instantiation.
The same classification is applied to program variables (select_pv)
and to local variables (in form_of_opselect, where a local that
shadows an operator fails to apply). The new UnappliedOp error and its
printer describe each failing candidate (operator, program variable or
local), the argument types, and for operators the declared polymorphic
type with the inferred type-parameter instantiation. Genuinely unknown
names keep the previous UnknownVarOrOp message.
Also add an "expect fail "..."" command that asserts a command fails
with a given error message, and use it in a new regression test covering
result/argument/arity mismatches, partial instantiation, multiple and
mixed-kind candidates, formula context and unknown names.
Closes #1048, #825.