Opened 8 years ago

Closed 8 years ago

#5380 closed bug (fixed)

arrows if command given too general a type

Reported by: sebf Owned by: ross
Priority: highest Milestone: 7.4.1
Component: Compiler Version: 7.0.3
Keywords: Cc: ross@…, ben@…
Operating System: Linux Architecture: x86_64 (amd64)
Type of failure: GHC accepts invalid program Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

This is a reduced version of a function posted on Haskell Cafe:

{-# LANGUAGE Arrows #-}

testB :: not_bool -> (() -> ()) -> () -> not_unit
testB b f = proc () -> if b then f -< () else f -< ()

There are two problems with the type of this function

  • the first argument can be anything but should be Bool and
  • the result type can be anything but should be ().

Yet the function is accepted by GHC.

This function can be used to define a value of arbitrary type:

anythingYouWant :: anything
anythingYouWant = testB () (const ()) ()

Here are some example calls from my machine:

ghci> anythingYouWant :: Int
1098066529
ghci> anythingYouWant :: String
""
ghci> anythingYouWant :: Char
'\1098066529'
ghci> anythingYouWant () :: ()
()
ghci> anythingYouWant () :: [()]
[()Segmentation fault

Change History (7)

comment:1 Changed 8 years ago by simonpj

Cc: ross@… added

Ross, might you look at this? It looks serious!

Simon

comment:2 Changed 8 years ago by simonpj

Milestone: 7.4.1
Priority: normalhighest

...but I don't think we should hold up 7.2.

comment:3 Changed 8 years ago by daniel.is.fischer

Might be obvious, but I tested it anyway: 6.12.3 rejected the programme demanding Bool resp. ().

comment:4 Changed 8 years ago by benmos

Cc: ben@… added

Still present in 7.2.0.20110728 .

comment:5 Changed 8 years ago by igloo

Owner: set to ross

Ross, I'm assigning this to you for now, but please let us know if you don't expect to have time to look into it in the near future. Thanks!

comment:6 Changed 8 years ago by ross@…

commit 7437af6f36b8201fba7a9dea98685da4d35f167f

Author: Ross Paterson <ross@soi.city.ac.uk>
Date:   Wed Oct 26 18:23:57 2011 +0100

    fix#5380: arrows if command given too general a type
    
    There were two bugs with the implementation of rebindable syntax, so I
    adapted the code for if-expressions.  Also noted that rebinding of if
    is a bit more restricted in the arrows case.

 compiler/typecheck/TcArrows.lhs |   29 ++++++++++++++++++++---------
 1 files changed, 20 insertions(+), 9 deletions(-)

comment:7 Changed 8 years ago by ross

Resolution: fixed
Status: newclosed
Summary: Too general type with Arrows extensionarrows if command given too general a type
Note: See TracTickets for help on using tickets.