Skip to content

Warn for shadowed type class variables - #2441

Merged
paf31 merged 2 commits into
purescript:masterfrom
joneshf:2140-fix
Nov 25, 2016
Merged

Warn for shadowed type class variables#2441
paf31 merged 2 commits into
purescript:masterfrom
joneshf:2140-fix

Conversation

@joneshf

@joneshf joneshf commented Nov 19, 2016

Copy link
Copy Markdown
Member

Should fix #2140

The error seems less than ideal:

psc: No input files.
➜  purescript git:(2140-fix) stack exec psc -- examples/warning/2140.purs                   
Compiling Main
Warning found:
in module Main
at /home/joneshf/programming/purescript/examples/warning/2140.purs line 4, column 1 - line 5, column 35

  Type variable a was shadowed.

in type class declaration for Test

See https://github.com/purescript/purescript/wiki/Error-Code-ShadowedTypeVar for more information,
or to contribute content related to this warning.

Should we add which type definition is shadowing? If so, how do we nest that properly? Or is this a fine message?

Comment thread src/Language/PureScript/Linter.hs Outdated
f (PositionedDeclaration pos _ dec) = addHint (PositionedError pos) (f dec)
f dec@(ValueDeclaration name _ _ _) = addHint (ErrorInValueDeclaration name) (warningsInDecl moduleNames dec <> checkTypeVarsInDecl dec)
f (TypeDeclaration name ty) = addHint (ErrorInTypeDeclaration name) (checkTypeVars ty)
f (TypeClassDeclaration name args _ _ decs) = addHint (ErrorInTypeClassDeclaration name) (foldMap (checkTypeVarsInDecl' (S.fromList $ fst <$> args)) decs)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does it make sense to call f recursively on the elements of decs here? Then you'd get a ErrorInTypeDeclaration wrapper applied too.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Probably, though I'm not following how we'd do that. 😄

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Oh, I guess we'd need to modify f to add an accumulator parameter then.

Either way, we should probably add an ErrorInTypeDeclaration somehow.

@paf31
paf31 merged commit 32bc8cc into purescript:master Nov 25, 2016
@paf31

paf31 commented Nov 25, 2016

Copy link
Copy Markdown
Contributor

Looks great, thanks!

@joneshf
joneshf deleted the 2140-fix branch November 26, 2016 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No ShadowedTypeVar is raised for member type vars shadowing class vars

2 participants