From c505474dd53d302668f19de470551f52cf5b113f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mois=C3=A9s=20Ackerman?= <m@akr.mn> Date: Sat, 10 Jun 2023 17:12:38 +0200 Subject: [PATCH] Use generated src span for catch-all case of record selector functions This fixes #23492. The problem was that we used the real source span of the field declaration for the generated catch-all case in the selector function, in particular in the generated call to `recSelError`, which meant it was included in the HIE output. Using `generatedSrcSpan` instead means that it is not included. (cherry picked from commit 356a269258a50bf67811fe0edb193fc9f82dfad1) --- compiler/GHC/Tc/TyCl/Utils.hs | 11 +++++++---- testsuite/tests/hiefile/should_run/T23492.stdout | 3 --- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/compiler/GHC/Tc/TyCl/Utils.hs b/compiler/GHC/Tc/TyCl/Utils.hs index 8e7b3b8c399..0ca024fefd3 100644 --- a/compiler/GHC/Tc/TyCl/Utils.hs +++ b/compiler/GHC/Tc/TyCl/Utils.hs @@ -64,6 +64,8 @@ import GHC.Data.FastString import GHC.Unit.Module +import GHC.Rename.Utils (wrapGenSpan) + import GHC.Types.Basic import GHC.Types.FieldLabel import GHC.Types.SrcLoc @@ -954,10 +956,11 @@ mkOneRecordSelector all_cons idDetails fl has_sel -- mentions this particular record selector deflt | all dealt_with all_cons = [] | otherwise = [mkSimpleMatch CaseAlt - [L loc' (WildPat noExtField)] - (mkHsApp (L loc' (HsVar noExtField - (L locn (getName rEC_SEL_ERROR_ID)))) - (L loc' (HsLit noComments msg_lit)))] + [wrapGenSpan (WildPat noExtField)] + (wrapGenSpan + (HsApp noComments + (wrapGenSpan (HsVar noExtField (wrapGenSpan (getName rEC_SEL_ERROR_ID)))) + (wrapGenSpan (HsLit noComments msg_lit))))] -- Do not add a default case unless there are unmatched -- constructors. We must take account of GADTs, else we diff --git a/testsuite/tests/hiefile/should_run/T23492.stdout b/testsuite/tests/hiefile/should_run/T23492.stdout index 1c53e8ff657..c4965ef47e5 100644 --- a/testsuite/tests/hiefile/should_run/T23492.stdout +++ b/testsuite/tests/hiefile/should_run/T23492.stdout @@ -1,9 +1,6 @@ At (13,20), got type: PartialFieldSelector -> Bool -Addr# Bool PartialFieldSelector -Addr# -> Bool -forall a. Addr# -> a At (18,7), got type: PartialFieldSelector -> Bool At (23,7), got type: PartialFieldSelector At (23,8), got type: PartialFieldSelector -- GitLab