summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorSimon Peyton Jones <simonpj@microsoft.com>2020-02-07 15:26:44 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-02-28 22:03:23 -0500
commit66f5d6d634698ce054a9b9ce0c53ce9682f6f042 (patch)
tree24225b89347cb0f32cff1f3921d71305f5fbdaab /compiler
parentf97d1fb614ff7638d13eb7c552d2a72fce4c613a (diff)
downloadhaskell-66f5d6d634698ce054a9b9ce0c53ce9682f6f042.tar.gz
Improve error handling for VTA + deferred type errors
This fixes #17792 See Note [VTA for out-of-scope functions] in TcExpr
Diffstat (limited to 'compiler')
-rw-r--r--compiler/typecheck/TcExpr.hs40
1 files changed, 19 insertions, 21 deletions
diff --git a/compiler/typecheck/TcExpr.hs b/compiler/typecheck/TcExpr.hs
index f5e92ffe7d..688e3797dc 100644
--- a/compiler/typecheck/TcExpr.hs
+++ b/compiler/typecheck/TcExpr.hs
@@ -1081,10 +1081,6 @@ isHsValArg (HsValArg {}) = True
isHsValArg (HsTypeArg {}) = False
isHsValArg (HsArgPar {}) = False
-isHsTypeArg :: HsArg tm ty -> Bool
-isHsTypeArg (HsTypeArg {}) = True
-isHsTypeArg _ = False
-
isArgPar :: HsArg tm ty -> Bool
isArgPar (HsArgPar {}) = True
isArgPar (HsValArg {}) = False
@@ -1219,14 +1215,6 @@ tcArgs :: LHsExpr GhcRn -- ^ The function itself (for err msgs only)
-> TcM (HsWrapper, [LHsExprArgOut], TcSigmaType)
-- ^ (a wrapper for the function, the tc'd args, result type)
tcArgs fun orig_fun_ty fun_orig orig_args herald
- | fun_is_out_of_scope
- , any isHsTypeArg orig_args
- = failM -- See Note [VTA for out-of-scope functions]
- -- We have /already/ emitted a CHoleCan constraint (in tcInferFun),
- -- which will later cough up a "Variable not in scope error", so
- -- we can simply fail now, avoiding a confusing error cascade
-
- | otherwise
= go [] 1 orig_fun_ty orig_args
where
-- Don't count visible type arguments when determining how many arguments
@@ -1248,6 +1236,10 @@ tcArgs fun orig_fun_ty fun_orig orig_args herald
}
go acc_args n fun_ty (HsTypeArg l hs_ty_arg : args)
+ | fun_is_out_of_scope -- See Note [VTA for out-of-scope functions]
+ = go acc_args (n+1) fun_ty args
+
+ | otherwise
= do { (wrap1, upsilon_ty) <- topInstantiateInferred fun_orig fun_ty
-- wrap1 :: fun_ty "->" upsilon_ty
; case tcSplitForAllTy_maybe upsilon_ty of
@@ -1338,17 +1330,23 @@ generate an immediate failure (in tc_app_err), saying that a function
of type 'alpha' can't be applied to Bool. That's insane! And indeed
users complain bitterly (#13834, #17150.)
-The right error is the CHoleCan, which reports 'wurble' as out of
-scope, and tries to give its type.
+The right error is the CHoleCan, which has /already/ been emitted by
+tcUnboundId. It later reports 'wurble' as out of scope, and tries to
+give its type.
+
+Fortunately in tcArgs we still have access to the function, so we can
+check if it is a HsUnboundVar. We use this info to simply skip over
+any visible type arguments. We've already inferred the type of the
+function, so we'll /already/ have emitted a CHoleCan constraint;
+failing preserves that constraint.
-Fortunately in tcArgs we still have access to the function, so
-we can check if it is a HsUnboundVar. If so, we simply fail
-immediately. We've already inferred the type of the function,
-so we'll /already/ have emitted a CHoleCan constraint; failing
-preserves that constraint.
+We do /not/ want to fail altogether in this case (via failM) becuase
+that may abandon an entire instance decl, which (in the presence of
+-fdefer-type-errors) leads to leading to #17792.
-A mild shortcoming of this approach is that we thereby
-don't typecheck any of the arguments, but so be it.
+Downside; the typechecked term has lost its visible type arguments; we
+don't even kind-check them. But let's jump that bridge if we come to
+it. Meanwhile, let's not crash!
Note [Visible type application zonk]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~