Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The fun x -> body expression in Typedtree receives the attrbitutes of the body #6737

vicuna opened this issue Dec 29, 2014 · 2 comments


Copy link

@vicuna vicuna commented Dec 29, 2014

Original bug ID: 6737
Reporter: oleg
Assigned to: @alainfrisch
Status: closed (set by @xavierleroy on 2016-12-07T10:47:02Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 4.02.1
Fixed in version: 4.03.0+dev / +beta1
Category: typing
Monitored by: @gasche

Bug description

Consider the following lines from typing/

| Pexp_fun (l, None, spat, sexp) ->
type_function ?in_function loc sexp.pexp_attributes env ty_expected
l [{pc_lhs=spat; pc_guard=None; pc_rhs=sexp}]
| Pexp_function caselist ->
type_function ?in_function
loc sexp.pexp_attributes env ty_expected "" caselist

When type-checking the Pexp_function, the resulting Texp_function node will receive
sexp.pexp_attributes, which are the attributes of the whole function expression.
On the other hand, in case of Pexp_fun, the resulting Text_function node will receive sexp.pexp_attributes -- which now refers to the attributes of the body
of the function rather than the attributes of the entire fun x -> body expression. Note that the identifier sexp is shadowed in the Pexp_fun clause.
This is an inconsistent, and seemingly wrong behavior (and yes, it affects me directly).

Copy link

@vicuna vicuna commented Jan 6, 2015

Comment author: @alainfrisch

Thanks Oleg. This is now fixed in trunk, commit 15763. There is some more work to do to keep proper attributes in presence of optional arguments with default values.

Out of curiosity, what is your use for attributes on Typedtree?

Copy link

@vicuna vicuna commented Jan 6, 2015

Comment author: @alainfrisch

Commit 15764 fixes the issue with default value on optional arguments. (The Typedtree representation of such default values remains a little bit ugly. I would prefer a more direct type-checking of that construction, without encoding, and a proper representation in the Typedtree.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

2 participants