Commit 9c21b2fd authored by Richard Eisenberg's avatar Richard Eisenberg Committed by Marge Bot

Fix #13571 by adding an extension flag check

Test case: indexed-types/should_fail/T13571
parent ae4415b9
Pipeline #10256 passed with stages
in 371 minutes and 13 seconds
......@@ -1951,6 +1951,7 @@ tcFamDecl1 parent (FamilyDecl { fdInfo = fam_info
{ traceTc "open type family:" (ppr tc_name)
; checkFamFlag tc_name
; inj' <- tcInjectivity binders inj
; checkResultSigFlag tc_name sig -- check after injectivity for better errors
; let tycon = mkFamilyTyCon tc_name binders res_kind
(resultVariableName sig) OpenSynFamilyTyCon
parent inj'
......@@ -1968,6 +1969,7 @@ tcFamDecl1 parent (FamilyDecl { fdInfo = fam_info
; return (inj', binders, res_kind) }
; checkFamFlag tc_name -- make sure we have -XTypeFamilies
; checkResultSigFlag tc_name sig
-- If Nothing, this is an abstract family in a hs-boot file;
-- but eqns might be empty in the Just case as well
......@@ -3707,6 +3709,14 @@ checkFamFlag tc_name
err_msg = hang (text "Illegal family declaration for" <+> quotes (ppr tc_name))
2 (text "Enable TypeFamilies to allow indexed type families")
checkResultSigFlag :: Name -> FamilyResultSig GhcRn -> TcM ()
checkResultSigFlag tc_name (TyVarSig _ tvb)
= do { ty_fam_deps <- xoptM LangExt.TypeFamilyDependencies
; checkTc ty_fam_deps $
hang (text "Illegal result type variable" <+> ppr tvb <+> text "for" <+> quotes (ppr tc_name))
2 (text "Enable TypeFamilyDependencies to allow result variable names") }
checkResultSigFlag _ _ = return () -- other cases OK
{- Note [Class method constraints]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Haskell 2010 is supposed to reject
......
{-# LANGUAGE GADTs, TypeOperators, DataKinds, TypeFamilies, PolyKinds #-}
{-# LANGUAGE GADTs, TypeOperators, DataKinds, TypeFamilies, PolyKinds, TypeFamilyDependencies #-}
module T14749 where
......
{-# LANGUAGE TypeFamilies #-}
module T13571 where
type family F a = r where
F a = a
T13571.hs:5:1: error:
• Illegal result type variable r for ‘F’
Enable TypeFamilyDependencies to allow result variable names
• In the type family declaration for ‘F’
{-# LANGUAGE TypeFamilies #-}
module T13571a where
import Data.Kind
type family G a = (r :: Type)
T13571a.hs:7:1: error:
• Illegal result type variable (r :: Type) for ‘G’
Enable TypeFamilyDependencies to allow result variable names
• In the type family declaration for ‘G’
......@@ -160,3 +160,5 @@ test('T16356_Fail1', normal, compile_fail, [''])
test('T16356_Fail2', normal, compile_fail, [''])
test('T16356_Fail3', normal, compile_fail, [''])
test('T17008a', normal, compile_fail, ['-fprint-explicit-kinds'])
test('T13571', normal, compile_fail, [''])
test('T13571a', normal, compile_fail, [''])
{-# LANGUAGE ScopedTypeVariables, PatternSynonyms, DataKinds, PolyKinds,
GADTs, TypeOperators, TypeFamilies #-}
GADTs, TypeOperators, TypeFamilies, TypeFamilyDependencies #-}
module T13441 where
......
{-# LANGUAGE TemplateHaskell, TypeFamilies, PolyKinds, TypeApplications #-}
{-# LANGUAGE TemplateHaskell, TypeFamilies, PolyKinds, TypeApplications, TypeFamilyDependencies #-}
module ClosedFam2 where
......
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