@@ -144,8 +144,8 @@ buildTC ist info emode opts fn tm
144 where pattern = emode == ELHS
144 where pattern = emode == ELHS
146-- return whether arguments of the given constructor name can be
146-- 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
147+-- matched on. If they're polymorphic, no, unless the type has beed made
148−-- return type, then no, otherwise yes.
148+-- concrete by the time we get around to elaborating the argument.
149getUnmatchable :: Context -> Name -> [Bool]
149getUnmatchable :: Context -> Name -> [Bool]
150getUnmatchable ctxt n | isDConName n ctxt && n /= inferCon
150getUnmatchable ctxt n | isDConName n ctxt && n /= inferCon
151 = case lookupTyExact n ctxt of
151 = case lookupTyExact n ctxt of
@@ -159,10 +159,7 @@ getUnmatchable ctxt n | isDConName n ctxt && n /= inferCon
159 checkArgs env' (intersect env (refsIn t) : ns)
159 checkArgs env' (intersect env (refsIn t) : ns)
160 (instantiate (P Bound n t) sc)
160 (instantiate (P Bound n t) sc)
161 checkArgs env ns t
161 checkArgs env ns t
162− = map (anyMissing (intersect env (refsIn t))) (reverse ns)
162+ = map (not . null) (reverse ns)
164− anyMissing tns [] = False
165− anyMissing tns (x : xs) = not (x `elem` tns) || anyMissing tns xs
167getUnmatchable ctxt n = []
164getUnmatchable ctxt n = []
@@ -175,6 +172,16 @@ data ElabCtxt = ElabCtxt { e_inarg :: Bool,
176initElabCtxt = ElabCtxt False False False False False
173initElabCtxt = ElabCtxt False False False False False
175+goal_polymorphic :: ElabD Bool
179+ P _ n _ -> do env <- get_env
180+ case lookup n env of
181+ Nothing -> return False
178-- Returns the set of declarations we need to add to complete the definition
185-- Returns the set of declarations we need to add to complete the definition
179-- (most likely case blocks to elaborate)
186-- (most likely case blocks to elaborate)
@@ -1098,9 +1105,11 @@ elab ist info emode opts fn tm
1098 -- traceWhen (not (null cs)) (show ty ++ "\n" ++ showImp True t) $
1105 -- traceWhen (not (null cs)) (show ty ++ "\n" ++ showImp True t) $
1099 do focus holeName;
1106 do focus holeName;
1100 g <- goal
1107 g <- goal
1108+ -- Can't pattern match on polymorphic goals
1109+ poly <- goal_polymorphic
1101 ulog <- getUnifyLog
1110 ulog <- getUnifyLog
1102 traceWhen ulog ("Elaborating argument " ++ show (argName, holeName, g)) $
1111 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
1104 return failed
1113 return failed
1105 done_elaborating_arg f argName
1114 done_elaborating_arg f argName
1106 elabArgs ist ina failed fc r f ns force args
1115 elabArgs ist ina failed fc r f ns force args