Skip to content

Conversation

@rodrigogribeiro
Copy link
Collaborator

@rodrigogribeiro rodrigogribeiro commented Dec 15, 2025

Fixes #240.

Signed-off-by: Rodrigo Ribeiro <rodrigogribeiro@gmail.com>
Signed-off-by: Rodrigo Ribeiro <rodrigogribeiro@gmail.com>
Signed-off-by: Rodrigo Ribeiro <rodrigogribeiro@gmail.com>
@rodrigogribeiro rodrigogribeiro changed the title Adding tests to check if type variables are unbound in class and instance definitions Checking if type variables are unbound in class and instance definitions Dec 16, 2025
Copy link
Collaborator

@mbenke mbenke left a comment

Choose a reason for hiding this comment

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

Well done, just a few nits.

Comment on lines 807 to 809
let unbound_vars = (bv idef) \\ vs
unless (null unbound_vars) $ do
unboundTypeVars idef unbound_vars
Copy link
Collaborator

Choose a reason for hiding this comment

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

Code duplication with the similar change in TcContract and also in checkSignature. Consider

  checkAllTypeVarsBound :: Pretty a => a -> [Tyvar] -> [Tyvar] -> TcM ()
  checkAllTypeVarsBound context used declared =
    let unbound = used \\ declared
    in unless (null unbound) $ unboundTypeVars context unbound

Then use:
-- In checkClass:

  checkAllTypeVarsBound icls (v : vs) bvs

  -- In checkInstance:
  checkAllTypeVarsBound idef (bv idef) vs

  -- In checkSignature:
  checkAllTypeVarsBound sig (v : vs) bvs

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed in the latest commit. Thanks for the suggestion!

Signed-off-by: Rodrigo Ribeiro <rodrigogribeiro@gmail.com>
@rodrigogribeiro rodrigogribeiro merged commit 52aa0af into main Dec 22, 2025
2 checks passed
@rodrigogribeiro rodrigogribeiro deleted the unbound-type-var-checking-fix branch December 22, 2025 13:09
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.

foralls not enforced/undefined types not caught in class instances

2 participants