Magnus pushed to branch wip/mangoiv/26616 at Glasgow Haskell Compiler / GHC
Commits:
-
768de01f
by mangoiv at 2026-06-16T11:58:01+02:00
30 changed files:
- + changelog.d/26616
- compiler/GHC/Hs/Expr.hs
- compiler/GHC/Rename/Env.hs
- compiler/GHC/Rename/Expr.hs
- compiler/GHC/Rename/HsType.hs
- compiler/GHC/Rename/Module.hs
- compiler/GHC/Rename/Pat.hs
- compiler/GHC/Rename/Splice.hs
- compiler/GHC/Rename/Splice.hs-boot
- compiler/GHC/Rename/Unbound.hs
- compiler/GHC/Tc/Errors.hs
- compiler/GHC/Tc/Errors/Ppr.hs
- compiler/GHC/Tc/Errors/Types.hs
- compiler/GHC/Tc/Gen/Export.hs
- compiler/GHC/Tc/Utils/Env.hs
- compiler/GHC/Tc/Utils/Monad.hs
- compiler/GHC/Types/Name/Reader.hs
- testsuite/tests/quotes/LiftErrMsg.stderr
- testsuite/tests/quotes/LiftErrMsgDefer.stderr
- testsuite/tests/quotes/LiftErrMsgTyped.stderr
- testsuite/tests/splice-imports/SI03.stderr
- testsuite/tests/splice-imports/SI05.stderr
- testsuite/tests/splice-imports/SI25.stderr
- testsuite/tests/splice-imports/SI28.stderr
- testsuite/tests/splice-imports/SI31.stderr
- testsuite/tests/splice-imports/T26088.stderr
- testsuite/tests/splice-imports/T26090.stderr
- + testsuite/tests/splice-imports/T26616.hs
- + testsuite/tests/splice-imports/T26616.stderr
- testsuite/tests/splice-imports/all.T
Changes:
| 1 | +section: compiler
|
|
| 2 | +synopsis: Fix bugs with ExplcitLevelImports accepting incorrect qualified imports and reporting errors
|
|
| 3 | + incorrectly in the presence of qualified imports
|
|
| 4 | +description: When reporting errors, ExplcitLevelImports would sometimes report identifiers qualified at a
|
|
| 5 | + module they were not oringally actually be qualified at. It would also allow using *any* qualified import
|
|
| 6 | + to bring an identifier into scope, even if that qualified import was not imported at the correct level.
|
|
| 7 | + This MR fixes both issues by passing more information to the responsible error reporting code.
|
|
| 8 | +mrs: !16195
|
|
| 9 | +issues: #26616 #27385 |
| ... | ... | @@ -2254,6 +2254,7 @@ data HsImplicitLiftSplice = |
| 2254 | 2254 | { implicit_lift_bind_lvl :: S.Set ThLevelIndex
|
| 2255 | 2255 | , implicit_lift_used_lvl :: ThLevelIndex
|
| 2256 | 2256 | , implicit_lift_gre :: Maybe GlobalRdrElt
|
| 2257 | + -- ^ Nothing iff 'LevelCheckReason' is 'LevelCheckInstance'
|
|
| 2257 | 2258 | , implicit_lift_lid :: LIdOccP GhcRn
|
| 2258 | 2259 | }
|
| 2259 | 2260 |
| ... | ... | @@ -12,9 +12,9 @@ module GHC.Rename.Env ( |
| 12 | 12 | |
| 13 | 13 | lookupLocatedTopBndrRnN, lookupTopBndrRn,
|
| 14 | 14 | |
| 15 | - lookupLocatedOccRn, lookupLocatedOccRnConstr, lookupLocatedOccRnRecField,
|
|
| 15 | + lookupLocatedOccRn, lookupLocatedOccRnGRE, lookupLocatedOccRnConstr, lookupLocatedOccRnRecField,
|
|
| 16 | 16 | lookupLocatedOccRnNone,
|
| 17 | - lookupOccRn, lookupOccRn_maybe, lookupSameOccRn_maybe,
|
|
| 17 | + lookupOccRn, lookupOccRnGRE, lookupOccRn_maybe, lookupSameOccRn_maybe,
|
|
| 18 | 18 | lookupLocalOccRn_maybe, lookupInfoOccRn,
|
| 19 | 19 | lookupLocalOccThLvl_maybe, lookupLocalOccRn,
|
| 20 | 20 | lookupTypeOccRn,
|
| ... | ... | @@ -992,6 +992,11 @@ lookupLocatedOccRn :: WhatLooking |
| 992 | 992 | -> TcRn (GenLocated (EpAnn ann) Name)
|
| 993 | 993 | lookupLocatedOccRn what = wrapLocMA (lookupOccRn what)
|
| 994 | 994 | |
| 995 | +lookupLocatedOccRnGRE :: WhatLooking
|
|
| 996 | + -> GenLocated (EpAnn ann) RdrName
|
|
| 997 | + -> TcRn (GenLocated (EpAnn ann) GlobalRdrElt)
|
|
| 998 | +lookupLocatedOccRnGRE what = wrapLocMA (lookupOccRnGRE what)
|
|
| 999 | + |
|
| 995 | 1000 | lookupLocatedOccRnConstr :: GenLocated (EpAnn ann) RdrName
|
| 996 | 1001 | -> TcRn (GenLocated (EpAnn ann) Name)
|
| 997 | 1002 | lookupLocatedOccRnConstr = wrapLocMA lookupOccRnConstr
|
| ... | ... | @@ -1019,11 +1024,14 @@ lookupLocalOccThLvl_maybe name |
| 1019 | 1024 | -- | lookupOccRn looks up an occurrence of a RdrName, and uses its argument to
|
| 1020 | 1025 | -- determine what kind of suggestions should be displayed if it is not in scope
|
| 1021 | 1026 | lookupOccRn :: WhatLooking -> RdrName -> RnM Name
|
| 1022 | -lookupOccRn which_suggest rdr_name
|
|
| 1027 | +lookupOccRn which_suggest = fmap greName . lookupOccRnGRE which_suggest
|
|
| 1028 | + |
|
| 1029 | +lookupOccRnGRE :: WhatLooking -> RdrName -> RnM GlobalRdrElt
|
|
| 1030 | +lookupOccRnGRE which_suggest rdr_name
|
|
| 1023 | 1031 | = do { mb_gre <- lookupOccRn_maybe rdr_name
|
| 1024 | 1032 | ; case mb_gre of
|
| 1025 | - Just gre -> return $ greName gre
|
|
| 1026 | - Nothing -> reportUnboundName which_suggest rdr_name }
|
|
| 1033 | + Just gre -> return gre
|
|
| 1034 | + Nothing -> mkUnboundGRERdr rdr_name <$ reportUnboundName which_suggest rdr_name }
|
|
| 1027 | 1035 | |
| 1028 | 1036 | -- | Look up an occurrence of a 'RdrName'.
|
| 1029 | 1037 | --
|
| ... | ... | @@ -1087,16 +1095,22 @@ lookupLocalOccRn rdr_name |
| 1087 | 1095 | |
| 1088 | 1096 | -- lookupTypeOccRn looks up an optionally promoted RdrName.
|
| 1089 | 1097 | -- Used for looking up type variables.
|
| 1090 | -lookupTypeOccRn :: RdrName -> RnM Name
|
|
| 1098 | +lookupTypeOccRn :: RdrName -> RnM GlobalRdrElt
|
|
| 1091 | 1099 | -- see Note [Demotion]
|
| 1092 | 1100 | lookupTypeOccRn rdr_name
|
| 1093 | 1101 | = do { mb_gre <- lookupOccRn_maybe rdr_name
|
| 1094 | 1102 | ; case mb_gre of
|
| 1095 | - Just gre -> return $ greName gre
|
|
| 1096 | - Nothing ->
|
|
| 1097 | - if occName rdr_name == occName eqTyCon_RDR -- See Note [eqTyCon (~) compatibility fallback]
|
|
| 1098 | - then eqTyConName <$ addDiagnostic TcRnTypeEqualityOutOfScope
|
|
| 1099 | - else lookup_demoted rdr_name }
|
|
| 1103 | + Just gre -> return gre
|
|
| 1104 | + Nothing
|
|
| 1105 | + | occName rdr_name == occName eqTyCon_RDR -- See Note [eqTyCon (~) compatibility fallback]
|
|
| 1106 | + -> mkExactGRE
|
|
| 1107 | + eqTyConName
|
|
| 1108 | + -- eqTyCon is not an open family ty con (which is the only
|
|
| 1109 | + -- case in which the functoriality of TyConFlavour actually
|
|
| 1110 | + -- matters)
|
|
| 1111 | + (IAmTyCon (eqTyConName <$ tyConFlavour eqTyCon))
|
|
| 1112 | + <$ addDiagnostic TcRnTypeEqualityOutOfScope
|
|
| 1113 | + | otherwise -> lookup_demoted rdr_name }
|
|
| 1100 | 1114 | |
| 1101 | 1115 | {- Note [eqTyCon (~) compatibility fallback]
|
| 1102 | 1116 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ... | ... | @@ -1113,7 +1127,7 @@ but emit appropriate warnings. |
| 1113 | 1127 | -}
|
| 1114 | 1128 | |
| 1115 | 1129 | -- Used when looking up a term name (varName or dataName) in a type
|
| 1116 | -lookup_demoted :: RdrName -> RnM Name
|
|
| 1130 | +lookup_demoted :: RdrName -> RnM GlobalRdrElt
|
|
| 1117 | 1131 | lookup_demoted rdr_name
|
| 1118 | 1132 | | Just demoted_rdr <- demoteRdrNameTcCls rdr_name
|
| 1119 | 1133 | -- Maybe it's the name of a *data* constructor
|
| ... | ... | @@ -1121,11 +1135,12 @@ lookup_demoted rdr_name |
| 1121 | 1135 | ; star_is_type <- xoptM LangExt.StarIsType
|
| 1122 | 1136 | ; let is_star_type = if star_is_type then StarIsType else StarIsNotType
|
| 1123 | 1137 | star_is_type_hints = noStarIsTypeHints is_star_type rdr_name
|
| 1138 | + mk_unbound_name_GRE hint = unboundGREX looking_for rdr_name hint
|
|
| 1124 | 1139 | ; if data_kinds
|
| 1125 | 1140 | then do { mb_demoted_gre <- lookupOccRn_maybe demoted_rdr
|
| 1126 | 1141 | ; case mb_demoted_gre of
|
| 1127 | - Nothing -> unboundNameX looking_for rdr_name star_is_type_hints
|
|
| 1128 | - Just demoted_gre -> return $ greName demoted_gre}
|
|
| 1142 | + Nothing -> mk_unbound_name_GRE star_is_type_hints
|
|
| 1143 | + Just demoted_gre -> return demoted_gre}
|
|
| 1129 | 1144 | else do { -- We need to check if a data constructor of this name is
|
| 1130 | 1145 | -- in scope to give good error messages. However, we do
|
| 1131 | 1146 | -- not want to give an additional error if the data
|
| ... | ... | @@ -1137,13 +1152,13 @@ lookup_demoted rdr_name |
| 1137 | 1152 | = [SuggestExtension $ SuggestSingleExtension additional LangExt.DataKinds]
|
| 1138 | 1153 | | otherwise
|
| 1139 | 1154 | = star_is_type_hints
|
| 1140 | - ; unboundNameX looking_for rdr_name suggestion } }
|
|
| 1155 | + ; mk_unbound_name_GRE suggestion } }
|
|
| 1141 | 1156 | |
| 1142 | 1157 | | isQual rdr_name,
|
| 1143 | 1158 | Just demoted_rdr_name <- demoteRdrNameTv rdr_name
|
| 1144 | 1159 | -- Definitely an illegal term variable, as type variables are never exported.
|
| 1145 | 1160 | -- See Note [Demotion of unqualified variables] (W2)
|
| 1146 | - = report_qualified_term_in_types rdr_name demoted_rdr_name
|
|
| 1161 | + = mkUnboundGREName <$> report_qualified_term_in_types rdr_name demoted_rdr_name
|
|
| 1147 | 1162 | |
| 1148 | 1163 | | isUnqual rdr_name,
|
| 1149 | 1164 | Just demoted_rdr_name <- demoteRdrNameTv rdr_name
|
| ... | ... | @@ -1152,12 +1167,12 @@ lookup_demoted rdr_name |
| 1152 | 1167 | ; if required_type_arguments
|
| 1153 | 1168 | then do { mb_demoted_gre <- lookupOccRn_maybe demoted_rdr_name
|
| 1154 | 1169 | ; case mb_demoted_gre of
|
| 1155 | - Nothing -> unboundName (LF WL_Anything WL_Anywhere) rdr_name
|
|
| 1156 | - Just demoted_gre -> return $ greName demoted_gre }
|
|
| 1157 | - else unboundName looking_for rdr_name }
|
|
| 1170 | + Nothing -> unboundGRE (LF WL_Anything WL_Anywhere) rdr_name
|
|
| 1171 | + Just demoted_gre -> return demoted_gre }
|
|
| 1172 | + else unboundGRE looking_for rdr_name }
|
|
| 1158 | 1173 | |
| 1159 | 1174 | | otherwise
|
| 1160 | - = unboundName looking_for rdr_name
|
|
| 1175 | + = unboundGRE looking_for rdr_name
|
|
| 1161 | 1176 | |
| 1162 | 1177 | where
|
| 1163 | 1178 | looking_for = LF WL_Type WL_Anywhere
|
| 1 | 1 | {-# LANGUAGE CPP #-}
|
| 2 | 2 | {-# LANGUAGE MonadComprehensions #-}
|
| 3 | 3 | {-# LANGUAGE MultiWayIf #-}
|
| 4 | -{-# LANGUAGE RecordWildCards #-}
|
|
| 5 | 4 | {-# LANGUAGE TypeFamilies #-}
|
| 6 | 5 | {-# LANGUAGE ViewPatterns #-}
|
| 7 | 6 | |
| ... | ... | @@ -321,7 +320,7 @@ rnExpr (HsVar _ (L l v)) |
| 321 | 320 | -- matching GRE and add a name clash error
|
| 322 | 321 | -- (see lookupGlobalOccRn_overloaded, called by lookupExprOccRn).
|
| 323 | 322 | -> do { let sel_name = flSelector $ recFieldLabel fld_info
|
| 324 | - ; checkThLocalNameNoLift (L (l2l l) (WithUserRdr v sel_name))
|
|
| 323 | + ; checkThLocalNameNoLift (L l $ WithUserRdr v gre)
|
|
| 325 | 324 | ; return (XExpr (HsRecSelRn (FieldOcc v (L l sel_name))), unitFN sel_name)
|
| 326 | 325 | }
|
| 327 | 326 | | nm == nilDataConName
|
| ... | ... | @@ -332,7 +331,7 @@ rnExpr (HsVar _ (L l v)) |
| 332 | 331 | -> rnExpr (ExplicitList noAnn [])
|
| 333 | 332 | |
| 334 | 333 | | otherwise
|
| 335 | - -> do { res_expr <- checkThLocalNameWithLift (L (l2l l) (WithUserRdr v nm))
|
|
| 334 | + -> do { res_expr <- checkThLocalNameWithLift (L (l2l l) (WithUserRdr v gre))
|
|
| 336 | 335 | ; return (res_expr, unitFN nm) }
|
| 337 | 336 | }}}
|
| 338 | 337 |
| ... | ... | @@ -606,20 +606,21 @@ rnHsTyKi env tv@(HsTyVar _ ip (L loc rdr_name)) |
| 606 | 606 | TcRnUnexpectedKindVar rdr_name
|
| 607 | 607 | -- Any type variable at the kind level is illegal without the use
|
| 608 | 608 | -- of PolyKinds (see #14710)
|
| 609 | - ; name <- rnTyVar env rdr_name
|
|
| 609 | + ; gre <- rnTyVar env rdr_name
|
|
| 610 | 610 | ; this_mod <- getModule
|
| 611 | 611 | ; explicit_level_imports <- xoptM LangExt.ExplicitLevelImports
|
| 612 | - ; let loc_name_with_rdr = L loc $ WithUserRdr rdr_name name
|
|
| 612 | + ; let loc_gre_with_rdr = L loc $ WithUserRdr rdr_name gre
|
|
| 613 | + name = greName gre
|
|
| 613 | 614 | ; if | explicit_level_imports
|
| 614 | 615 | -- See Note [Strict level checks with ExplicitLevelImports]
|
| 615 | - -> checkThLocalNameNoLift loc_name_with_rdr
|
|
| 616 | + -> checkThLocalNameNoLift loc_gre_with_rdr
|
|
| 616 | 617 | |
| 617 | 618 | | nameIsLocalOrFrom this_mod name
|
| 618 | - -> checkThLocalTyName name
|
|
| 619 | + -> checkThLocalTyName gre
|
|
| 619 | 620 | |
| 620 | 621 | | otherwise -> pure ()
|
| 621 | - ; checkPromotedDataConName env tv Prefix ip name
|
|
| 622 | - ; return (HsTyVar noAnn ip loc_name_with_rdr, unitFN name) }
|
|
| 622 | + ; checkPromotedDataConName env tv Prefix ip $ greName gre
|
|
| 623 | + ; return (HsTyVar noAnn ip $ fmap greName <$> loc_gre_with_rdr, unitFN name) }
|
|
| 623 | 624 | |
| 624 | 625 | rnHsTyKi env ty@(HsOpTy _ ty1 tyop ty2)
|
| 625 | 626 | = setSrcSpan (getLocA tyop) $
|
| ... | ... | @@ -826,13 +827,13 @@ throw an error accordingly. |
| 826 | 827 | -}
|
| 827 | 828 | |
| 828 | 829 | --------------
|
| 829 | -rnTyVar :: RnTyKiEnv -> RdrName -> RnM Name
|
|
| 830 | +rnTyVar :: RnTyKiEnv -> RdrName -> RnM GlobalRdrElt
|
|
| 830 | 831 | rnTyVar env rdr_name
|
| 831 | - = do { name <- lookupTypeOccRn rdr_name
|
|
| 832 | - ; checkNamedWildCard env name
|
|
| 833 | - ; return name }
|
|
| 832 | + = do { gre <- lookupTypeOccRn rdr_name
|
|
| 833 | + ; checkNamedWildCard env $ greName gre
|
|
| 834 | + ; return gre }
|
|
| 834 | 835 | |
| 835 | -rnLTyVar :: LocatedN RdrName -> RnM (LocatedN Name)
|
|
| 836 | +rnLTyVar :: LocatedN RdrName -> RnM (LocatedN GlobalRdrElt)
|
|
| 836 | 837 | -- Called externally; does not deal with wildcards
|
| 837 | 838 | rnLTyVar (L loc rdr_name)
|
| 838 | 839 | = do { tyvar <- lookupTypeOccRn rdr_name
|
| ... | ... | @@ -843,14 +844,15 @@ rnHsTyOp :: RnTyKiEnv -> HsType GhcPs -> LHsType GhcPs |
| 843 | 844 | -> RnM (LHsType GhcRn, FreeNames)
|
| 844 | 845 | rnHsTyOp env overall_ty tyop
|
| 845 | 846 | | L l (HsTyVar ann prom (L loc op)) <- tyop
|
| 846 | - = do { op' <- rnTyVar env op
|
|
| 847 | + = do { opgre <- rnTyVar env op
|
|
| 848 | + ; let opName = greName opgre
|
|
| 847 | 849 | ; unlessXOptM LangExt.TypeOperators $
|
| 848 | - if (op' `hasKey` eqTyConKey) -- See [eqTyCon (~) compatibility fallback] in GHC.Rename.Env
|
|
| 850 | + if opName `hasKey` eqTyConKey -- See [eqTyCon (~) compatibility fallback] in GHC.Rename.Env
|
|
| 849 | 851 | then addDiagnostic TcRnTypeEqualityRequiresOperators
|
| 850 | 852 | else addErr $ TcRnIllegalTypeOperator (ppr overall_ty) op
|
| 851 | - ; checkPromotedDataConName env overall_ty Infix prom op'
|
|
| 852 | - ; let tyop' = L l (HsTyVar ann prom (L loc (WithUserRdr op op')))
|
|
| 853 | - ; return (tyop', unitFN op') }
|
|
| 853 | + ; checkPromotedDataConName env overall_ty Infix prom opName
|
|
| 854 | + ; let tyop' = L l (HsTyVar ann prom (L loc (WithUserRdr op opName)))
|
|
| 855 | + ; return (tyop', unitFN opName) }
|
|
| 854 | 856 | | otherwise
|
| 855 | 857 | = rnLHsTyKi env tyop
|
| 856 | 858 |
| ... | ... | @@ -2491,8 +2491,8 @@ rnInjectivityAnn tvBndrs (L _ (TyVarSig _ resTv)) |
| 2491 | 2491 | bindLocalNames (maybeToList (hsLTyVarName resTv)) $
|
| 2492 | 2492 | -- The return type variable scopes over the injectivity annotation
|
| 2493 | 2493 | -- e.g. type family F a = (r::*) | r -> a
|
| 2494 | - do { injFrom' <- rnLTyVar injFrom
|
|
| 2495 | - ; injTo' <- mapM rnLTyVar injTo
|
|
| 2494 | + do { injFrom' <- fmap greName <$> rnLTyVar injFrom
|
|
| 2495 | + ; injTo' <- mapM (fmap (fmap greName) . rnLTyVar) injTo
|
|
| 2496 | 2496 | -- Note: srcSpan is unchanged, but typechecker gets
|
| 2497 | 2497 | -- confused, l2l call makes it happy
|
| 2498 | 2498 | ; return $ L (l2l srcSpan) (InjectivityAnn x injFrom' injTo') }
|
| ... | ... | @@ -2533,7 +2533,7 @@ rnInjectivityAnn _ _ (L srcSpan (InjectivityAnn x injFrom injTo)) = |
| 2533 | 2533 | (injDecl', _) <- askNoErrs $ do
|
| 2534 | 2534 | injFrom' <- rnLTyVar injFrom
|
| 2535 | 2535 | injTo' <- mapM rnLTyVar injTo
|
| 2536 | - return $ L srcSpan (InjectivityAnn x injFrom' injTo')
|
|
| 2536 | + return $ L srcSpan (InjectivityAnn x (fmap greName injFrom') (fmap (fmap greName) injTo'))
|
|
| 2537 | 2537 | return $ injDecl'
|
| 2538 | 2538 | |
| 2539 | 2539 | {-
|
| ... | ... | @@ -1296,7 +1296,8 @@ wrapSrcSpanTPRnM fn (L loc a) = do |
| 1296 | 1296 | |
| 1297 | 1297 | lookupTypeOccTPRnM :: RdrName -> TPRnM Name
|
| 1298 | 1298 | lookupTypeOccTPRnM rdr_name = liftRnFV $ do
|
| 1299 | - name <- lookupTypeOccRn rdr_name
|
|
| 1299 | + gre <- lookupTypeOccRn rdr_name
|
|
| 1300 | + let name = greName gre
|
|
| 1300 | 1301 | pure (name, unitFN name)
|
| 1301 | 1302 | |
| 1302 | 1303 | rn_lty_pat :: LHsType GhcPs -> TPRnM (LHsType GhcRn)
|
| 1 | 1 | {-# LANGUAGE TypeFamilies #-}
|
| 2 | -{-# LANGUAGE MultiWayIf #-}
|
|
| 3 | 2 | |
| 4 | 3 | module GHC.Rename.Splice (
|
| 5 | 4 | rnTopSpliceDecls,
|
| ... | ... | @@ -40,7 +39,7 @@ import GHC.Unit.Module |
| 40 | 39 | import GHC.Types.SrcLoc
|
| 41 | 40 | import GHC.Rename.HsType ( rnLHsType )
|
| 42 | 41 | |
| 43 | -import Control.Monad ( unless, when )
|
|
| 42 | +import Control.Monad ( unless, when, void )
|
|
| 44 | 43 | |
| 45 | 44 | import {-# SOURCE #-} GHC.Rename.Expr ( rnLExpr )
|
| 46 | 45 | |
| ... | ... | @@ -182,11 +181,12 @@ rnUntypedBracket e br_body |
| 182 | 181 | |
| 183 | 182 | rn_utbracket :: HsQuote GhcPs -> RnM (HsQuote GhcRn, FreeNames)
|
| 184 | 183 | rn_utbracket (VarBr _ is_value_name rdr_name)
|
| 185 | - = do { name <- lookupOccRn (if is_value_name then WL_Term else WL_Type) (unLoc rdr_name)
|
|
| 186 | - ; let res_name = L (l2l (locA rdr_name)) (WithUserRdr (unLoc rdr_name) name)
|
|
| 187 | - ; if is_value_name then checkThLocalNameNoLift res_name else checkThLocalTyName name
|
|
| 188 | - ; check_namespace is_value_name name
|
|
| 189 | - ; return (VarBr noExtField is_value_name (noLocA name), unitFN name) }
|
|
| 184 | + = do { gre <- lookupOccRnGRE (if is_value_name then WL_Term else WL_Type) (unLoc rdr_name)
|
|
| 185 | + ; let res_name = L (l2l (locA rdr_name)) (WithUserRdr (unLoc rdr_name) gre)
|
|
| 186 | + ; let name = greName gre
|
|
| 187 | + ; if is_value_name then checkThLocalNameNoLift res_name else checkThLocalTyName gre
|
|
| 188 | + ; check_namespace is_value_name $ greName gre
|
|
| 189 | + ; return (VarBr noExtField is_value_name (fmap (greName . unwrapUserRdr) res_name), unitFN name) }
|
|
| 190 | 190 | |
| 191 | 191 | rn_utbracket (ExpBr _ e) = do { (e', fvs) <- rnLExpr e
|
| 192 | 192 | ; return (ExpBr noExtField e', fvs) }
|
| ... | ... | @@ -431,10 +431,11 @@ rnUntypedSplice (HsUntypedSpliceExpr _ expr) flavour |
| 431 | 431 | |
| 432 | 432 | rnUntypedSplice (HsQuasiQuote _ quoter quote) flavour
|
| 433 | 433 | = do { -- Rename the quoter; akin to the HsVar case of rnExpr
|
| 434 | - ; quoter' <- lookupLocatedOccRn WL_TermVariable quoter
|
|
| 434 | + ; quoter' <- lookupLocatedOccRnGRE WL_TermVariable quoter
|
|
| 435 | 435 | ; let res_name = WithUserRdr (unLoc quoter) <$> quoter'
|
| 436 | 436 | ; checkThLocalNameNoLift res_name
|
| 437 | - ; return (HsQuasiQuote (HsQuasiQuoteExt flavour) quoter' quote, unitFN (unLoc quoter')) }
|
|
| 437 | + ; let loc_name = fmap greName quoter'
|
|
| 438 | + ; return (HsQuasiQuote (HsQuasiQuoteExt flavour) loc_name quote, unitFN (unLoc loc_name)) }
|
|
| 438 | 439 | |
| 439 | 440 | ---------------------
|
| 440 | 441 | rnTypedSplice :: HsTypedSplice GhcPs -- Typed splice expression
|
| ... | ... | @@ -907,14 +908,14 @@ traceSplice (SpliceInfo { spliceDescription = sd, spliceSource = mb_src |
| 907 | 908 | = vcat [ text "--" <+> ppr loc <> colon <+> text "Splicing" <+> text sd
|
| 908 | 909 | , gen ]
|
| 909 | 910 | |
| 910 | -checkThLocalTyName :: Name -> RnM ()
|
|
| 911 | -checkThLocalTyName name
|
|
| 911 | +checkThLocalTyName :: GlobalRdrElt -> RnM ()
|
|
| 912 | +checkThLocalTyName gre
|
|
| 912 | 913 | | isUnboundName name -- Do not report two errors for
|
| 913 | 914 | = return () -- $(not_in_scope args)
|
| 914 | 915 | |
| 915 | 916 | | otherwise
|
| 916 | 917 | = do { traceRn "checkThLocalTyName" (ppr name)
|
| 917 | - ; mb_local_use <- getCurrentAndBindLevel name
|
|
| 918 | + ; mb_local_use <- getCurrentAndBindLevel gre
|
|
| 918 | 919 | ; case mb_local_use of {
|
| 919 | 920 | Nothing -> return () ; -- Not a locally-bound thing
|
| 920 | 921 | Just (top_lvl, bind_lvl, use_lvl) ->
|
| ... | ... | @@ -932,28 +933,29 @@ checkThLocalTyName name |
| 932 | 933 | <+> ppr use_lvl)
|
| 933 | 934 | ; dflags <- getDynFlags
|
| 934 | 935 | ; checkCrossLevelLiftingTy dflags top_lvl bind_lvl use_lvl name } } }
|
| 936 | + where name = greName gre
|
|
| 935 | 937 | |
| 936 | 938 | -- | Check whether we are allowed to use a Name in this context (for TH purposes)
|
| 937 | 939 | -- In the case of a level incorrect program, attempt to fix it by using
|
| 938 | 940 | -- a Lift constraint.
|
| 939 | -checkThLocalNameWithLift :: LIdOccP GhcRn -> RnM (HsExpr GhcRn)
|
|
| 941 | +checkThLocalNameWithLift :: LocatedN (WithUserRdr GlobalRdrElt) -> RnM (HsExpr GhcRn)
|
|
| 940 | 942 | checkThLocalNameWithLift = checkThLocalName True
|
| 941 | 943 | |
| 942 | 944 | -- | Check whether we are allowed to use a Name in this context (for TH purposes)
|
| 943 | 945 | -- In the case of a level incorrect program, do not attempt to fix it by using
|
| 944 | 946 | -- a Lift constraint.
|
| 945 | -checkThLocalNameNoLift :: LIdOccP GhcRn -> RnM ()
|
|
| 946 | -checkThLocalNameNoLift name = checkThLocalName False name >> return ()
|
|
| 947 | +checkThLocalNameNoLift :: LocatedN (WithUserRdr GlobalRdrElt) -> RnM ()
|
|
| 948 | +checkThLocalNameNoLift = void . checkThLocalName False
|
|
| 947 | 949 | |
| 948 | 950 | -- | Implementation of the level checks
|
| 949 | 951 | -- See Note [Template Haskell levels]
|
| 950 | -checkThLocalName :: Bool -> LIdOccP GhcRn -> RnM (HsExpr GhcRn)
|
|
| 951 | -checkThLocalName allow_lifting name_var
|
|
| 952 | +checkThLocalName :: Bool -> LocatedN (WithUserRdr GlobalRdrElt) -> RnM (HsExpr GhcRn)
|
|
| 953 | +checkThLocalName allow_lifting loc_gre
|
|
| 952 | 954 | -- Exact and Orig names are not imported, so presumed available at all levels.
|
| 953 | 955 | -- whenever the user uses exact names, e.g. say @'mkNameG_v' "" "Foo" "bar"@,
|
| 954 | 956 | -- even though the 'mkNameG_v' here is essentially a quotation, we do not do
|
| 955 | 957 | -- level checks as we assume that the user was trying to bypass the level checks
|
| 956 | - | isExact (userRdrName (unLoc name_var)) || isOrig (userRdrName (unLoc name_var))
|
|
| 958 | + | isExact rdr || isOrig rdr
|
|
| 957 | 959 | = return (HsVar noExtField name_var)
|
| 958 | 960 | | isUnboundName name -- Do not report two errors for
|
| 959 | 961 | = return (HsVar noExtField name_var) -- $(not_in_scope args)
|
| ... | ... | @@ -961,7 +963,7 @@ checkThLocalName allow_lifting name_var |
| 961 | 963 | = return (HsVar noExtField name_var)
|
| 962 | 964 | | otherwise
|
| 963 | 965 | = do {
|
| 964 | - mb_local_use <- getCurrentAndBindLevel name
|
|
| 966 | + mb_local_use <- getCurrentAndBindLevel $ unwrap loc_gre
|
|
| 965 | 967 | ; case mb_local_use of {
|
| 966 | 968 | Nothing -> return (HsVar noExtField name_var) ; -- Not a locally-bound thing
|
| 967 | 969 | Just (top_lvl, bind_lvl, use_lvl) ->
|
| ... | ... | @@ -969,13 +971,12 @@ checkThLocalName allow_lifting name_var |
| 969 | 971 | ; let is_local
|
| 970 | 972 | | Just mod <- nameModule_maybe name = mod == cur_mod
|
| 971 | 973 | | otherwise = True
|
| 972 | - ; traceRn "checkThLocalName" (ppr name <+> ppr bind_lvl <+> ppr use_lvl)
|
|
| 973 | 974 | ; dflags <- getDynFlags
|
| 974 | - ; env <- getGlobalRdrEnv
|
|
| 975 | - ; let mgre = lookupGRE_Name env name
|
|
| 976 | - ; checkCrossLevelLifting dflags (LevelCheckSplice name mgre) top_lvl is_local allow_lifting bind_lvl use_lvl name_var } } }
|
|
| 977 | - where
|
|
| 978 | - name = getName name_var
|
|
| 975 | + ; checkCrossLevelLifting dflags (LevelCheckSplice $ unLoc loc_gre) top_lvl is_local allow_lifting bind_lvl use_lvl name_var } } }
|
|
| 976 | + where rdr = userRdrName $ unLoc name_var
|
|
| 977 | + name_var = fmap greName <$> loc_gre
|
|
| 978 | + name = unwrap name_var
|
|
| 979 | + unwrap = unwrapUserRdr . unLoc
|
|
| 979 | 980 | |
| 980 | 981 | --------------------------------------
|
| 981 | 982 | checkCrossLevelLifting :: DynFlags
|
| ... | ... | @@ -1013,12 +1014,14 @@ checkCrossLevelLifting dflags reason top_lvl_flg is_local allow_lifting bind_lvl |
| 1013 | 1014 | , any (\bind_idx -> use_lvl_idx == incThLevelIndex bind_idx) (Set.toList bind_lvl)
|
| 1014 | 1015 | , allow_lifting
|
| 1015 | 1016 | = do
|
| 1016 | - let mgre = case reason of
|
|
| 1017 | - LevelCheckSplice _ gre -> gre
|
|
| 1018 | - _ -> Nothing
|
|
| 1017 | + let gre
|
|
| 1018 | + | LevelCheckSplice rdr <- reason
|
|
| 1019 | + = Just $! unwrapUserRdr rdr
|
|
| 1020 | + | otherwise
|
|
| 1021 | + = Nothing
|
|
| 1019 | 1022 | (splice_name :: Name) <- newLocalBndrRn (noLocA unqualSplice)
|
| 1020 | 1023 | let pend_splice :: HsImplicitLiftSplice
|
| 1021 | - pend_splice = HsImplicitLiftSplice bind_lvl use_lvl_idx mgre name_var
|
|
| 1024 | + pend_splice = HsImplicitLiftSplice bind_lvl use_lvl_idx gre name_var
|
|
| 1022 | 1025 | -- Warning for implicit lift (#17804)
|
| 1023 | 1026 | addDetailedDiagnostic (TcRnImplicitLift name)
|
| 1024 | 1027 |
| ... | ... | @@ -2,7 +2,7 @@ module GHC.Rename.Splice where |
| 2 | 2 | |
| 3 | 3 | import GHC.Hs
|
| 4 | 4 | import GHC.Tc.Utils.Monad
|
| 5 | -import GHC.Types.Name (Name)
|
|
| 5 | +import GHC.Types.Name.Reader (WithUserRdr, GlobalRdrElt)
|
|
| 6 | 6 | import GHC.Types.Name.Set
|
| 7 | 7 | |
| 8 | 8 | |
| ... | ... | @@ -15,6 +15,6 @@ rnSpliceDecl :: SpliceDecl GhcPs -> RnM (SpliceDecl GhcRn, FreeNames) |
| 15 | 15 | |
| 16 | 16 | rnTopSpliceDecls :: HsUntypedSplice GhcPs -> RnM ([LHsDecl GhcPs], FreeNames)
|
| 17 | 17 | |
| 18 | -checkThLocalTyName :: Name -> RnM ()
|
|
| 18 | +checkThLocalTyName :: GlobalRdrElt -> RnM ()
|
|
| 19 | 19 | |
| 20 | -checkThLocalNameNoLift :: LIdOccP GhcRn -> RnM () |
|
| 20 | +checkThLocalNameNoLift :: LocatedN (WithUserRdr GlobalRdrElt) -> RnM () |
| ... | ... | @@ -11,6 +11,7 @@ module GHC.Rename.Unbound |
| 11 | 11 | , mkUnboundNameRdr
|
| 12 | 12 | , mkUnboundGRE
|
| 13 | 13 | , mkUnboundGRERdr
|
| 14 | + , mkUnboundGREName
|
|
| 14 | 15 | , isUnboundName
|
| 15 | 16 | , reportUnboundName
|
| 16 | 17 | , unknownNameSuggestions
|
| ... | ... | @@ -24,6 +25,8 @@ module GHC.Rename.Unbound |
| 24 | 25 | , LookingFor(..)
|
| 25 | 26 | , unboundName
|
| 26 | 27 | , unboundNameX
|
| 28 | + , unboundGRE
|
|
| 29 | + , unboundGREX
|
|
| 27 | 30 | , unboundTermNameInTypes
|
| 28 | 31 | , IsTermInTypes(..)
|
| 29 | 32 | , notInScopeErr
|
| ... | ... | @@ -102,14 +105,23 @@ mkUnboundNameRdr :: RdrName -> Name |
| 102 | 105 | mkUnboundNameRdr rdr = mkUnboundName (rdrNameOcc rdr)
|
| 103 | 106 | |
| 104 | 107 | mkUnboundGRE :: OccName -> GlobalRdrElt
|
| 105 | -mkUnboundGRE occ = mkLocalGRE UnboundGRE NoParent $ mkUnboundName occ
|
|
| 108 | +mkUnboundGRE occ = mkUnboundGREName $ mkUnboundName occ
|
|
| 106 | 109 | |
| 107 | 110 | mkUnboundGRERdr :: RdrName -> GlobalRdrElt
|
| 108 | -mkUnboundGRERdr rdr = mkLocalGRE UnboundGRE NoParent $ mkUnboundNameRdr rdr
|
|
| 111 | +mkUnboundGRERdr rdr = mkUnboundGREName $ mkUnboundNameRdr rdr
|
|
| 112 | + |
|
| 113 | +mkUnboundGREName :: Name -> GlobalRdrElt
|
|
| 114 | +mkUnboundGREName = mkLocalGRE UnboundGRE NoParent
|
|
| 109 | 115 | |
| 110 | 116 | reportUnboundName :: WhatLooking -> RdrName -> RnM Name
|
| 111 | 117 | reportUnboundName what_look rdr = unboundName (LF what_look WL_Anywhere) rdr
|
| 112 | 118 | |
| 119 | +unboundGRE :: LookingFor -> RdrName -> RnM GlobalRdrElt
|
|
| 120 | +unboundGRE lf rdr = mkUnboundGREName <$> unboundName lf rdr
|
|
| 121 | + |
|
| 122 | +unboundGREX :: LookingFor -> RdrName -> [GhcHint] -> RnM GlobalRdrElt
|
|
| 123 | +unboundGREX lf rdr hints = mkUnboundGREName <$> unboundNameX lf rdr hints
|
|
| 124 | + |
|
| 113 | 125 | unboundName :: LookingFor -> RdrName -> RnM Name
|
| 114 | 126 | unboundName lf rdr = unboundNameX lf rdr []
|
| 115 | 127 |
| ... | ... | @@ -1188,8 +1188,14 @@ mkImplicitLiftingReporter ctxt |
| 1188 | 1188 | mkImplicitLiftingError :: ErrorItem -> TcRnMessage
|
| 1189 | 1189 | mkImplicitLiftingError item =
|
| 1190 | 1190 | case errorItemOrigin item of
|
| 1191 | - ImplicitLiftOrigin (HsImplicitLiftSplice bound used gre name) ->
|
|
| 1192 | - TcRnBadlyLevelled (LevelCheckSplice (getName name) gre) bound used (Just item) (cec_defer_type_errors ctxt)
|
|
| 1191 | + -- mgre is Nothing IFF LevelCheckReason is LevelCheckInstance
|
|
| 1192 | + ImplicitLiftOrigin (HsImplicitLiftSplice bound used (Just gre) loc_name) ->
|
|
| 1193 | + TcRnBadlyLevelled
|
|
| 1194 | + (LevelCheckSplice $ gre <$ unLoc loc_name)
|
|
| 1195 | + bound
|
|
| 1196 | + used
|
|
| 1197 | + (Just item)
|
|
| 1198 | + (cec_defer_type_errors ctxt)
|
|
| 1193 | 1199 | _ -> pprPanic "mkImplicitLiftingError" (ppr item)
|
| 1194 | 1200 | |
| 1195 | 1201 | mkGivenErrorReporter :: Reporter
|
| ... | ... | @@ -3465,12 +3465,16 @@ pprTcRnBadlyLevelled reason bind_lvls use_lvl lift_attempt = mkDecorated $ |
| 3465 | 3465 | (text "No instance for:" <+> quotes (ppr (errorItemPred item)))
|
| 3466 | 3466 | | Just item <- [lift_attempt]
|
| 3467 | 3467 | ] ++
|
| 3468 | - [ vcat (text "Available from the imports:" : ppr_imports (gre_imp gre))
|
|
| 3469 | - | LevelCheckSplice _ (Just gre) <- [reason]
|
|
| 3468 | + [ ppr_imports (gre_imp gre)
|
|
| 3469 | + | LevelCheckSplice (unwrapUserRdr -> gre) <- [reason]
|
|
| 3470 | 3470 | , not (isEmptyBag (gre_imp gre)) ]
|
| 3471 | 3471 | where
|
| 3472 | - ppr_imports :: Bag ImportSpec -> [SDoc]
|
|
| 3473 | - ppr_imports = map ((bullet <+>) . ppr ) . bagToList
|
|
| 3472 | + ppr_imports :: Bag ImportSpec -> SDoc
|
|
| 3473 | + ppr_imports bag
|
|
| 3474 | + | [imp] <- impspecs = pprImpSpec imp
|
|
| 3475 | + | otherwise = vcat $ text "Available from the imports:" : map ((bullet <+>) . pprImpSpec) impspecs
|
|
| 3476 | + where impspecs = bagToList bag
|
|
| 3477 | + pprImpSpec imp = ppr imp
|
|
| 3474 | 3478 | |
| 3475 | 3479 | note :: SDoc -> SDoc
|
| 3476 | 3480 | note note = "Note" <> colon <+> note <> dot
|
| ... | ... | @@ -6250,8 +6254,8 @@ pprLevelCheckReason :: LevelCheckReason -> SDoc |
| 6250 | 6254 | pprLevelCheckReason = \case
|
| 6251 | 6255 | LevelCheckInstance _ t ->
|
| 6252 | 6256 | text "instance for" <+> quotes (ppr t)
|
| 6253 | - LevelCheckSplice t _ ->
|
|
| 6254 | - quotes (ppr t)
|
|
| 6257 | + LevelCheckSplice t ->
|
|
| 6258 | + quotes $ ppr $ userRdrName t
|
|
| 6255 | 6259 | |
| 6256 | 6260 | pprUninferrableTyVarCtx :: UninferrableTyVarCtx -> SDoc
|
| 6257 | 6261 | pprUninferrableTyVarCtx = \case
|
| ... | ... | @@ -6338,7 +6338,7 @@ data WrongThingSort |
| 6338 | 6338 | |
| 6339 | 6339 | data LevelCheckReason
|
| 6340 | 6340 | = LevelCheckInstance !InstanceWhat !PredType
|
| 6341 | - | LevelCheckSplice !Name !(Maybe GlobalRdrElt)
|
|
| 6341 | + | LevelCheckSplice !(WithUserRdr GlobalRdrElt)
|
|
| 6342 | 6342 | |
| 6343 | 6343 | data UninferrableTyVarCtx
|
| 6344 | 6344 | = UninfTyCtx_ClassContext [TcType]
|
| ... | ... | @@ -540,7 +540,7 @@ exports_from_avail (Just (L _ rdr_items)) rdr_env imports this_mod |
| 540 | 540 | let avail = availFromGRE gre
|
| 541 | 541 | name = greName gre
|
| 542 | 542 | |
| 543 | - checkThLocalNameNoLift (ieLWrappedUserRdrName l name)
|
|
| 543 | + checkThLocalNameNoLift $ ieLWrappedUserRdrName l gre
|
|
| 544 | 544 | occs' <- check_occs occs ie [gre]
|
| 545 | 545 | (export_warn_spans', dont_warn_export', warn_txt_rn)
|
| 546 | 546 | <- process_warning export_warn_spans
|
| ... | ... | @@ -589,7 +589,7 @@ exports_from_avail (Just (L _ rdr_items)) rdr_env imports this_mod |
| 589 | 589 | occs' <- check_occs occs ie [gre]
|
| 590 | 590 | return (Just avail, occs', exp_dflts)
|
| 591 | 591 | |
| 592 | - checkThLocalNameNoLift (ieLWrappedUserRdrName l name)
|
|
| 592 | + checkThLocalNameNoLift (ieLWrappedUserRdrName l gre)
|
|
| 593 | 593 | (export_warn_spans', dont_warn_export', warn_txt_rn)
|
| 594 | 594 | <- process_warning export_warn_spans
|
| 595 | 595 | dont_warn_export
|
| ... | ... | @@ -617,7 +617,7 @@ exports_from_avail (Just (L _ rdr_items)) rdr_env imports this_mod |
| 617 | 617 | all_gres = par : all_kids
|
| 618 | 618 | all_names = map greName all_gres
|
| 619 | 619 | |
| 620 | - checkThLocalNameNoLift (ieLWrappedUserRdrName l name)
|
|
| 620 | + checkThLocalNameNoLift (ieLWrappedUserRdrName l par)
|
|
| 621 | 621 | occs' <- check_occs occs ie all_gres
|
| 622 | 622 | (export_warn_spans', dont_warn_export', warn_txt_rn)
|
| 623 | 623 | <- process_warning export_warn_spans
|
| ... | ... | @@ -656,7 +656,7 @@ exports_from_avail (Just (L _ rdr_items)) rdr_env imports this_mod |
| 656 | 656 | all_gres = par : all_kids
|
| 657 | 657 | all_names = map greName all_gres
|
| 658 | 658 | |
| 659 | - checkThLocalNameNoLift (ieLWrappedUserRdrName l name)
|
|
| 659 | + checkThLocalNameNoLift (ieLWrappedUserRdrName l par)
|
|
| 660 | 660 | occs' <- check_occs occs ie all_gres
|
| 661 | 661 | (export_warn_spans', dont_warn_export', warn_txt_rn)
|
| 662 | 662 | <- process_warning export_warn_spans
|
| ... | ... | @@ -794,8 +794,8 @@ exports_from_avail (Just (L _ rdr_items)) rdr_env imports this_mod |
| 794 | 794 | = addUsedGREs ExportDeprecationWarnings (pickGREs parent_rdr kid_gres)
|
| 795 | 795 | |
| 796 | 796 | |
| 797 | -ieLWrappedUserRdrName :: LIEWrappedName GhcPs -> Name -> LIdOccP GhcRn
|
|
| 798 | -ieLWrappedUserRdrName l n = fmap (\rdr -> WithUserRdr rdr n) $ ieLWrappedName l
|
|
| 797 | +ieLWrappedUserRdrName :: LIEWrappedName GhcPs -> n -> GenLocated SrcSpanAnnN (WithUserRdr n)
|
|
| 798 | +ieLWrappedUserRdrName l n = (\rdr -> WithUserRdr rdr n) <$> ieLWrappedName l
|
|
| 799 | 799 | |
| 800 | 800 | -- | In what namespaces should we go looking for an import/export item
|
| 801 | 801 | -- that is out of scope, for suggestions in error messages?
|
| ... | ... | @@ -901,7 +901,7 @@ lookupChildrenExport parent_gre child_gres rdr_items = mapAndReportM doOne rdr_i |
| 901 | 901 | ; return (replaceLWrappedName n ub, gre)}
|
| 902 | 902 | FoundChild child@(GRE { gre_name = child_nm, gre_par = par }) ->
|
| 903 | 903 | do { checkPatSynParent spec_parent par child_nm
|
| 904 | - ; checkThLocalNameNoLift (ieLWrappedUserRdrName n child_nm)
|
|
| 904 | + ; checkThLocalNameNoLift (ieLWrappedUserRdrName n child)
|
|
| 905 | 905 | ; return (replaceLWrappedName n child_nm, child)
|
| 906 | 906 | }
|
| 907 | 907 | IncorrectParent p c gs -> failWithDcErr (parentGRE_name p) (greName c) gs
|
| ... | ... | @@ -135,7 +135,7 @@ import GHC.Types.Unique.Set ( nonDetEltsUniqSet ) |
| 135 | 135 | import qualified GHC.LanguageExtensions as LangExt
|
| 136 | 136 | |
| 137 | 137 | import GHC.Iface.Errors.Types
|
| 138 | -import GHC.Rename.Unbound ( unknownNameSuggestions )
|
|
| 138 | +import GHC.Rename.Unbound ( unknownNameSuggestions, mkUnboundGREName )
|
|
| 139 | 139 | import GHC.Tc.Errors.Types.PromotionErr
|
| 140 | 140 | import {-# SOURCE #-} GHC.Tc.Errors.Hole (getHoleFitDispConfig)
|
| 141 | 141 | |
| ... | ... | @@ -252,15 +252,12 @@ tcLookupGlobal name |
| 252 | 252 | env <- getGblEnv
|
| 253 | 253 | ; case lookupNameEnv (tcg_type_env env) name of {
|
| 254 | 254 | Just thing -> return thing ;
|
| 255 | - Nothing ->
|
|
| 256 | - |
|
| 257 | 255 | -- Should it have been in the local envt?
|
| 258 | 256 | -- (NB: use semantic mod here, since names never use
|
| 259 | 257 | -- identity module, see Note [Identity versus semantic module].)
|
| 260 | - if nameIsLocalOrFrom (tcg_semantic_mod env) name
|
|
| 261 | - then notFound name -- Internal names can happen in GHCi
|
|
| 262 | - else
|
|
| 263 | - |
|
| 258 | + Nothing | nameIsLocalOrFrom (tcg_semantic_mod env) name ->
|
|
| 259 | + notFound $ mkUnboundGREName name -- Internal names can happen in GHCi
|
|
| 260 | + | otherwise ->
|
|
| 264 | 261 | -- Try home package table and external package table
|
| 265 | 262 | do { mb_thing <- tcLookupImported_maybe name
|
| 266 | 263 | ; case mb_thing of
|
| ... | ... | @@ -1221,10 +1218,10 @@ pprBinders :: [Name] -> SDoc |
| 1221 | 1218 | pprBinders [bndr] = quotes (ppr bndr)
|
| 1222 | 1219 | pprBinders bndrs = pprWithCommas ppr bndrs
|
| 1223 | 1220 | |
| 1224 | -notFound :: Name -> TcM TyThing
|
|
| 1225 | -notFound name
|
|
| 1221 | +notFound :: GlobalRdrElt -> TcM TyThing
|
|
| 1222 | +notFound gre
|
|
| 1226 | 1223 | = do { lcl_env <- getLclEnv
|
| 1227 | - ; lvls <- getCurrentAndBindLevel name
|
|
| 1224 | + ; lvls <- getCurrentAndBindLevel gre
|
|
| 1228 | 1225 | ; if -- See Note [Out of scope might be a staging error]
|
| 1229 | 1226 | | isUnboundName name -> failM -- If the name really isn't in scope
|
| 1230 | 1227 | -- don't report it again (#11941)
|
| ... | ... | @@ -1234,8 +1231,13 @@ notFound name |
| 1234 | 1231 | -- introducing bugs after a refactoring of that
|
| 1235 | 1232 | -- function, we check this completely independently
|
| 1236 | 1233 | -- before scrutinizing lvls
|
| 1237 | - | Just (_top_lvl_flag, bind_lvls, lvl@Splice {}) <- lvls
|
|
| 1238 | - -> failWithTc (TcRnBadlyLevelled (LevelCheckSplice name Nothing) bind_lvls (thLevelIndex lvl) Nothing ErrorWithoutFlag)
|
|
| 1234 | + | Just (_top_lvl_flag, bind_lvls, lvl@Splice {}) <- lvls -> failWithTc $
|
|
| 1235 | + TcRnBadlyLevelled
|
|
| 1236 | + (LevelCheckSplice (gre <$ noUserRdr name))
|
|
| 1237 | + bind_lvls
|
|
| 1238 | + (thLevelIndex lvl)
|
|
| 1239 | + Nothing
|
|
| 1240 | + ErrorWithoutFlag
|
|
| 1239 | 1241 | | otherwise -> pure ()
|
| 1240 | 1242 | |
| 1241 | 1243 | ; if isTermVarOrFieldNameSpace (nameNameSpace name)
|
| ... | ... | @@ -1260,6 +1262,7 @@ notFound name |
| 1260 | 1262 | -- so let's just not print it! Getting a loop here is
|
| 1261 | 1263 | -- very unhelpful, because it hides one compiler bug with another
|
| 1262 | 1264 | }
|
| 1265 | + where name = greName gre
|
|
| 1263 | 1266 | |
| 1264 | 1267 | wrongThingErr :: WrongThingSort -> TcTyThing -> Name -> TcM a
|
| 1265 | 1268 | wrongThingErr expected thing name =
|
| ... | ... | @@ -2468,32 +2468,22 @@ keepAlive name |
| 2468 | 2468 | getThLevel :: TcM ThLevel
|
| 2469 | 2469 | getThLevel = do { env <- getLclEnv; return (getLclEnvThLevel env) }
|
| 2470 | 2470 | |
| 2471 | -getCurrentAndBindLevel :: Name -> TcRn (Maybe (TopLevelFlag, Set.Set ThLevelIndex, ThLevel))
|
|
| 2472 | -getCurrentAndBindLevel name
|
|
| 2471 | +getCurrentAndBindLevel :: GlobalRdrElt -> TcRn (Maybe (TopLevelFlag, Set.Set ThLevelIndex, ThLevel))
|
|
| 2472 | +getCurrentAndBindLevel gre
|
|
| 2473 | 2473 | = do { env <- getLclEnv;
|
| 2474 | - ; case lookupNameEnv (getLclEnvThBndrs env) name of
|
|
| 2475 | - Nothing -> do
|
|
| 2476 | - lvls <- getExternalBindLvl name
|
|
| 2477 | - if Set.empty == lvls
|
|
| 2478 | - -- This case happens when code is generated for identifiers which are not
|
|
| 2479 | - -- in scope.
|
|
| 2480 | - --
|
|
| 2481 | - -- TODO: What happens if someone generates [|| GHC.Magic.dataToTag# ||]
|
|
| 2482 | - then do
|
|
| 2483 | - return Nothing
|
|
| 2484 | - else return (Just (TopLevel, lvls, getLclEnvThLevel env))
|
|
| 2485 | - Just (top_lvl, bind_lvl) -> return (Just (top_lvl, Set.singleton bind_lvl, getLclEnvThLevel env)) }
|
|
| 2486 | - |
|
| 2487 | -getExternalBindLvl :: Name -> TcRn (Set.Set ThLevelIndex)
|
|
| 2488 | -getExternalBindLvl name = do
|
|
| 2489 | - env <- getGlobalRdrEnv
|
|
| 2490 | - mod <- getModule
|
|
| 2491 | - case lookupGRE_Name env name of
|
|
| 2492 | - Just gre -> return $ (Set.map thLevelIndexFromImportLevel (greLevels gre))
|
|
| 2493 | - Nothing ->
|
|
| 2494 | - if nameIsLocalOrFrom mod name
|
|
| 2495 | - then return $ Set.singleton topLevelIndex
|
|
| 2496 | - else return Set.empty
|
|
| 2474 | + ; return $ case lookupNameEnv (getLclEnvThBndrs env) $ greName gre of
|
|
| 2475 | + Nothing
|
|
| 2476 | + | Set.null lvls -> Nothing
|
|
| 2477 | + -- This case happens when code is generated for identifiers which are not
|
|
| 2478 | + -- in scope.
|
|
| 2479 | + --
|
|
| 2480 | + -- TODO: What happens if someone generates [|| GHC.Magic.dataToTag# ||]
|
|
| 2481 | + | otherwise -> Just (TopLevel, lvls, getLclEnvThLevel env)
|
|
| 2482 | + Just (top_lvl, bind_lvl) -> Just (top_lvl, Set.singleton bind_lvl, getLclEnvThLevel env) }
|
|
| 2483 | + where lvls = getExternalBindLvl gre
|
|
| 2484 | + |
|
| 2485 | +getExternalBindLvl :: GlobalRdrElt -> Set.Set ThLevelIndex
|
|
| 2486 | +getExternalBindLvl gre = Set.map thLevelIndexFromImportLevel (greLevels gre)
|
|
| 2497 | 2487 | |
| 2498 | 2488 | setThLevel :: ThLevel -> TcM a -> TcRn a
|
| 2499 | 2489 | setThLevel l = updLclEnv (setLclEnvThLevel l)
|
| ... | ... | @@ -40,7 +40,7 @@ module GHC.Types.Name.Reader ( |
| 40 | 40 | isOrig, isOrig_maybe, isExact, isExact_maybe, isSrcRdrName,
|
| 41 | 41 | |
| 42 | 42 | -- ** Preserving user-written qualification
|
| 43 | - WithUserRdr(..), noUserRdr, unLocWithUserRdr, userRdrName,
|
|
| 43 | + WithUserRdr(..), noUserRdr, unLocWithUserRdr, userRdrName, unwrapUserRdr,
|
|
| 44 | 44 | |
| 45 | 45 | -- * Local mapping of 'RdrName' to 'Name.Name'
|
| 46 | 46 | LocalRdrEnv, emptyLocalRdrEnv, extendLocalRdrEnv, extendLocalRdrEnvList,
|
| ... | ... | @@ -2247,9 +2247,12 @@ unLocWithUserRdr (L _ (WithUserRdr _ a)) = a |
| 2247 | 2247 | noUserRdr :: Name -> WithUserRdr Name
|
| 2248 | 2248 | noUserRdr n = WithUserRdr (nameRdrName n) n
|
| 2249 | 2249 | |
| 2250 | -userRdrName :: WithUserRdr Name -> RdrName
|
|
| 2250 | +userRdrName :: WithUserRdr a -> RdrName
|
|
| 2251 | 2251 | userRdrName (WithUserRdr rdr _) = rdr
|
| 2252 | 2252 | |
| 2253 | +unwrapUserRdr :: WithUserRdr a -> a
|
|
| 2254 | +unwrapUserRdr (WithUserRdr _ a) = a
|
|
| 2255 | + |
|
| 2253 | 2256 | rdrQual_maybe :: RdrName -> Maybe ModuleName
|
| 2254 | 2257 | rdrQual_maybe = \case
|
| 2255 | 2258 | Qual q _ -> Just q
|
| ... | ... | @@ -2,8 +2,7 @@ LiftErrMsg.hs:14:11: error: [GHC-28914] |
| 2 | 2 | • Level error: ‘id’ is bound at level 0 but used at level 1
|
| 3 | 3 | • Could not be resolved by implicit lifting due to the following error:
|
| 4 | 4 | No instance for: ‘Lift (a2 -> a2)’
|
| 5 | - • Available from the imports:
|
|
| 6 | - • imported from ‘Prelude’
|
|
| 5 | + • imported from ‘Prelude’
|
|
| 7 | 6 | • In the expression: [| id |]
|
| 8 | 7 | In an equation for ‘test’: test = [| id |]
|
| 9 | 8 | |
| ... | ... | @@ -11,8 +10,7 @@ LiftErrMsg.hs:17:13: error: [GHC-28914] |
| 11 | 10 | • Level error: ‘id’ is bound at level 0 but used at level 1
|
| 12 | 11 | • Could not be resolved by implicit lifting due to the following error:
|
| 13 | 12 | No instance for: ‘Lift (a1 -> a1)’
|
| 14 | - • Available from the imports:
|
|
| 15 | - • imported from ‘Prelude’
|
|
| 13 | + • imported from ‘Prelude’
|
|
| 16 | 14 | • In the expression: [| (id, id) |]
|
| 17 | 15 | In an equation for ‘test2’: test2 = [| (id, id) |]
|
| 18 | 16 | |
| ... | ... | @@ -20,8 +18,7 @@ LiftErrMsg.hs:17:17: error: [GHC-28914] |
| 20 | 18 | • Level error: ‘id’ is bound at level 0 but used at level 1
|
| 21 | 19 | • Could not be resolved by implicit lifting due to the following error:
|
| 22 | 20 | No instance for: ‘Lift (a0 -> a0)’
|
| 23 | - • Available from the imports:
|
|
| 24 | - • imported from ‘Prelude’
|
|
| 21 | + • imported from ‘Prelude’
|
|
| 25 | 22 | • In the expression: [| (id, id) |]
|
| 26 | 23 | In an equation for ‘test2’: test2 = [| (id, id) |]
|
| 27 | 24 |
| ... | ... | @@ -4,12 +4,11 @@ LiftErrMsgDefer.hs:14:12: warning: [GHC-28914] [-Wdeferred-type-errors (in -Wdef |
| 4 | 4 | • Level error: ‘id’ is bound at level 0 but used at level 1
|
| 5 | 5 | • Could not be resolved by implicit lifting due to the following error:
|
| 6 | 6 | No instance for: ‘Lift (a2 -> a2)’
|
| 7 | - • Available from the imports:
|
|
| 8 | - • imported from ‘Prelude’
|
|
| 7 | + • imported from ‘Prelude’
|
|
| 9 | 8 | • In the expression: [| id |]
|
| 10 | 9 | In an equation for ‘test1’: test1 = [| id |]
|
| 11 | 10 | (deferred type error)
|
| 12 | 11 | |
| 13 | 12 | HasCallStack backtrace:
|
| 14 | - throw, called at libraries/ghc-internal/src/GHC/Internal/Control/Exception/Base.hs:435:30 in ghc-internal:GHC.Internal.Control.Exception.Base
|
|
| 13 | + throw, called at libraries/ghc-internal/src/GHC/Internal/Control/Exception/Base.hs:441:30 in ghc-internal:GHC.Internal.Control.Exception.Base
|
|
| 15 | 14 |
| ... | ... | @@ -2,8 +2,7 @@ LiftErrMsgTyped.hs:14:12: error: [GHC-28914] |
| 2 | 2 | • Level error: ‘id’ is bound at level 0 but used at level 1
|
| 3 | 3 | • Could not be resolved by implicit lifting due to the following error:
|
| 4 | 4 | No instance for: ‘Lift (a -> a)’
|
| 5 | - • Available from the imports:
|
|
| 6 | - • imported from ‘Prelude’
|
|
| 5 | + • imported from ‘Prelude’
|
|
| 7 | 6 | • In the typed Template Haskell splice: id
|
| 8 | 7 | In the Template Haskell typed quotation: [|| id ||]
|
| 9 | 8 | In the expression: [|| id ||]
|
| ... | ... | @@ -12,8 +11,7 @@ LiftErrMsgTyped.hs:17:14: error: [GHC-28914] |
| 12 | 11 | • Level error: ‘id’ is bound at level 0 but used at level 1
|
| 13 | 12 | • Could not be resolved by implicit lifting due to the following error:
|
| 14 | 13 | No instance for: ‘Lift (a -> a)’
|
| 15 | - • Available from the imports:
|
|
| 16 | - • imported from ‘Prelude’
|
|
| 14 | + • imported from ‘Prelude’
|
|
| 17 | 15 | • In the typed Template Haskell splice: id
|
| 18 | 16 | In the expression: id
|
| 19 | 17 | In the Template Haskell typed quotation: [|| (id, id) ||]
|
| 1 | 1 | SI03.hs:10:11: error: [GHC-28914]
|
| 2 | 2 | • Level error: ‘sid’ is bound at level 0 but used at level -1
|
| 3 | - • Available from the imports:
|
|
| 4 | - • imported from ‘SI01A’ at SI03.hs:5:1-12
|
|
| 3 | + • imported from ‘SI01A’ at SI03.hs:5:1-12
|
|
| 5 | 4 | • In the untyped splice: $(sid [| pure () |])
|
| 6 | 5 |
| 1 | 1 | SI05.hs:10:11: error: [GHC-28914]
|
| 2 | - • Level error: ‘SI01A.sid’ is bound at level 0 but used at level -1
|
|
| 3 | - • Available from the imports:
|
|
| 4 | - • imported from ‘SI01A’ at SI05.hs:6:1-12
|
|
| 2 | + • Level error: ‘sid’ is bound at level 0 but used at level -1
|
|
| 3 | + • imported from ‘SI01A’ at SI05.hs:6:1-12
|
|
| 5 | 4 | • In the untyped splice: $(sid [| pure () |])
|
| 6 | 5 | |
| 7 | 6 | SI05.hs:10:11: error: [GHC-87543]
|
| 1 | 1 | SI25.hs:16:13: error: [GHC-28914]
|
| 2 | 2 | • Level error: ‘nestedCode’ is bound at level -1
|
| 3 | 3 | but used at level -2
|
| 4 | - • Available from the imports:
|
|
| 5 | - • imported from ‘SI25Helper’ at -1 at SI25.hs:6:1-24
|
|
| 4 | + • imported from ‘SI25Helper’ at -1 at SI25.hs:6:1-24
|
|
| 6 | 5 | • In the untyped splice: $(nestedCode "nested")
|
| 7 | 6 | In the untyped splice: $($(nestedCode "nested"))
|
| 8 | 7 |
| 1 | 1 | SI28.hs:8:13: error: [GHC-28914]
|
| 2 | 2 | • Level error: ‘id’ is bound at level 1 but used at level 0
|
| 3 | - • Available from the imports:
|
|
| 4 | - • imported from ‘Prelude’ at 1 at SI28.hs:6:1-20
|
|
| 3 | + • imported from ‘Prelude’ at 1 at SI28.hs:6:1-20
|
|
| 5 | 4 | • In the Template Haskell quotation: [| id |]
|
| 6 | 5 | In the untyped splice: $([| id |])
|
| 7 | 6 |
| 1 | 1 | <interactive>:2:3: error: [GHC-28914]
|
| 2 | 2 | • Level error: ‘id’ is bound at level 0 but used at level -1
|
| 3 | - • Available from the imports:
|
|
| 4 | - • imported from ‘Prelude’
|
|
| 3 | + • imported from ‘Prelude’
|
|
| 5 | 4 | • In the untyped splice: $(id [| () |])
|
| 6 | 5 |
| 1 | 1 | T26088A.hs:8:8: error: [GHC-28914]
|
| 2 | 2 | • Level error: ‘a’ is bound at level -1 but used at level 1
|
| 3 | - • Available from the imports:
|
|
| 4 | - • imported from ‘T26088B’ at -1 at T26088A.hs:4:1-21
|
|
| 3 | + • imported from ‘T26088B’ at -1 at T26088A.hs:4:1-21
|
|
| 5 | 4 | • In the Template Haskell quotation: [| a |]
|
| 6 | 5 |
| 1 | 1 | T26090.hs:2:17: error: [GHC-28914]
|
| 2 | 2 | • Level error: ‘a’ is bound at level 1 but used at level 0
|
| 3 | - • Available from the imports:
|
|
| 4 | - • imported from ‘T26090A’ at 1 at T26090.hs:8:1-20
|
|
| 3 | + • imported from ‘T26090A’ at 1 at T26090.hs:8:1-20
|
|
| 5 | 4 | |
| 6 | 5 | T26090.hs:4:17: error: [GHC-28914]
|
| 7 | 6 | • Level error: ‘s’ is bound at level 1 but used at level 0
|
| 8 | - • Available from the imports:
|
|
| 9 | - • imported from ‘T26090A’ at 1 at T26090.hs:8:1-20
|
|
| 7 | + • imported from ‘T26090A’ at 1 at T26090.hs:8:1-20
|
|
| 10 | 8 | • In the export: S(s)
|
| 11 | 9 | |
| 12 | 10 | T26090.hs:5:17: error: [GHC-28914]
|
| 13 | 11 | • Level error: ‘R’ is bound at level 1 but used at level 0
|
| 14 | - • Available from the imports:
|
|
| 15 | - • imported from ‘T26090A’ at 1 at T26090.hs:8:1-20
|
|
| 12 | + • imported from ‘T26090A’ at 1 at T26090.hs:8:1-20
|
|
| 16 | 13 |
| 1 | +{-# LANGUAGE ExplicitLevelImports, NoImplicitPrelude #-}
|
|
| 2 | +module T26616 where
|
|
| 3 | + |
|
| 4 | +import quote Data.Maybe qualified as Q
|
|
| 5 | +import Data.Maybe qualified as Z
|
|
| 6 | +import splice Data.Maybe qualified as S
|
|
| 7 | + |
|
| 8 | +foo = Q.isJust |
| 1 | +T26616.hs:8:7: error: [GHC-28914]
|
|
| 2 | + • Level error: ‘Q.isJust’ is bound at level 1 but used at level 0
|
|
| 3 | + • imported qualified from ‘Data.Maybe’ at 1 at T26616.hs:4:1-39
|
|
| 4 | + |
| ... | ... | @@ -52,3 +52,4 @@ test('T26090', [], multimod_compile_fail, ['T26090', '-v0']) |
| 52 | 52 | test('ModuleExport', [], multimod_compile_fail, ['ModuleExport', '-v0'])
|
| 53 | 53 | test('LevelImportExports', [], makefile_test, [])
|
| 54 | 54 | test('DodgyLevelExport', [], multimod_compile, ['DodgyLevelExport', '-v0 -Wdodgy-exports'])
|
| 55 | +test('T26616', normal, compile_fail, ['']) |