Magnus pushed to branch wip/mangoiv/28038 at Glasgow Haskell Compiler / GHC Commits: d1c42b22 by mangoiv at 2026-10-27T13:43:31+01:00 Abort more eagerly when trying to bind type variables in Patbinds GHC currently does not allow to bind type variables in patterns. When a user would try that, we didn't abort eagerly enough after discovering the error and thus ran into a panic looking up the type in the env while trying to update the local context. Instead, when discovering the error, we now just failM as late as possible before lookin up the tv binds. Fixes #28038 - - - - - 6 changed files: - + changelog.d/28038 - compiler/GHC/Tc/Gen/Pat.hs - + testsuite/tests/typecheck/should_fail/T28038.hs - + testsuite/tests/typecheck/should_fail/T28038.stderr - testsuite/tests/typecheck/should_fail/TyAppPat_PatternBindingExistential.stderr - testsuite/tests/typecheck/should_fail/all.T Changes: ===================================== changelog.d/28038 ===================================== @@ -0,0 +1,12 @@ +section: compiler +synopsis: + Fix a panic when trying to bind a type variable in patterns. +description: + GHC currently does not allow to bind type variables in patterns. When + a user would try that, in some situations, we didn't abort eagerly + enough after discovering the error and thus ran into a panic looking up + the type in the env while trying to update the local context. Instead, + when discovering the error, + we now abort eagerly. +mrs: !16868 +issues: #28038 ===================================== compiler/GHC/Tc/Gen/Pat.hs ===================================== @@ -1912,6 +1912,8 @@ tcConTyArg tenv penv (rn_ty, con_tv) thing_inside -- See Note [Type applications in patterns] (W1) ; _ <- unifyType Nothing arg_ty (substTyVar tenv con_tv) + ; failIfErrsM + ; result <- tcExtendNameTyVarEnv sig_wcs $ tcExtendNameTyVarEnv sig_ibs $ thing_inside ===================================== testsuite/tests/typecheck/should_fail/T28038.hs ===================================== @@ -0,0 +1,12 @@ +{-# LANGUAGE RequiredTypeArguments #-} +module Main where + +data A where + A :: forall a -> A + +main :: IO () +main = do + let a = A Int + let A b = a + pure () + ===================================== testsuite/tests/typecheck/should_fail/T28038.stderr ===================================== @@ -0,0 +1,6 @@ +T28038.hs:10:7: error: [GHC-48361] + • Binding type variables is not allowed in pattern bindings + • In the pattern: A b + In a pattern binding: A b = a + In a stmt of a 'do' block: let A b = a + ===================================== testsuite/tests/typecheck/should_fail/TyAppPat_PatternBindingExistential.stderr ===================================== @@ -3,18 +3,6 @@ TyAppPat_PatternBindingExistential.hs:10:1: error: [GHC-48361] • In the pattern: Some @a x In a pattern binding: Some @a x = Some (5 :: Integer) -TyAppPat_PatternBindingExistential.hs:10:9: error: [GHC-25897] - • Couldn't match expected type ‘p’ with actual type ‘a’ - ‘a’ is a rigid type variable bound by - a pattern with constructor: Some :: forall a. a -> Some, - in a pattern binding - at TyAppPat_PatternBindingExistential.hs:10:1-9 - ‘p’ is a rigid type variable bound by - the inferred type of x :: p - at TyAppPat_PatternBindingExistential.hs:10:1-31 - • In the pattern: Some @a x - In a pattern binding: Some @a x = Some (5 :: Integer) - TyAppPat_PatternBindingExistential.hs:13:3: error: [GHC-39999] • Ambiguous type variable ‘a0’ arising from a use of ‘print’ prevents the constraint ‘(Show a0)’ from being solved. ===================================== testsuite/tests/typecheck/should_fail/all.T ===================================== @@ -768,3 +768,4 @@ test('T26532', normal, compile_fail, ['']) test('T27731', normal, compile_fail, ['']) test('T27844', normal, compile_fail, ['']) test('T26543a', normal, compile_fail, ['']) +test('T28038', normal, compile_fail, ['']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d1c42b22b28f92d867417e531bb36345... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d1c42b22b28f92d867417e531bb36345... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
participants (1)
-
Magnus (@MangoIV)