[GHC] #8542: Suggest NegativeLiterals

#8542: Suggest NegativeLiterals ------------------------------------+------------------------------------- Reporter: monoidal | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.7 Keywords: | Operating System: Unknown/Multiple Architecture: Unknown/Multiple | Type of failure: None/Unknown Difficulty: Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | ------------------------------------+------------------------------------- If we write -128 :: Int8, we get a useful warning (#7895), but it would be even better to suggest NegativeLiterals. Patch incoming. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8542 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8542: Suggest NegativeLiterals -------------------------------------+------------------------------------ Reporter: monoidal | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Changes (by monoidal): * status: new => patch Comment: Patch attached. It also gives an (incorrect) suggestion for 128 :: Int8, but this shouldn't matter. While we are at it: to determine whether an `Int` literal is correct we test with `minBound :: Int` and `maxBound :: Int`. This can vary between machines. Should this be changed to testing against `2^30` or something similar? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8542#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8542: Suggest NegativeLiterals -------------------------------------+------------------------------------ Reporter: monoidal | Owner: Type: bug | Status: patch Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Unknown/Multiple Type of failure: None/Unknown | Difficulty: Unknown Test Case: | Blocked By: Blocking: | Related Tickets: -------------------------------------+------------------------------------ Comment (by thoughtpolice): I'm very much in favor of frontend-warnings that don't depend on peculiarities of the machine, if possible. The Report specifies an Int at minimum has the range `[-2^29 .. 2^29-1]`, so I think your suggestion is reasonable. Does anyone else have opinions? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8542#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8542: Suggest NegativeLiterals
-------------------------------------+------------------------------------
Reporter: monoidal | Owner:
Type: bug | Status: patch
Priority: normal | Milestone:
Component: Compiler | Version: 7.7
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture: Unknown/Multiple
Type of failure: None/Unknown | Difficulty: Unknown
Test Case: | Blocked By:
Blocking: | Related Tickets:
-------------------------------------+------------------------------------
Comment (by Simon Peyton Jones

#8542: Suggest NegativeLiterals
-------------------------------------+------------------------------------
Reporter: monoidal | Owner:
Type: bug | Status: patch
Priority: normal | Milestone:
Component: Compiler | Version: 7.7
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture: Unknown/Multiple
Type of failure: None/Unknown | Difficulty: Unknown
Test Case: | Blocked By:
Blocking: | Related Tickets:
-------------------------------------+------------------------------------
Comment (by Simon Peyton Jones

#8542: Suggest NegativeLiterals ----------------------------------------------+---------------------------- Reporter: monoidal | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: None/Unknown | Unknown/Multiple Test Case: numeric/should_fail/T8542 | Difficulty: Unknown Blocking: | Blocked By: | Related Tickets: ----------------------------------------------+---------------------------- Changes (by simonpj): * status: patch => closed * testcase: => numeric/should_fail/T8542 * resolution: => fixed Comment: I pushed this, modified a bit to give errors like {{{ T7895.hs:13:6: Warning: Literal -129 is out of the Int8 range -128..127 }}} That is, we now give the expected range explicitly. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8542#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8542: Suggest NegativeLiterals -------------------------------------+------------------------------------- Reporter: monoidal | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | numeric/should_fail/T8542 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by alpmestan): The `hpc` way fails on `T8542`: {{{ =====> T8542(hpc) 1 of 1 [0, 0, 0] cd "./numeric/should_compile/T8542.run" && "/home/alp/ghc/inplace/test spaces/ghc-stage2" -c T8542.hs -dcore-lint -dcmm-lint -no-user-package-db -rtsopts -fno-warn-missed-specialisations -fshow-warning-groups -fdiagnostics-color=never -fno-diagnostics-show-caret -dno-debug-output -O -fhpc Actual stderr output differs from expected: diff -uw "./numeric/should_compile/T8542.run/T8542.stderr.normalised" "./numeric/should_compile/T8542.run/T8542.comp.stderr.normalised" --- ./numeric/should_compile/T8542.run/T8542.stderr.normalised 2018-03-08 10:24:05.303965000 +0100 +++ ./numeric/should_compile/T8542.run/T8542.comp.stderr.normalised 2018-03-08 10:24:05.303965000 +0100 @@ -1,4 +1,8 @@ +T8542.hs:6:6: warning: [-Woverflowed-literals (in -Wdefault)] + Literal 128 is out of the Int8 range -128..127 + If you are trying to write a large negative literal, use NegativeLiterals + T8542.hs:9:5: warning: [-Woverflowed-literals (in -Wdefault)] Literal 128 is out of the Int8 range -128..127 If you are trying to write a large negative literal, use NegativeLiterals *** unexpected failure for T8542(hpc) }}} Somehow, unlike all the other ways, it ends up warning us about both occurences of `128` in: {{{#!hs module T8542 where import GHC.Int x :: Int8 x = -128 y :: Int8 y = 128 }}} instead of realizing that the first literal is `-128` directly, which _is_ within the `[-128 .. 127]` range but supposedly not considered because `NegativeLiterals` is not on? It does sound like a little bug, and I'm curious as to why we don't see it with any of the other ways, even though to be honest I'm not familiar with the `hpc` way. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8542#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8542: Suggest NegativeLiterals -------------------------------------+------------------------------------- Reporter: monoidal | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | numeric/should_fail/T8542 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by alpmestan): * cc: alpmestan (added) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8542#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8542: Suggest NegativeLiterals -------------------------------------+------------------------------------- Reporter: monoidal | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | numeric/should_fail/T8542 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by monoidal): Originally, we were giving this warning both to `128 :: Word8` and `-128 :: Word8`. In #13257 the code was modified to recognize the pattern `negate (fromIntegral x)`. I guess that HPC is modifying to code to be able to check for coverage of both the whole expression `negate (fromInteger x)` and the subexpression `fromInteger x`, and this causes the warning not to appear. Nothing to worry, I would just skip the test with this way. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8542#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8542: Suggest NegativeLiterals -------------------------------------+------------------------------------- Reporter: monoidal | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.7 Resolution: fixed | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: | numeric/should_fail/T8542 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by alpmestan): Will do. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8542#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC