Opened 2 years ago

Closed 2 years ago

#5570 closed bug (fixed)

($) of an unboxed double appears to be treated as 0.0

Reported by: manzyuk Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.0.3
Keywords: Cc: axch@…
Operating System: Linux Architecture: x86_64 (amd64)
Type of failure: Incorrect result at runtime Difficulty:
Test Case: typecheck/should_fail/T5570 Blocked By:
Blocking: Related Tickets:

Description

The following program compiles cleanly with GHC 7.0.3 running on a 64 bit Linux machine, but produces the wrong answer:

$ uname -a
Linux pandora 2.6.32-5-amd64 #1 SMP Fri Sep 9 20:23:16 UTC 2011 x86_64 GNU/Linux
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.0.3
$ cat bug.hs
{-# LANGUAGE MagicHash #-}

import GHC.Exts

main :: IO ()
main = print $ D# $ 3.0##
$ ghc -Wall bug.hs
[1 of 1] Compiling Main             ( bug.hs, bug.o )
Linking bug ...
$ ./bug
0.0

The expected behavior was to either produce a compile-time error message or to output 3.0.

Compiling this program on the same machine with -dcore-lint produces:

$ ghc bug.hs -dcore-lint
[1 of 1] Compiling Main             ( bug.hs, bug.o )
*** Core Lint errors : in result of Desugar ***
<no location info>:
    In the expression: GHC.Base.$ @ GHC.Prim.Double#
    Kinds don't match in type application:
    Type variable: a_ahX :: *
    Arg type: GHC.Prim.Double# :: #
*** Offending Program ***
Main.main :: GHC.Types.IO ()
[LclIdX]
Main.main =
  GHC.Base.$
    @ GHC.Types.Double
    @ (GHC.Types.IO ())
    (System.IO.print @ GHC.Types.Double GHC.Float.$fShowDouble)
    (GHC.Base.$ @ GHC.Prim.Double# @ GHC.Types.Double GHC.Types.D# 3.0)

:Main.main :: GHC.Types.IO ()
[LclIdX]
:Main.main = GHC.TopHandler.runMainIO @ () Main.main

*** End of Offense ***


<no location info>: 
Compilation had errors

Compiling the program with GHC 6.12.1 on a different machine running 32 bit Linux fails with the following perfectly reasonable error message:

$ uname -a
Linux golconda 2.6.32-5-686 #1 SMP Mon Jun 13 04:13:06 UTC 2011 i686 GNU/Linux
$ ghc --version
The Glorious Glasgow Haskell Compilation System, version 6.12.1
$ ghc bug.hs

bug.hs:6:15:
    Couldn't match kind `#' against `*'
    When matching the kinds of `Double# :: #' and `a :: *'
      Expected type: a
      Inferred type: Double#
    In the first argument of `($)', namely `D#'

Change History (2)

comment:1 Changed 2 years ago by simonpj@…

commit 7c8921e89a9d54e91f92a381418489f28b77372b

Author: Simon Peyton Jones <simonpj@microsoft.com>
Date:   Fri Oct 21 23:07:10 2011 +0100

    Make sure the arg and result of ($) have kind *
    
    Fixes Trac #5570

 compiler/typecheck/TcExpr.lhs |    8 ++++++++
 1 files changed, 8 insertions(+), 0 deletions(-)

comment:2 Changed 2 years ago by simonpj

  • Resolution set to fixed
  • Status changed from new to closed
  • Test Case set to typecheck/should_fail/T5570

Thanks for reporting this. It arises because ($) has its own typing rule, an ad hoc special case to allow impredicative instantiation of runST $ blah.

Simon

Note: See TracTickets for help on using tickets.