Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC Commits: cfd4fb67 by Ryan Scott at 2026-11-22T16:36:59-05:00 GHC.HsToCore.Quote: Quote \cases with the correct type Previously, `\cases` expressions inside of Template Haskell quotes would incorrectly use the `Match` type instead of `Clause` for the element type. We now use `nonEmptyCoreList` when quoting `\cases`, which infers the correct type automatically. This works because `\cases` has an invariant that the list of clauses is always non-empty. Fixes #27826. - - - - - 3 changed files: - compiler/GHC/HsToCore/Quote.hs - + testsuite/tests/th/T27826.hs - testsuite/tests/th/all.T Changes: ===================================== compiler/GHC/HsToCore/Quote.hs ===================================== @@ -1604,7 +1604,10 @@ repE (HsLam _ LamCase (MG { mg_alts = L _ ms })) ; repLamCase core_ms } repE (HsLam _ LamCases (MG { mg_alts = (L _ ms) })) = do { ms' <- mapM repClauseTup ms - ; core_ms <- coreListM matchTyConOcc ms' + -- Safety: \cases has an invariant that `mg_alts` is + -- non-empty, so calling `nonEmptyCoreList` below is + -- always safe. + ; let core_ms = nonEmptyCoreList ms' ; repLamCases core_ms } repE (HsApp _ x y) = do {a <- repLE x; b <- repLE y; repApp a b} repE (HsAppType _ e t) = do { a <- repLE e ===================================== testsuite/tests/th/T27826.hs ===================================== @@ -0,0 +1,8 @@ +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE TemplateHaskellQuotes #-} +module T27826 where + +import Language.Haskell.TH + +foo :: Q Exp +foo = [| \cases x -> x |] ===================================== testsuite/tests/th/all.T ===================================== @@ -657,6 +657,7 @@ test('T8306_th', only_ways(['ghci']), ghci_script, ['T8306_th.script']) test('T26862_th', only_ways(['ghci']), ghci_script, ['T26862_th.script']) test('T27022', normal, compile_and_run, ['']) test('T27034', normal, compile, ['-v0 -ddump-splices -dsuppress-uniques']) +test('T27826', normal, compile, ['']) test('T20902', normal, compile, ['']) test('TH_cvt_DefaultDataInstDecl', normal, compile_fail, ['-v0']) test('TH_cvt_IllegalDeclaration', normal, compile_fail, ['-v0']) View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/cfd4fb67e963e0202e142cb4d1919f3a... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/cfd4fb67e963e0202e142cb4d1919f3a... 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