[GHC] #8643: Silent name shadowing

#8643: Silent name shadowing ------------------------------------+------------------------------------- Reporter: mirpa | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.4.1 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: #5288 | ------------------------------------+------------------------------------- I have code like: {{{ let baseTex = (getTexPropNode nodes . NC.properties . NC.av $ geometry)
= baseTex = (flip Map.lookup texs) . NC.tdSource }}} which gives me error: {{{ Games/secunda/Graph.hs:224:23: Couldn't match expected type `TexProperty -> Maybe a0' with actual type `Maybe b0' In the second argument of `(>>=)', namely `baseTex' In the first argument of `(>>=)', namely `(getTexPropNode nodes . NC.properties . NC.av $ geometry) >>= baseTex' In the expression: (getTexPropNode nodes . NC.properties . NC.av $ geometry) >>= baseTex >>= (flip Map.lookup texs) . NC.tdSource }}}
However if I try to get type of expressin on the right hand side of {{{let baseTex = ...}}} in ghci then I get no error. Problem is that I am importing module with function {{{baseTex :: TexProperty -> Maybe TexDesc}}} and that function is shadowed by {{{let}}} expression which should have type of {{{Maybe Texture}}}. I tried to use {{{ghc-options: -Wall -fwarn-name-shadowing}}} in Cabal with no effect. From above error I conclude, that I made a type error. So I try to get type of expression in ghci which results in correct type - that makes my confusion. While I am trying to concentrate on type error, I am missing that I shadowed function by variable. This is not for the first time I've done same mistake. I would appreciate to get warnings about name shadowing since they makes me belief that I am using names of different type. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8643 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8643: Silent name shadowing -------------------------------------+------------------------------------ Reporter: mirpa | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.4.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: #5288 -------------------------------------+------------------------------------ Comment (by simonpj): I'm afraid I don't understand your explanation. Are you saying that compiling the original module with `baseTex` in it should have given a name-shadowing error? Or what? Can you perhaps give a reproducible test case (ie not relying on other modules I don't have) and the sequence of steps that shows the problem? Thanks. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8643#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8643: Silent name shadowing -------------------------------------+------------------------------------ Reporter: mirpa | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.4.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: #5288 -------------------------------------+------------------------------------ Comment (by mirpa): {{{ $ ghc -Wall -fwarn-name-shadowing --make main.hs [2 of 2] Compiling Main ( main.hs, main.o ) main.hs:9:23: Couldn't match expected type `Int -> Maybe a0' with actual type `Maybe b0' In the second argument of `(>>=)', namely `foo' In the first argument of `(>>=)', namely `bar 1 >>= foo' In the expression: bar 1 >>= foo >>= return . (+ 1) $ ghc -Wall -fwarn-name-shadowing --make main2.hs [2 of 2] Compiling Main ( main2.hs, main2.o ) main2.hs:8:1: Warning: Top-level binding with no type signature: main :: IO () main2.hs:9:7: Warning: This binding for `foo' shadows the existing binding imported from `FooLib' at main2.hs:3:1-19 Linking main2 ... }}} Compiling {{{main.hs}}} gives no warning about shadowing of {{{foo}}}. I must use qualified name first in order to get warning about shadowing as shown in {{{main2.hs}}}. I would like to have name shadowing warning when compiling {{{main.hs}}} (while I don't see it necessary in case of {{{main2.hs}}}). -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8643#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8643: Silent name shadowing -------------------------------------+------------------------------------ Reporter: mirpa | Owner: Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.4.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: #5288 -------------------------------------+------------------------------------ Comment (by simonpj): Thanks. Now I see. The problem is that * name-shadowing is a warning, not an error * if there are errors, GHC reports them and suppresses warnings In your example, your program had a type error, which was correctly reported; but the type error was caused by accidental name capture. But only the type error is reported; the warning is suppressed. It would be easy to report warnings as well as errors, rather than suppressing the warnings. That would help you, but will mix up warnings (which are no necessarily errors) with errors (which are). I'm open to suggestions here. Does anyone else have an opinion? Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8643#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC