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

Closed
vicuna opened this issue Dec 29, 2014 · 2 comments

Comments

Projects
None yet
2 participants
@vicuna
Copy link

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/typecore.ml

| 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).

@vicuna

This comment has been minimized.

Copy link
Author

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?

@vicuna

This comment has been minimized.

Copy link
Author

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.)

@vicuna vicuna closed this Dec 7, 2016

@vicuna vicuna added the typing label Mar 14, 2019

@vicuna vicuna added the bug label Mar 20, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.