
#9244: Compiler could warn about type variable shadowing, and hint about ScopedTypeVariables -------------------------------------+------------------------------------- Reporter: stusmith | Owner: kanetw Type: feature request | Status: new Priority: normal | Milestone: 8.4.1 Component: Compiler | Version: 7.6.3 Resolution: | Keywords: | TypeErrorMessages Operating System: Unknown/Multiple | Architecture: Type of failure: Incorrect | Unknown/Multiple warning at compile-time | Test Case: Blocked By: | Blocking: Related Tickets: #1316, #3691, | Differential Rev(s): #11438, #10581, #11539, #12716 | Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Before implementing much, it'd be good to write a specification of what you are trying to implement. I think it may be something like this: * When compiling without `-XScopedTypevariables`... * ...and type variable `a` ''would'' have been in scope if you were compiling ''with'' `-XScopedTypeVariables`... * ...and when you are about to add implicit quantification over `a` * ...then emit a warning Example {{{ f :: forall a. [a] -> [a] f = ....(let g :: a -> a g = ... in blah).... }}} With `-XScopedTypeVariables` the tyvar `a` would have been in scope in the body of `f`. Because it isn't in scope, we are going to implicitly quantify over `a` in the type signature for `g`, treating its signature as `g :: forall a. a->a`. That implicit quantification is what we want to warn about. Question: what if we had instead written {{{ f :: [a] -> [a] f = ....(let g :: a -> a g = ... in blah).... }}} Now, even with `-XScopedTypeVariables` the tyvar `a` would not be in scope. Do we want to warn then too? I guess so. Writing all this down, with a series of examples, would be helpful. I can see that it's a bit tricky to implement. We kind of need an extra set of tyvars that would be in scope if `-XScopedTypeVariables` was on, but aren't in scope because it isn't. Is it worth the fuss? Perhaps. Anyway, it'd be worth explaining your proposed implementation path before investing effort in implementing it. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/9244#comment:11 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler