Commit 32dc7698 authored by Krzysztof Gogolewski's avatar Krzysztof Gogolewski Committed by Marge Bot

Linear types: fix roles in GADTs (#18799)

parent 36787bba
...@@ -580,8 +580,8 @@ irDataCon :: DataCon -> RoleM () ...@@ -580,8 +580,8 @@ irDataCon :: DataCon -> RoleM ()
irDataCon datacon irDataCon datacon
= setRoleInferenceVars univ_tvs $ = setRoleInferenceVars univ_tvs $
irExTyVars ex_tvs $ \ ex_var_set -> irExTyVars ex_tvs $ \ ex_var_set ->
mapM_ (irType ex_var_set) do mapM_ (irType ex_var_set) (eqSpecPreds eq_spec ++ theta ++ map scaledThing arg_tys)
(map tyVarKind ex_tvs ++ eqSpecPreds eq_spec ++ theta ++ (map scaledThing arg_tys)) mapM_ (markNominal ex_var_set) (map tyVarKind ex_tvs ++ map scaledMult arg_tys) -- Field multiplicities are nominal (#18799)
-- See Note [Role-checking data constructor arguments] -- See Note [Role-checking data constructor arguments]
where where
(univ_tvs, ex_tvs, eq_spec, theta, arg_tys, _res_ty) (univ_tvs, ex_tvs, eq_spec, theta, arg_tys, _res_ty)
......
{-# LANGUAGE LinearTypes, GADTs, DataKinds #-}
module LinearRole where -- #18799
import GHC.Types (Multiplicity(..))
import Data.Coerce
data T m a where
MkT :: a %m -> T m a
f :: T 'One a -> T 'Many a
f x = coerce x
LinearRole.hs:12:7: error:
• Couldn't match type ‘'One’ with ‘'Many’
arising from a use of ‘coerce’
• In the expression: coerce x
In an equation for ‘f’: f x = coerce x
...@@ -17,6 +17,7 @@ test('LinearSeq', normal, compile_fail, ['']) ...@@ -17,6 +17,7 @@ test('LinearSeq', normal, compile_fail, [''])
test('LinearViewPattern', normal, compile_fail, ['']) test('LinearViewPattern', normal, compile_fail, [''])
test('LinearConfusedDollar', normal, compile_fail, ['']) test('LinearConfusedDollar', normal, compile_fail, [''])
test('LinearPatSyn', normal, compile_fail, ['']) test('LinearPatSyn', normal, compile_fail, [''])
test('LinearRole', normal, compile_fail, [''])
test('LinearGADTNewtype', normal, compile_fail, ['']) test('LinearGADTNewtype', normal, compile_fail, [''])
test('LinearPartialSig', normal, compile_fail, ['']) test('LinearPartialSig', normal, compile_fail, [''])
test('LinearKind', normal, compile_fail, ['']) test('LinearKind', normal, compile_fail, [''])
......
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