fix(frontends/lean/elaborator): expression may not be an application due to error recovery

Issue described at https://groups.google.com/forum/#!topic/lean-user/uSSYhgVKKH0
This commit is contained in:
Leonardo de Moura 2017-02-16 21:11:17 -08:00
parent aabc15823c
commit 71950bdf01
2 changed files with 43 additions and 2 deletions

View file

@ -2426,8 +2426,11 @@ expr elaborator::visit_field(expr const & e, optional<expr> const & expected_typ
expr proj = copy_tag(e, mk_constant(full_fname));
expr new_e = copy_tag(e, mk_app(proj, copy_tag(e, mk_as_is(s))));
expr r = visit(new_e, expected_type);
if (auto pos = get_field_notation_field_pos(e))
save_identifier_info(app_fn(r), pos);
if (is_app(r)) {
/* r may be a sorry macro due to error recovery*/
if (auto pos = get_field_notation_field_pos(e))
save_identifier_info(app_fn(r), pos);
}
return r;
}

View file

@ -0,0 +1,38 @@
universe variables u v
structure Category :=
(Obj : Type u)
(Hom : Obj → Obj → Type v)
universe variables u1 v1 u2 v2
structure Functor (C : Category.{ u1 v1 }) (D : Category.{ u2 v2 }) :=
(onObjects : C^.Obj → D^.Obj)
@[reducible] definition ProductCategory (C : Category) (D : Category) :
Category :=
{
Obj := C^.Obj × D^.Obj,
Hom := (λ X Y : C^.Obj × D^.Obj, C^.Hom (X^.fst) (Y^.fst) × D^.Hom (X^.snd) (Y^.snd))
}
namespace ProductCategory
notation C `×` D := ProductCategory C D
end ProductCategory
@[reducible] definition TensorProduct ( C: Category ) := Functor ( C × C ) C
structure MonoidalCategory
extends carrier : Category :=
(tensor : TensorProduct carrier)
instance MonoidalCategory_coercion : has_coe MonoidalCategory Category :=
⟨MonoidalCategory.to_Category⟩
-- Convenience methods which take two arguments, rather than a pair. (This seems to often help the elaborator avoid getting stuck on `prod.mk`.)
@[reducible] definition MonoidalCategory.tensorObjects { C : MonoidalCategory } ( X Y : C^.Obj ) : C^.Obj := C^.tensor^.onObjects (X, Y)
definition tensor_on_left { C: MonoidalCategory.{u v} } ( Z: C^.Obj ) : Functor.{u v u v} C C :=
{
onObjects := λ X, C^.tensorObjects Z X
}