Commit edf54d72 authored by Simon Peyton Jones's avatar Simon Peyton Jones
Browse files

Do not use defaulting in ambiguity check

This fixes Trac #11947.  See TcSimplify
Note [No defaulting in the ambiguity check]
parent f02af79e
......@@ -384,13 +384,25 @@ How is this implemented? It's complicated! So we'll step through it all:
7) `HscMain.tcRnModule'` -- Reads `tcg_safeInfer` after type-checking, calling
`HscMain.markUnsafeInfer` (passing the reason along) when safe-inferrence
failed.
Note [No defaulting in the ambiguity check]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When simplifying constraints for the ambiguity check, we use
solveWantedsAndDrop, not simpl_top, so that we do no defaulting.
Trac #11947 was an example:
f :: Num a => Int -> Int
This is ambiguous of course, but we don't want to default the
(Num alpha) constraint to (Num Int)! Doing so gives a defaulting
warning, but no error.
-}
------------------
simplifyAmbiguityCheck :: Type -> WantedConstraints -> TcM ()
simplifyAmbiguityCheck ty wanteds
= do { traceTc "simplifyAmbiguityCheck {" (text "type = " <+> ppr ty $$ text "wanted = " <+> ppr wanteds)
; (final_wc, _) <- runTcS $ simpl_top wanteds
; (final_wc, _) <- runTcS $ solveWantedsAndDrop wanteds
-- NB: no defaulting! See Note [No defaulting in the ambiguity check]
; traceTc "End simplifyAmbiguityCheck }" empty
-- Normally report all errors; but with -XAllowAmbiguousTypes
......
{-# LANGUAGE TypeApplications, ScopedTypeVariables, AllowAmbiguousTypes #-}
module T11947 where
theFloatDigits :: forall a. RealFloat a => Int
-- The type is ambiguous
theFloatDigits = floatDigits (undefined @_ @a)
foo :: IO ()
foo = print (theFloatDigits @Double, theFloatDigits @Float)
-- But the applications are not
......@@ -514,3 +514,4 @@ test('T11754', normal, compile, [''])
test('T11811', normal, compile, [''])
test('T11793', normal, compile, [''])
test('T11348', normal, compile, [''])
test('T11947', normal, compile, [''])
{-# LANGUAGE TypeApplications, ScopedTypeVariables #-}
module T11947 where
theFloatDigits :: forall a. RealFloat a => Int
-- The type is ambiguous, despite potential defaulting
theFloatDigits = floatDigits (undefined @_ @a)
T11947a.hs:4:19: error:
• Could not deduce (RealFloat a0)
from the context: RealFloat a
bound by the type signature for:
theFloatDigits :: RealFloat a => Int
at T11947a.hs:4:19-46
The type variable ‘a0’ is ambiguous
• In the ambiguity check for ‘theFloatDigits’
To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
In the type signature:
theFloatDigits :: forall a. RealFloat a => Int
......@@ -414,3 +414,4 @@ test('T11723', normal, compile_fail, [''])
test('T11724', normal, compile_fail, [''])
test('BadUnboxedTuple', normal, compile_fail, [''])
test('T11698', normal, compile_fail, [''])
test('T11947a', normal, compile_fail, [''])
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