@@ -144,8 +144,8 @@ buildTC ist info emode opts fn tm
144144 where pattern = emode == ELHS
145145
146146-- return whether arguments of the given constructor name can be
147−-- matched on. If they're polymorphic and the type doesn't appear in the
148−-- return type, then no, otherwise yes.
147+-- matched on. If they're polymorphic, no, unless the type has beed made
148+-- concrete by the time we get around to elaborating the argument.
149149getUnmatchable :: Context -> Name -> [Bool]
150150getUnmatchable ctxt n | isDConName n ctxt && n /= inferCon
151151 = case lookupTyExact n ctxt of
@@ -159,10 +159,7 @@ getUnmatchable ctxt n | isDConName n ctxt && n /= inferCon
159159 checkArgs env' (intersect env (refsIn t) : ns)
160160 (instantiate (P Bound n t) sc)
161161 checkArgs env ns t
162− = map (anyMissing (intersect env (refsIn t))) (reverse ns)
163−
164− anyMissing tns [] = False
165− anyMissing tns (x : xs) = not (x `elem` tns) || anyMissing tns xs
162+ = map (not . null) (reverse ns)
166163
167164getUnmatchable ctxt n = []
168165
@@ -175,6 +172,16 @@ data ElabCtxt = ElabCtxt { e_inarg :: Bool,
175172
176173initElabCtxt = ElabCtxt False False False False False
177174
175+goal_polymorphic :: ElabD Bool
176+goal_polymorphic =
177+ do ty <- goal
178+ case ty of
179+ P _ n _ -> do env <- get_env
180+ case lookup n env of
181+ Nothing -> return False
182+ _ -> return True
183+ _ -> return False
184+
178185-- Returns the set of declarations we need to add to complete the definition
179186-- (most likely case blocks to elaborate)
180187
@@ -1098,9 +1105,11 @@ elab ist info emode opts fn tm
10981105 -- traceWhen (not (null cs)) (show ty ++ "\n" ++ showImp True t) $
10991106 do focus holeName;
11001107 g <- goal
1108+ -- Can't pattern match on polymorphic goals
1109+ poly <- goal_polymorphic
11011110 ulog <- getUnifyLog
11021111 traceWhen ulog ("Elaborating argument " ++ show (argName, holeName, g)) $
1103− elab (ina { e_nomatching = unm }) (Just fc) t
1112+ elab (ina { e_nomatching = unm && poly }) (Just fc) t
11041113 return failed
11051114 done_elaborating_arg f argName
11061115 elabArgs ist ina failed fc r f ns force args