[GHC] #14397: For type error involving inferred types, show source of the type

#14397: For type error involving inferred types, show source of the type -------------------------------------+------------------------------------- Reporter: max630 | Owner: (none) Type: feature | Status: new request | Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Consider the code: {{{#!hs a = 42 b = a . "hello" }}} The type Error is (ghc-8.2.1): {{{ TestTypes.hs:3:5: error: • Couldn't match expected type ‘b0 -> c’ with actual type ‘Integer’ • In the first argument of ‘(.)’, namely ‘a’ In the expression: a . "hello" In an equation for ‘b’: b = a . "hello" • Relevant bindings include b :: a -> c (bound at TestTypes.hs:3:1) | 3 | b = a . "hello" | ^ TestTypes.hs:3:9: error: • Couldn't match expected type ‘a -> b0’ with actual type ‘[Char]’ • In the second argument of ‘(.)’, namely ‘"hello"’ In the expression: a . "hello" In an equation for ‘b’: b = a . "hello" • Relevant bindings include b :: a -> c (bound at TestTypes.hs:3:1) | 3 | b = a . "hello" | ^^^^^^^ }}} Actually, the real mistake may be in line 1, where `a` is inferred as of type `Integer`, while it probably was not meant to. But that location is not reported to the error. As you can guess, in real code location where the unexpected type is inferred for a binding is not that obvious to find. Suggestion: track locations where bindings' types are inferred, and in case of type error involvin the bindings, add them to the "Relevant bindings" section, or otherwise show it. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14397 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14397: For type error involving inferred types, show source of the type -------------------------------------+------------------------------------- Reporter: max630 | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Description changed by max630: Old description:
Consider the code:
{{{#!hs a = 42
b = a . "hello" }}}
The type Error is (ghc-8.2.1):
{{{ TestTypes.hs:3:5: error: • Couldn't match expected type ‘b0 -> c’ with actual type ‘Integer’ • In the first argument of ‘(.)’, namely ‘a’ In the expression: a . "hello" In an equation for ‘b’: b = a . "hello" • Relevant bindings include b :: a -> c (bound at TestTypes.hs:3:1) | 3 | b = a . "hello" | ^
TestTypes.hs:3:9: error: • Couldn't match expected type ‘a -> b0’ with actual type ‘[Char]’ • In the second argument of ‘(.)’, namely ‘"hello"’ In the expression: a . "hello" In an equation for ‘b’: b = a . "hello" • Relevant bindings include b :: a -> c (bound at TestTypes.hs:3:1) | 3 | b = a . "hello" | ^^^^^^^ }}}
Actually, the real mistake may be in line 1, where `a` is inferred as of type `Integer`, while it probably was not meant to. But that location is not reported to the error. As you can guess, in real code location where the unexpected type is inferred for a binding is not that obvious to find.
Suggestion: track locations where bindings' types are inferred, and in case of type error involvin the bindings, add them to the "Relevant bindings" section, or otherwise show it.
New description: Consider the code: {{{#!hs module TestTypes where a = 42 b = a ++ "hello" }}} The type Error is (ghc-8.2.1): {{{ TestTypes.hs:3:5: error: • No instance for (Num [Char]) arising from the literal ‘42’ • In the expression: 42 In an equation for ‘a’: a = 42 | 3 | a = 42 | ^^ }}} Actually, the real mistake is in line 3, where `a` is inferred as of type `[Char]`, while it was not meant to. But that location is not reported to the error. As you can guess, in real code location where the unexpected type is inferred for a binding is not that obvious to find. Suggestion: track locations where bindings' types are inferred, and in case of type error involvin the bindings, add them to the "Relevant bindings" section, or otherwise show it. -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14397#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14397: For type error involving inferred types, show source of the type -------------------------------------+------------------------------------- Reporter: max630 | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by max630): I have fixed error in the example. This way the behavior is more clearly shown. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14397#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14397: For type error involving inferred types, show source of the type -------------------------------------+------------------------------------- Reporter: max630 | Owner: (none) Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.1 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Old description:
Consider the code:
{{{#!hs module TestTypes where
a = 42
b = a ++ "hello" }}}
The type Error is (ghc-8.2.1):
{{{ TestTypes.hs:3:5: error: • No instance for (Num [Char]) arising from the literal ‘42’ • In the expression: 42 In an equation for ‘a’: a = 42 | 3 | a = 42 | ^^ }}}
Actually, the real mistake is in line 3, where `a` is inferred as of type `[Char]`, while it was not meant to. But that location is not reported to the error. As you can guess, in real code location where the unexpected type is inferred for a binding is not that obvious to find.
Suggestion: track locations where bindings' types are inferred, and in case of type error involvin the bindings, add them to the "Relevant bindings" section, or otherwise show it.
New description: Consider the code: {{{#!hs module TestTypes where a = 42 b = a ++ "hello" }}} The type Error is (ghc-8.2.1): {{{ TestTypes.hs:3:5: error: • No instance for (Num [Char]) arising from the literal ‘42’ • In the expression: 42 In an equation for ‘a’: a = 42 | 3 | a = 42 | ^^ }}} Actually, the real mistake is in line 5, where `a` is inferred as of type `[Char]`, while it was not meant to. But that location is not reported to the error. As you can guess, in real code location where the unexpected type is inferred for a binding is not that obvious to find. Suggestion: track locations where bindings' types are inferred, and in case of type error involvin the bindings, add them to the "Relevant bindings" section, or otherwise show it. -- Comment (by max630): Fix the line reference in description -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14397#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC