Skip to content

Fixes instance checking and elaboration for members which return closures#313

Merged
rodrigogribeiro merged 3 commits into
mainfrom
instance-closure-fix
Jan 26, 2026
Merged

Fixes instance checking and elaboration for members which return closures#313
rodrigogribeiro merged 3 commits into
mainfrom
instance-closure-fix

Conversation

@rodrigogribeiro

Copy link
Copy Markdown
Collaborator

This PR fixes #302 .

The strategy is to type the code twice: first we run the type inference without any desugaring. This is necessary becase code with closures will change its type. Such desugaring strategy is a problematic in the presence of type signatures, since the infered type for the desugared term will not match the annotated type. The strategy is detect all possible errors in the first step and then desugar and annotate all terms in the second one.

Comment thread src/Solcore/Frontend/TypeInference/TcContract.hs Outdated
Comment thread src/Solcore/Frontend/TypeInference/TcStmt.hs
Comment thread src/Solcore/Frontend/TypeInference/TcStmt.hs
Comment thread src/Solcore/Frontend/TypeInference/TcStmt.hs
* We type check the code twice: one with no desugaring enabled and
another with the command line options.
* Changed the ambiguity check in order to not consider invokable
constraints when the option of no desugaring indirect calls is enabled.
This is necessary because if no desugaring calls is enabled, no
invokable instance is generated. Thus, no invokable constraint can be
entailed in this situation.

@mbenke mbenke left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Well done!

@rodrigogribeiro rodrigogribeiro merged commit 6bb8725 into main Jan 26, 2026
2 checks passed
@rodrigogribeiro rodrigogribeiro deleted the instance-closure-fix branch January 26, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Closure types don't unify with function types in instance methods

2 participants