Commit 1c062b79 authored by Simon Peyton Jones's avatar Simon Peyton Jones

Simplify rnLHsInstType

This patch is preparatory for the main fix for Trac #13324

Here, we simplify rnLHsInstType so that it does not try
to figure out the class name.  This turns out to have a good
(rather than bad) effect on error messages, and it prepares
the way for the main event.

Plus, less code!
parent 6ee831f2
......@@ -326,20 +326,8 @@ rnImplicitBndrs bind_free_tvs doc
rnLHsInstType :: SDoc -> LHsSigType GhcPs -> RnM (LHsSigType GhcRn, FreeVars)
-- Rename the type in an instance or standalone deriving decl
-- The 'doc_str' is "an instance declaration" or "a VECTORISE pragma"
rnLHsInstType doc_str inst_ty
| Just cls <- getLHsInstDeclClass_maybe inst_ty
, isTcOcc (rdrNameOcc (unLoc cls))
-- The guards check that the instance type looks like
-- blah => C ty1 .. tyn
= do { let full_doc = doc_str <+> text "for" <+> quotes (ppr cls)
; rnHsSigType (GenericCtx full_doc) inst_ty }
| otherwise -- The instance is malformed, but we'd still like
-- to make progress rather than failing outright, so
-- we report more errors. So we rename it anyway.
= do { addErrAt (getLoc (hsSigType inst_ty)) $
text "Malformed instance:" <+> ppr inst_ty
; rnHsSigType (GenericCtx doc_str) inst_ty }
-- Do not try to decompose the inst_ty in case it is malformed
rnLHsInstType doc inst_ty = rnHsSigType (GenericCtx doc) inst_ty
mk_implicit_bndrs :: [Name] -- implicitly bound
-> a -- payload
......@@ -351,6 +339,7 @@ mk_implicit_bndrs vars body fvs
, hsib_closed = nameSetAll (not . isTyVarName) (vars `delFVs` fvs) }
{- ******************************************************
* *
LHsType and HsType
......
T3811c.hs:6:10: Malformed instance: !Show D
T3811c.hs:6:10: error:
• Unexpected strictness annotation: !Show
strictness annotation cannot appear nested inside a type
• In the instance declaration for ‘!Show D’
WildcardInInstanceHead.hs:7:14: error:
Wildcard ‘_’ not allowed
in an instance declaration for ‘Foo’
in an instance declaration
WildcardInStandaloneDeriving.hs:4:19: error: Malformed instance: _
WildcardInStandaloneDeriving.hs:4:19: error:
Wildcard ‘_’ not allowed
in a deriving declaration
T5513.hs:4:19: Malformed instance: lowercase_name a
T5513.hs:4:19: error:
• Instance head is not headed by a class
• In the stand-alone deriving instance for ‘lowercase_name a’
T5951.hs:8:8: Malformed instance: A => B => C
T5951.hs:8:8: error:
• Expecting one more argument to ‘A’
Expected a constraint, but ‘A’ has kind ‘* -> Constraint’
• In the instance declaration for ‘B => C’
T5951.hs:9:8: error:
• Expecting one more argument to ‘B’
Expected a constraint, but ‘B’ has kind ‘* -> Constraint’
• In the instance declaration for ‘B => C’
T5951.hs:10:8: error:
• Expecting one more argument to ‘C’
Expected a constraint, but ‘C’ has kind ‘* -> Constraint’
• In the instance declaration for ‘B => C’
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