Opened 3 years ago

Last modified 9 months ago

#13069 new bug

hs-boot files permit default methods in type class (but don't typecheck them)

Reported by: ezyang Owned by:
Priority: normal Milestone: 8.10.1
Component: Compiler (Type checker) Version: 8.1
Keywords: backpack hs-boot Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: GHC accepts invalid program Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

The documentation claims you are not allowed to do so but the compiler does not reject it.

ezyang@sabre:~$ cat A.hs-boot
module A where
class C a where
    f :: a -> a
    f x = x
ezyang@sabre:~$ ghc-head -c A.hs-boot -fforce-recomp
ezyang@sabre:~$ ghc-head --version
The Glorious Glasgow Haskell Compilation System, version 8.1.20161218

The same problem applies to hsig files (which combust more spectacularly)

Change History (9)

comment:1 Changed 3 years ago by ezyang

It looks like some hs-boot files have come to rely on this behavior:

MiniAgda-0.2014.9.12/Eval.hs-boot:class Reval a where
MiniAgda-0.2014.9.12/Eval.hs-boot-  reval' :: Valuation -> a -> TypeCheck a
MiniAgda-0.2014.9.12/Eval.hs-boot-  reval  :: a -> TypeCheck a
MiniAgda-0.2014.9.12/Eval.hs-boot-  reval = reval' emptyVal
postgresql-simple-0.5.2.1/src/Database/PostgreSQL/Simple/ToRow.hs-boot:class ToRow a where
postgresql-simple-0.5.2.1/src/Database/PostgreSQL/Simple/ToRow.hs-boot-    toRow :: a -> [Action]
postgresql-simple-0.5.2.1/src/Database/PostgreSQL/Simple/ToRow.hs-boot-    default toRow :: (Generic a, GToRow (Rep a)) => a -> [Action]
postgresql-simple-0.5.2.1/src/Database/PostgreSQL/Simple/ToRow.hs-boot-    toRow = gtoRow . from
event-monad-0.0.3/src/Control/Monad/Event/Classes.hs-boot:class (MonadEvent m e, MonadTime m t) => ScheduleEvent m t e | m -> t                                                                             event-monad-0.0.3/src/Control/Monad/Event/Classes.hs-boot-    where
event-monad-0.0.3/src/Control/Monad/Event/Classes.hs-boot-        scheduleEventAt :: t -> e -> m EventID
event-monad-0.0.3/src/Control/Monad/Event/Classes.hs-boot-        doNext :: e -> m () 
event-monad-0.0.3/src/Control/Monad/Event/Classes.hs-boot-        doNext e = do
event-monad-0.0.3/src/Control/Monad/Event/Classes.hs-boot-            now <- getCurrentTime
event-monad-0.0.3/src/Control/Monad/Event/Classes.hs-boot-            scheduleEventAt now e

Maybe less than a dozen I could see on Hackage. So maybe we should just update the docs.

comment:2 Changed 3 years ago by ezyang

Actually, the bug is worse: the following A.hs-boot file is accepted by GHC.

module A where
class C a where
    f :: a -> a
    f = True

This doesn't seem to be a soundness problem because what this actually seems to translate into "there is a default method for f", so this code never gets compiled / used for anything.

comment:3 Changed 3 years ago by ezyang

Summary: hs-boot files permit default methods in type classhs-boot files permit default methods in type class (but don't typecheck them)

comment:4 Changed 3 years ago by dfeuer

Milestone: 8.2.1

comment:5 Changed 3 years ago by ezyang

The corresponding version of this bug with hsig files was fixed with #13041. So it's just an hs-boot bug now.

comment:6 Changed 2 years ago by bgamari

Milestone: 8.2.18.4.1

Given that 8.2.1-rc1 is imminent, I'm bumping these off to the 8.4

comment:7 Changed 20 months ago by bgamari

Milestone: 8.4.18.6.1

This ticket won't be resolved in 8.4; remilestoning for 8.6. Do holler if you are affected by this or would otherwise like to work on it.

comment:8 Changed 15 months ago by bgamari

Milestone: 8.6.18.8.1

These won't be fixed for 8.6, bumping to 8.8.

comment:9 Changed 9 months ago by osa1

Milestone: 8.8.18.10.1

Bumping milestones of low-priority tickets.

Note: See TracTickets for help on using tickets.