Fix 'unsolved constraints' in GHCi
authorSimon Peyton Jones <simonpj@microsoft.com>
Mon, 27 Mar 2017 13:32:43 +0000 (14:32 +0100)
committerSimon Peyton Jones <simonpj@microsoft.com>
Mon, 27 Mar 2017 15:31:04 +0000 (16:31 +0100)
In initTc, if the computation fails with an exception, we
should not complain about unsolved constraints.

Fixes Trac #13466.

compiler/typecheck/TcRnMonad.hs
testsuite/tests/ghci/scripts/T13466.script [new file with mode: 0644]
testsuite/tests/ghci/scripts/T13466.stderr [new file with mode: 0644]
testsuite/tests/ghci/scripts/all.T

index 3404ce7..2b73812 100644 (file)
@@ -336,11 +336,14 @@ initTcWithGbl hsc_env gbl_env loc do_this
                           Right res -> return (Just res)
                           Left _    -> return Nothing }
 
-        -- Check for unsolved constraints
+      -- Check for unsolved constraints
+      -- If we succeed (maybe_res = Just r), there should be
+      -- no unsolved constraints.  But if we exit via an
+      -- exception (maybe_res = Nothing), we may have skipped
+      -- solving, so don't panic then (Trac #13466)
       ; lie <- readIORef (tcl_lie lcl_env)
-      ; if isEmptyWC lie
-           then return ()
-           else pprPanic "initTc: unsolved constraints" (ppr lie)
+      ; when (isJust maybe_res && not (isEmptyWC lie)) $
+        pprPanic "initTc: unsolved constraints" (ppr lie)
 
         -- Collect any error messages
       ; msgs <- readIORef (tcl_errs lcl_env)
diff --git a/testsuite/tests/ghci/scripts/T13466.script b/testsuite/tests/ghci/scripts/T13466.script
new file mode 100644 (file)
index 0000000..0310fac
--- /dev/null
@@ -0,0 +1,2 @@
+:set -XTypeApplications
+:t out_of_scope @[]
diff --git a/testsuite/tests/ghci/scripts/T13466.stderr b/testsuite/tests/ghci/scripts/T13466.stderr
new file mode 100644 (file)
index 0000000..ba3d5fd
--- /dev/null
@@ -0,0 +1,5 @@
+
+<interactive>:1:1: error:
+    • Cannot apply expression of type ‘t1’
+      to a visible type argument ‘[]’
+    • In the expression: out_of_scope @[]
index 20bc5ae..00d8d81 100755 (executable)
@@ -250,3 +250,4 @@ test('T12550', normal, ghci_script, ['T12550.script'])
 test('StaticPtr', normal, ghci_script, ['StaticPtr.script'])
 test('T13202', normal, ghci_script, ['T13202.script'])
 test('T13202a', normal, ghci_script, ['T13202a.script'])
+test('T13466', normal, ghci_script, ['T13466.script'])