@@ -967,7 +967,7 @@ elab ist info emode opts fn tm
967967 -- if the scrutinee is one of the 'args' in env, we should
968968 -- inspect it directly, rather than adding it as a new argument
969969 let newdef = PClauses fc [] cname'
970− (caseBlock fc cname'
970+ (caseBlock fc cname' scr
971971 (map (isScr scr) (reverse args')) opts)
972972 -- elaborate case
973973 updateAux (\e -> e { case_decls = (cname', newdef) : case_decls e } )
@@ -1161,9 +1161,10 @@ elab ist info emode opts fn tm
11611161 isScr (PRef _ n) (n', b) = (n', (n == n', b))
11621162 isScr _ (n', b) = (n', (False, b))
11631163
1164− caseBlock :: FC -> Name ->
1165− [(Name, (Bool, Binder Term))] -> [(PTerm, PTerm)] -> [PClause]
1166− caseBlock fc n env opts
1164+ caseBlock :: FC -> Name
1165+ -> PTerm -- original scrutinee
1166+ -> [(Name, (Bool, Binder Term))] -> [(PTerm, PTerm)] -> [PClause]
1167+ caseBlock fc n scr env opts
11671168 = let args' = findScr env
11681169 args = map mkarg (map getNmScr args') in
11691170 map (mkClause args) opts
@@ -1189,18 +1190,33 @@ elab ist info emode opts fn tm
11891190 mkarg (n, s) = (PRef fc n, s)
11901191 -- may be shadowed names in the new pattern - so replace the
11911192 -- old ones with an _
1193+ -- Also, names which don't appear on the rhs should not be
1194+ -- fixed on the lhs, or this restricts the kind of matching
1195+ -- we can do to non-dependent types.
11921196 mkClause args (l, r)
11931197 = let args' = map (shadowed (allNamesIn l)) args
1198+ args'' = map (implicitable (allNamesIn r ++
1199+ keepscrName scr)) args'
11941200 lhs = PApp (getFC fc l) (PRef NoFC n)
1195− (map (mkLHSarg l) args') in
1201+ (map (mkLHSarg l) args'') in
11961202 PClause (getFC fc l) n lhs [] r []
11971203
1204+ -- Keep scrutinee available if it's just a name (this makes
1205+ -- the names in scope look better when looking at a hole on
1206+ -- the rhs of a case)
1207+ keepscrName (PRef _ n) = [n]
1208+ keepscrName _ = []
1209+
11981210 mkLHSarg l (tm, True) = pexp l
11991211 mkLHSarg l (tm, False) = pexp tm
12001212
12011213 shadowed new (PRef _ n, s) | n `elem` new = (Placeholder, s)
12021214 shadowed new t = t
12031215
1216+ implicitable rhs (PRef _ n, s) | n `notElem` rhs = (Placeholder, s)
1217+ implicitable rhs t = t
1218+
1219+
12041220 getFC d (PApp fc _ _) = fc
12051221 getFC d (PRef fc _) = fc
12061222 getFC d (PAlternative _ (x:_)) = getFC d x