diff options
author | Jaro Reinders <jaro.reinders@gmail.com> | 2021-05-01 17:40:38 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-05-05 05:44:26 -0400 |
commit | f464e4777662a25c0b241d396146ba7a3182b9f3 (patch) | |
tree | 2bb8860a0c6f9d338996ce411710b124d7f7d91a | |
parent | e9617fbace826b048208c51e47d1552449675d57 (diff) | |
download | haskell-f464e4777662a25c0b241d396146ba7a3182b9f3.tar.gz |
More specific error messages for annotations (fixes #19740)
-rw-r--r-- | compiler/GHC/Rename/HsType.hs | 4 | ||||
-rw-r--r-- | compiler/GHC/Rename/Module.hs | 4 | ||||
-rw-r--r-- | compiler/GHC/Rename/Unbound.hs | 16 | ||||
-rw-r--r-- | testsuite/tests/annotations/should_fail/annfail01.stderr | 5 | ||||
-rw-r--r-- | testsuite/tests/annotations/should_fail/annfail02.stderr | 6 | ||||
-rw-r--r-- | testsuite/tests/annotations/should_fail/annfail11.stderr | 9 |
6 files changed, 23 insertions, 21 deletions
diff --git a/compiler/GHC/Rename/HsType.hs b/compiler/GHC/Rename/HsType.hs index e9ee8bb31b..e7a5f9fa5a 100644 --- a/compiler/GHC/Rename/HsType.hs +++ b/compiler/GHC/Rename/HsType.hs @@ -53,7 +53,7 @@ import GHC.Rename.Utils ( HsDocContext(..), inHsDocContext, withHsDocContext , checkShadowedRdrNames ) import GHC.Rename.Fixity ( lookupFieldFixityRn, lookupFixityRn , lookupTyFixityRn ) -import GHC.Rename.Unbound ( notInScopeErr ) +import GHC.Rename.Unbound ( notInScopeErr, WhereLooking(WL_LocalOnly) ) import GHC.Tc.Utils.Monad import GHC.Types.Name.Reader import GHC.Builtin.Names @@ -745,7 +745,7 @@ rnHsTyKi env (XHsType ty) mb_name <- lookupLocalOccRn_maybe rdr_name when (isNothing mb_name) $ addErr $ withHsDocContext (rtke_ctxt env) $ - notInScopeErr rdr_name + notInScopeErr WL_LocalOnly rdr_name rnHsTyKi env ty@(HsExplicitListTy _ ip tys) = do { data_kinds <- xoptM LangExt.DataKinds diff --git a/compiler/GHC/Rename/Module.hs b/compiler/GHC/Rename/Module.hs index 1b54b53716..80384e56d8 100644 --- a/compiler/GHC/Rename/Module.hs +++ b/compiler/GHC/Rename/Module.hs @@ -35,7 +35,7 @@ import GHC.Rename.Utils ( HsDocContext(..), mapFvRn, bindLocalNames , newLocalBndrsRn , withHsDocContext, noNestedForallsContextsErr , addNoNestedForallsContextsErr, checkInferredVars ) -import GHC.Rename.Unbound ( mkUnboundName, notInScopeErr ) +import GHC.Rename.Unbound ( mkUnboundName, notInScopeErr, WhereLooking(WL_Global) ) import GHC.Rename.Names import GHC.Tc.Gen.Annotation ( annCtxt ) import GHC.Tc.Utils.Monad @@ -1347,7 +1347,7 @@ badRuleLhsErr name lhs bad_e text "LHS must be of form (f e1 .. en) where f is not forall'd" where err = case bad_e of - HsUnboundVar _ uv -> notInScopeErr (mkRdrUnqual uv) + HsUnboundVar _ uv -> notInScopeErr WL_Global (mkRdrUnqual uv) _ -> text "Illegal expression:" <+> ppr bad_e {- ************************************************************** diff --git a/compiler/GHC/Rename/Unbound.hs b/compiler/GHC/Rename/Unbound.hs index ab651b93a7..f4c09dbe4c 100644 --- a/compiler/GHC/Rename/Unbound.hs +++ b/compiler/GHC/Rename/Unbound.hs @@ -72,7 +72,7 @@ unboundNameX :: WhereLooking -> RdrName -> SDoc -> RnM Name unboundNameX where_look rdr_name extra = do { dflags <- getDynFlags ; let show_helpful_errors = gopt Opt_HelpfulErrors dflags - err = notInScopeErr rdr_name $$ extra + err = notInScopeErr where_look rdr_name $$ extra ; if not show_helpful_errors then addErr err else do { local_env <- getLocalRdrEnv @@ -86,12 +86,13 @@ unboundNameX where_look rdr_name extra ; addErr (err $$ suggestions) } ; return (mkUnboundNameRdr rdr_name) } -notInScopeErr :: RdrName -> SDoc -notInScopeErr rdr_name - = case isExact_maybe rdr_name of - Just name -> exactNameErr name - Nothing -> hang (text "Not in scope:") - 2 (what <+> quotes (ppr rdr_name)) +notInScopeErr :: WhereLooking -> RdrName -> SDoc +notInScopeErr where_look rdr_name + | Just name <- isExact_maybe rdr_name = exactNameErr name + | WL_LocalTop <- where_look = hang (text "No top-level binding for") + 2 (what <+> quotes (ppr rdr_name) <+> text "in this module") + | otherwise = hang (text "Not in scope:") + 2 (what <+> quotes (ppr rdr_name)) where what = pprNonVarNameSpace (occNameSpace (rdrNameOcc rdr_name)) @@ -250,6 +251,7 @@ importSuggestions :: WhereLooking -> ImportAvails -> RdrName -> SDoc importSuggestions where_look global_env hpt currMod imports rdr_name | WL_LocalOnly <- where_look = Outputable.empty + | WL_LocalTop <- where_look = Outputable.empty | not (isQual rdr_name || isUnqual rdr_name) = Outputable.empty | null interesting_imports , Just name <- mod_name diff --git a/testsuite/tests/annotations/should_fail/annfail01.stderr b/testsuite/tests/annotations/should_fail/annfail01.stderr index f3f5a75740..0aa033fe43 100644 --- a/testsuite/tests/annotations/should_fail/annfail01.stderr +++ b/testsuite/tests/annotations/should_fail/annfail01.stderr @@ -1,8 +1,9 @@ annfail01.hs:4:14: - Not in scope: type constructor or class ‘Foo’ + No top-level binding for + type constructor or class ‘Foo’ in this module In the annotation: {-# ANN type Foo (1 :: Int) #-} annfail01.hs:5:9: - Not in scope: ‘f’ + No top-level binding for ‘f’ in this module In the annotation: {-# ANN f (1 :: Int) #-} diff --git a/testsuite/tests/annotations/should_fail/annfail02.stderr b/testsuite/tests/annotations/should_fail/annfail02.stderr index 0b1e556739..3c29ec743f 100644 --- a/testsuite/tests/annotations/should_fail/annfail02.stderr +++ b/testsuite/tests/annotations/should_fail/annfail02.stderr @@ -1,8 +1,10 @@ annfail02.hs:6:9: - Not in scope: data constructor ‘Foo’ + No top-level binding for + data constructor ‘Foo’ in this module In the annotation: {-# ANN Foo (1 :: Int) #-} annfail02.hs:7:14: - Not in scope: type constructor or class ‘Bar’ + No top-level binding for + type constructor or class ‘Bar’ in this module In the annotation: {-# ANN type Bar (2 :: Int) #-} diff --git a/testsuite/tests/annotations/should_fail/annfail11.stderr b/testsuite/tests/annotations/should_fail/annfail11.stderr index a1c2e3fd24..d110fdda29 100644 --- a/testsuite/tests/annotations/should_fail/annfail11.stderr +++ b/testsuite/tests/annotations/should_fail/annfail11.stderr @@ -1,14 +1,11 @@ annfail11.hs:3:9: error: - Not in scope: ‘length’ - Perhaps you want to add ‘length’ to the import list - in the import of ‘Prelude’ (annfail11.hs:1:8-16). + No top-level binding for ‘length’ in this module In the annotation: {-# ANN length "Cannot annotate other modules yet" #-} annfail11.hs:4:14: error: - Not in scope: type constructor or class ‘Integer’ - Perhaps you want to add ‘Integer’ to the import list - in the import of ‘Prelude’ (annfail11.hs:1:8-16). + No top-level binding for + type constructor or class ‘Integer’ in this module In the annotation: {-# ANN type Integer "Cannot annotate other modules yet" #-} |