Commit a3986d7f authored by Tao He's avatar Tao He Committed by Ben Gamari

Fix scoped type variables in TH for several constructs

Namely class methods, default signatures and pattern synonyms.

When scoped type variables occur inside class default methods,
default signatures and pattern synonyms, avoid re-create explicit
type variables when represent the type signatures.

This patch should fix Trac#14885.
Signed-off-by: Tao He's avatarHE, Tao <sighingnow@gmail.com>

Test Plan: make test TEST="T14885a T14885b T14885c"

Reviewers: goldfire, bgamari, simonpj, RyanGlScott

Reviewed By: simonpj, RyanGlScott

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #14885

Differential Revision: https://phabricator.haskell.org/D4469
parent 0cbb13b3
This diff is collapsed.
......@@ -57,6 +57,9 @@ Language
See :ghc-ticket:`14773`.
- Scoped type variables now work in default methods of class declarations
and in pattern synonyms in Template Haskell. See :ghc-ticket:`14885`.
Compiler
~~~~~~~~
......
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE InstanceSigs #-}
module T14885a where
class Foo1 a where
bar1 :: forall b. a -> b -> b
bar1 _ x = (x :: b)
$([d| class Foo2 a where
bar2 :: forall b. a -> b -> b
bar2 _ x = (x :: b)
instance Foo2 Int where
bar2 :: forall b. Int -> b -> b
bar2 _ x = (x :: b)
|])
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
module T14885b where
class Foo1 a where
foo1 :: forall b. a -> b -> b
default foo1 :: forall b. a -> b -> b
foo1 _ x = (x :: b)
$([d| class Foo2 a where
foo2 :: forall b. a -> b -> b
default foo2 :: forall b. a -> b -> b
foo2 _ x = (x :: b)
|])
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TemplateHaskell #-}
module T14885c where
pattern P1 :: forall a. a -> Maybe a
pattern P1 x <- Just x where
P1 x = Just (x :: a)
$([d| pattern P2 :: forall a. a -> Maybe a
pattern P2 x <- Just x where
P2 x = Just (x :: a)
|])
......@@ -13,8 +13,8 @@ g3_0 x_1 = 3
GHC.Types.Int -> GHC.Types.Int #-}
data T_0 a_1 = T_2 a_1
instance GHC.Classes.Eq a_0 => GHC.Classes.Eq (T_1 a_0)
where (GHC.Classes.==) (T_2 x_3) (T_2 y_4) = x_3 GHC.Classes.== y_4
{-# SPECIALISE instance GHC.Classes.Eq (T_1 GHC.Types.Int) #-}
where {-# SPECIALISE instance GHC.Classes.Eq (T_1 GHC.Types.Int) #-}
(GHC.Classes.==) (T_2 x_3) (T_2 y_4) = x_3 GHC.Classes.== y_4
{-# RULES "rule1"
GHC.Real.fromIntegral
= GHC.Base.id :: a_0 -> a_0 #-}
......
......@@ -409,3 +409,6 @@ test('T14869', normal, compile,
test('T14888', normal, compile,
['-v0 -ddump-splices -dsuppress-uniques ' + config.ghc_th_way_flags])
test('T14298', normal, compile_and_run, ['-v0'])
test('T14885a', normal, compile, [''])
test('T14885b', normal, compile, [''])
test('T14885c', normal, compile, [''])
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment