[commit: ghc] ghc-7.10: Fix #10495. (3340d30)

git at git.haskell.org git at git.haskell.org
Tue Sep 29 16:09:20 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : ghc-7.10
Link       : http://ghc.haskell.org/trac/ghc/changeset/3340d3035afdc128e12fc64d3af97d76d19edda1/ghc

>---------------------------------------------------------------

commit 3340d3035afdc128e12fc64d3af97d76d19edda1
Author: Richard Eisenberg <eir at cis.upenn.edu>
Date:   Mon Jun 8 15:57:33 2015 -0400

    Fix #10495.
    
    This change means that the intricate reasoning in TcErrors
    around getting messages just right for nominal equalities
    is skipped for representational equalities.


>---------------------------------------------------------------

3340d3035afdc128e12fc64d3af97d76d19edda1
 compiler/typecheck/TcErrors.hs                      | 19 +++++++++++++------
 testsuite/tests/typecheck/should_fail/T10495.hs     |  5 +++++
 testsuite/tests/typecheck/should_fail/T10495.stderr |  6 ++++++
 testsuite/tests/typecheck/should_fail/all.T         |  1 +
 4 files changed, 25 insertions(+), 6 deletions(-)

diff --git a/compiler/typecheck/TcErrors.hs b/compiler/typecheck/TcErrors.hs
index b07fbf9..415346a 100644
--- a/compiler/typecheck/TcErrors.hs
+++ b/compiler/typecheck/TcErrors.hs
@@ -815,6 +815,7 @@ mkTyVarEqErr dflags ctxt extra ct oriented tv1 ty2
                             -- be oriented the other way round;
                             -- see TcCanonical.canEqTyVarTyVar
   || isSigTyVar tv1 && not (isTyVarTy ty2)
+  || ctEqRel ct == ReprEq  -- the cases below don't really apply to ReprEq
   = mkErrorMsg ctxt ct (vcat [ misMatchOrCND ctxt ct oriented ty1 ty2
                              , extraTyVarInfo ctxt tv1 ty2
                              , extra ])
@@ -938,25 +939,31 @@ misMatchOrCND ctxt ct oriented ty1 ty2
     isGivenCt ct
        -- If the equality is unconditionally insoluble
        -- or there is no context, don't report the context
-  = misMatchMsg oriented (ctEqRel ct) ty1 ty2
+  = misMatchMsg oriented eq_rel ty1 ty2
   | otherwise
-  = couldNotDeduce givens ([mkTcEqPred ty1 ty2], orig)
+  = couldNotDeduce givens ([eq_pred], orig)
   where
+    eq_rel = ctEqRel ct
     givens = [ given | given@(_, _, no_eqs, _) <- getUserGivens ctxt, not no_eqs]
              -- Keep only UserGivens that have some equalities
-    orig   = TypeEqOrigin { uo_actual = ty1, uo_expected = ty2 }
+
+    (eq_pred, orig) = case eq_rel of
+      NomEq  -> ( mkTcEqPred ty1 ty2
+                , TypeEqOrigin { uo_actual = ty1, uo_expected = ty2 })
+      ReprEq -> ( mkCoerciblePred ty1 ty2
+                , CoercibleOrigin ty1 ty2 )
 
 couldNotDeduce :: [UserGiven] -> (ThetaType, CtOrigin) -> SDoc
 couldNotDeduce givens (wanteds, orig)
-  = vcat [ addArising orig (ptext (sLit "Could not deduce") <+> pprTheta wanteds)
+  = vcat [ addArising orig (ptext (sLit "Could not deduce:") <+> pprTheta wanteds)
          , vcat (pp_givens givens)]
 
 pp_givens :: [UserGiven] -> [SDoc]
 pp_givens givens
    = case givens of
          []     -> []
-         (g:gs) ->      ppr_given (ptext (sLit "from the context")) g
-                 : map (ppr_given (ptext (sLit "or from"))) gs
+         (g:gs) ->      ppr_given (ptext (sLit "from the context:")) g
+                 : map (ppr_given (ptext (sLit "or from:"))) gs
     where
        ppr_given herald (gs, skol_info, _, loc)
            = hang (herald <+> pprEvVarTheta gs)
diff --git a/testsuite/tests/typecheck/should_fail/T10495.hs b/testsuite/tests/typecheck/should_fail/T10495.hs
new file mode 100644
index 0000000..2573f51
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T10495.hs
@@ -0,0 +1,5 @@
+module T10495 where
+
+import Data.Coerce
+
+foo = coerce
diff --git a/testsuite/tests/typecheck/should_fail/T10495.stderr b/testsuite/tests/typecheck/should_fail/T10495.stderr
new file mode 100644
index 0000000..6e92505
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T10495.stderr
@@ -0,0 +1,6 @@
+
+T10495.hs:5:7: error:
+    Couldn't match representation of type ‘a0’ with that of ‘b0’
+    Relevant bindings include foo :: a0 -> b0 (bound at T10495.hs:5:1)
+    In the expression: coerce
+    In an equation for ‘foo’: foo = coerce
diff --git a/testsuite/tests/typecheck/should_fail/all.T b/testsuite/tests/typecheck/should_fail/all.T
index 95911d1..b6e5867 100644
--- a/testsuite/tests/typecheck/should_fail/all.T
+++ b/testsuite/tests/typecheck/should_fail/all.T
@@ -363,3 +363,4 @@ test('T9858b', normal, compile_fail, [''])
 test('T9858e', normal, compile_fail, [''])
 test('T10534', extra_clean(['T10534a.hi', 'T10534a.o']),
      multimod_compile_fail, ['T10534', '-v0'])
+test('T10495', normal, compile_fail, [''])



More information about the ghc-commits mailing list