Ticket #4912 (closed bug: fixed)

Opened 2 years ago

Last modified 2 years ago

No warnings for orphan instances declared via TypeSynonymInstances

Reported by: batterseapower Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.0.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect warning at compile-time Difficulty:
Test Case: typecheck/should_compile/T4912 Blocked By:
Blocking: Related Tickets:

Description

File Classes.hs:

module Classes where

data TheirData = TheirData

class Foo a where
    foo :: a -> a

class Bar a where
    bar :: a -> String

File Orphans.hs:

{-# LANGUAGE TypeSynonymInstances #-}
module Orphans where

import Classes


type OurData = TheirData

instance Foo TheirData where
    foo = id

instance Bar OurData where
    bar _ = "Ours"

Compile:

$ ghc --make -fforce-recomp -fwarn-orphans Orphans.hs 
[1 of 2] Compiling Classes          ( Classes.hs, Classes.o )
[2 of 2] Compiling Orphans          ( Orphans.hs, Orphans.o )

Orphans.hs:9:10: Warning: orphan instance: instance Foo TheirData

This is not my expected result. We should get orphan instance warnings for Bar OurData? as well, since OurData? is just a thinly-disguised version of TheirData?.

Change History

Changed 2 years ago by simonpj

  • status changed from new to merge
  • testcase set to typecheck/should_compile/T4912

Fixed by

Wed Jan 26 17:12:29 GMT 2011  simonpj@microsoft.com
  * Look through type synonyms when computing orphans
  
  I renamed functions tyClsNamesOfTypes to oprhNamesOfType,
  because it's only used in that capacity, and we therefore
  want to look through type synonyms.  Similarly exprOrphNames.
  
  This fixes Trac #4912.

    M ./compiler/coreSyn/CoreFVs.lhs -16 +17
    M ./compiler/iface/MkIface.lhs -8 +6
    M ./compiler/main/InteractiveEval.hs -1 +1
    M ./compiler/typecheck/TcRnDriver.lhs -2 +2
    M ./compiler/typecheck/TcType.lhs -22 +27

Worth merging if easy.

Changed 2 years ago by igloo

  • status changed from merge to closed
  • resolution set to fixed

Merged

Note: See TracTickets for help on using tickets.