diff --git a/compiler/GHC/Tc/Deriv/Generate.hs b/compiler/GHC/Tc/Deriv/Generate.hs index f5ef61727aa921e01b89757dca79b10866cbbf0d..e9bebf570ba67ab0d15e4f244ed6f606b48691ed 100644 --- a/compiler/GHC/Tc/Deriv/Generate.hs +++ b/compiler/GHC/Tc/Deriv/Generate.hs @@ -1407,7 +1407,7 @@ gen_Data_binds loc (DerivInstTys{dit_rep_tc = rep_tc}) gfoldl_eqn con = ([nlVarPat k_RDR, z_Pat, nlConVarPat con_name as_needed], - foldl' mk_k_app (z_Expr `nlHsApp` (eta_expand_data_con con)) as_needed) + foldl' mk_k_app (z_Expr `nlHsApp` (nlHsVar (getRdrName con))) as_needed) where con_name :: RdrName con_name = getRdrName con @@ -1427,18 +1427,9 @@ gen_Data_binds loc (DerivInstTys{dit_rep_tc = rep_tc}) gunfold_alt dc = mkHsCaseAlt (mk_unfold_pat dc) (mk_unfold_rhs dc) mk_unfold_rhs dc = foldr nlHsApp - (z_Expr `nlHsApp` (eta_expand_data_con dc)) + (z_Expr `nlHsApp` (nlHsVar (getRdrName dc))) (replicate (dataConSourceArity dc) (nlHsVar k_RDR)) - eta_expand_data_con dc = - mkHsLam (noLocA eta_expand_pats) - (foldl nlHsApp (nlHsVar (getRdrName dc)) eta_expand_hsvars) - where - eta_expand_pats = map nlVarPat eta_expand_vars - eta_expand_hsvars = map nlHsVar eta_expand_vars - eta_expand_vars = take (dataConSourceArity dc) as_RDRs - - mk_unfold_pat dc -- Last one is a wild-pat, to avoid -- redundant test, and annoying warning | tag-fIRST_TAG == n_cons-1 = nlWildPat -- Last constructor diff --git a/testsuite/tests/deriving/should_compile/T14682.stderr b/testsuite/tests/deriving/should_compile/T14682.stderr index 28b0a959a08c2e44cf0f314a416c6cd9549adcda..90e8da1400e96a337dacf643f40e0b942d3a952e 100644 --- a/testsuite/tests/deriving/should_compile/T14682.stderr +++ b/testsuite/tests/deriving/should_compile/T14682.stderr @@ -26,9 +26,8 @@ Derived class instances: instance GHC.Internal.Data.Data.Data T14682.Foo where GHC.Internal.Data.Data.gfoldl k z (T14682.Foo a1 a2) - = ((z (\ a1 a2 -> T14682.Foo a1 a2) `k` a1) `k` a2) - GHC.Internal.Data.Data.gunfold k z _ - = k (k (z (\ a1 a2 -> T14682.Foo a1 a2))) + = ((z T14682.Foo `k` a1) `k` a2) + GHC.Internal.Data.Data.gunfold k z _ = k (k (z T14682.Foo)) GHC.Internal.Data.Data.toConstr (T14682.Foo _ _) = $cFoo GHC.Internal.Data.Data.dataTypeOf _ = $tFoo diff --git a/testsuite/tests/typecheck/should_fail/T15883e.stderr b/testsuite/tests/typecheck/should_fail/T15883e.stderr index 8f0fdfb76807530e840da381b1f4b5573750083d..effaf71c313c9e87866639dfeb3dce0516fee5f6 100644 --- a/testsuite/tests/typecheck/should_fail/T15883e.stderr +++ b/testsuite/tests/typecheck/should_fail/T15883e.stderr @@ -1,71 +1,26 @@ - -T15883e.hs:16:1: error: [GHC-39999] - • Ambiguous type variable ‘d0’ arising from a use of ‘k’ - prevents the constraint ‘(Data d0)’ from being solved. - Probable fix: use a type annotation to specify what ‘d0’ should be. - Potentially matching instances: - instance (Data a, Data b) => Data (Either a b) - -- Defined in ‘GHC.Internal.Data.Data’ - instance Data a => Data (Down a) - -- Defined in ‘GHC.Internal.Data.Data’ - ...plus 20 others - ...plus 47 instances involving out-of-scope types - (use -fprint-potential-instances to see them all) - • In the expression: z (\ a1 -> MkFoo a1) `k` a1 - In an equation for ‘GHC.Internal.Data.Data.gfoldl’: - GHC.Internal.Data.Data.gfoldl k z (MkFoo a1) - = (z (\ a1 -> MkFoo a1) `k` a1) - When typechecking the code for ‘GHC.Internal.Data.Data.gfoldl’ - in a derived instance for ‘Data (Foo LiftedRep)’: - To see the code I am typechecking, use -ddump-deriv - In the instance declaration for ‘Data (Foo LiftedRep)’ - -T15883e.hs:16:1: error: [GHC-46956] - • Couldn't match expected type ‘a’ with actual type ‘d0’ - because type variable ‘a’ would escape its scope - This (rigid, skolem) type variable is bound by - a type expected by the context: - forall a. a - at T15883e.hs:16:1-52 - • In the first argument of ‘MkFoo’, namely ‘a1’ - In the expression: MkFoo a1 - In the first argument of ‘z’, namely ‘(\ a1 -> MkFoo a1)’ +T15883e.hs:16:1: error: [GHC-91028] + • Couldn't match type ‘d0’ with ‘forall a. a’ + Expected: d0 -> Foo LiftedRep + Actual: (forall a. a) -> Foo LiftedRep + Cannot instantiate unification variable ‘d0’ + with a type involving polytypes: forall a. a + • In the first argument of ‘z’, namely ‘MkFoo’ + In the first argument of ‘k’, namely ‘z MkFoo’ + In the expression: z MkFoo `k` a1 When typechecking the code for ‘GHC.Internal.Data.Data.gfoldl’ in a derived instance for ‘Data (Foo LiftedRep)’: To see the code I am typechecking, use -ddump-deriv - • Relevant bindings include a1 :: d0 (bound at T15883e.hs:16:1) -T15883e.hs:16:1: error: [GHC-39999] - • Ambiguous type variable ‘b0’ arising from a use of ‘k’ - prevents the constraint ‘(Data b0)’ from being solved. - Probable fix: use a type annotation to specify what ‘b0’ should be. - Potentially matching instances: - instance (Data a, Data b) => Data (Either a b) - -- Defined in ‘GHC.Internal.Data.Data’ - instance Data a => Data (Down a) - -- Defined in ‘GHC.Internal.Data.Data’ - ...plus 20 others - ...plus 47 instances involving out-of-scope types - (use -fprint-potential-instances to see them all) - • In the expression: k (z (\ a1 -> MkFoo a1)) - In an equation for ‘GHC.Internal.Data.Data.gunfold’: - GHC.Internal.Data.Data.gunfold k z _ = k (z (\ a1 -> MkFoo a1)) +T15883e.hs:16:1: error: [GHC-91028] + • Couldn't match type ‘b0’ with ‘forall a. a’ + Expected: b0 -> Foo LiftedRep + Actual: (forall a. a) -> Foo LiftedRep + Cannot instantiate unification variable ‘b0’ + with a type involving polytypes: forall a. a + • In the first argument of ‘z’, namely ‘MkFoo’ + In the first argument of ‘k’, namely ‘(z MkFoo)’ + In the expression: k (z MkFoo) When typechecking the code for ‘GHC.Internal.Data.Data.gunfold’ in a derived instance for ‘Data (Foo LiftedRep)’: To see the code I am typechecking, use -ddump-deriv - In the instance declaration for ‘Data (Foo LiftedRep)’ -T15883e.hs:16:1: error: [GHC-46956] - • Couldn't match expected type ‘a’ with actual type ‘b0’ - because type variable ‘a’ would escape its scope - This (rigid, skolem) type variable is bound by - a type expected by the context: - forall a. a - at T15883e.hs:16:1-52 - • In the first argument of ‘MkFoo’, namely ‘a1’ - In the expression: MkFoo a1 - In the first argument of ‘z’, namely ‘(\ a1 -> MkFoo a1)’ - When typechecking the code for ‘GHC.Internal.Data.Data.gunfold’ - in a derived instance for ‘Data (Foo LiftedRep)’: - To see the code I am typechecking, use -ddump-deriv - • Relevant bindings include a1 :: b0 (bound at T15883e.hs:16:1)