Hide derived OccNames from user
authorBen Gamari <bgamari.foss@gmail.com>
Mon, 18 Jan 2016 22:12:51 +0000 (23:12 +0100)
committerBen Gamari <ben@smart-cactus.org>
Mon, 18 Jan 2016 23:07:33 +0000 (00:07 +0100)
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: https://phabricator.haskell.org/D1794

GHC Trac Issues: #11051

compiler/main/InteractiveEval.hs
testsuite/tests/ghci/scripts/T11051a.script [new file with mode: 0644]
testsuite/tests/ghci/scripts/T11051a.stdout [new file with mode: 0644]
testsuite/tests/ghci/scripts/T11051b.script [new file with mode: 0644]
testsuite/tests/ghci/scripts/T11051b.stdout [new file with mode: 0644]
testsuite/tests/ghci/scripts/all.T

index 47d282e..6356928 100644 (file)
@@ -235,8 +235,9 @@ runStmtWithLocation source linenumber expr step = do
 runDecls :: GhcMonad m => String -> m [Name]
 runDecls = runDeclsWithLocation "<interactive>" 1
 
-runDeclsWithLocation
- :: 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 =
   do
     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
diff --git a/testsuite/tests/ghci/scripts/T11051a.script b/testsuite/tests/ghci/scripts/T11051a.script
new file mode 100644 (file)
index 0000000..96fadeb
--- /dev/null
@@ -0,0 +1,3 @@
+-- Ensure that type representation bindings aren't visible to user
+:set +t
+data Hi
diff --git a/testsuite/tests/ghci/scripts/T11051a.stdout b/testsuite/tests/ghci/scripts/T11051a.stdout
new file mode 100644 (file)
index 0000000..44fb93c
--- /dev/null
@@ -0,0 +1 @@
+data Hi
diff --git a/testsuite/tests/ghci/scripts/T11051b.script b/testsuite/tests/ghci/scripts/T11051b.script
new file mode 100644 (file)
index 0000000..dd42074
--- /dev/null
@@ -0,0 +1,5 @@
+-- ensure that derived Generics types aren't visible to user
+:set +t
+:set -XDeriveGeneric
+import GHC.Generics
+data Hello = Hello Int deriving (Eq, Generic)
diff --git a/testsuite/tests/ghci/scripts/T11051b.stdout b/testsuite/tests/ghci/scripts/T11051b.stdout
new file mode 100644 (file)
index 0000000..7eb3f08
--- /dev/null
@@ -0,0 +1 @@
+data Hello = Hello Int
index c1bda85..7a6225c 100755 (executable)
@@ -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'])