Commit d2ea7f94 authored by Ben Gamari's avatar Ben Gamari Committed by Ben Gamari

Hide derived OccNames from user

This hides derived OccNames from the Names returned from
runDeclsWithLocation and clarifies the documentation. This is done to
ensure that these names (originating from, e.g., derived Generic
instances and type representation bindings) don't show up in ghci output
when run with `:set +t`. This fixes #11051.

Test Plan: Validate with included tests

Reviewers: austin

Reviewed By: austin

Subscribers: thomie, hvr

Differential Revision:

GHC Trac Issues: #11051
parent cbc03f1c
......@@ -235,8 +235,9 @@ runStmtWithLocation source linenumber expr step = do
runDecls :: GhcMonad m => String -> m [Name]
runDecls = runDeclsWithLocation "<interactive>" 1
:: GhcMonad m => String -> Int -> String -> m [Name]
-- | Run some declarations and return any user-visible names that were brought
-- into scope.
runDeclsWithLocation :: GhcMonad m => String -> Int -> String -> m [Name]
runDeclsWithLocation source linenumber expr =
hsc_env <- getSession
......@@ -246,7 +247,8 @@ runDeclsWithLocation source linenumber expr =
hsc_env <- getSession
hsc_env' <- liftIO $ rttiEnvironment hsc_env
modifySession (\_ -> hsc_env')
return (map getName tyThings)
return $ filter (not . isDerivedOccName . nameOccName)
$ map getName tyThings
withVirtualCWD :: GhcMonad m => m a -> m a
-- Ensure that type representation bindings aren't visible to user
:set +t
data Hi
-- ensure that derived Generics types aren't visible to user
:set +t
:set -XDeriveGeneric
import GHC.Generics
data Hello = Hello Int deriving (Eq, Generic)
......@@ -236,4 +236,6 @@ test('T8316', expect_broken(8316), ghci_script, ['T8316.script'])
test('T11252', normal, ghci_script, ['T11252.script'])
test('T10576a', expect_broken(10576), ghci_script, ['T10576a.script'])
test('T10576b', expect_broken(10576), ghci_script, ['T10576b.script'])
\ No newline at end of file
test('T10576b', expect_broken(10576), ghci_script, ['T10576b.script'])
test('T11051a', normal, ghci_script, ['T11051a.script'])
test('T11051b', normal, ghci_script, ['T11051b.script'])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment