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

Item attributes are allowed on regular let bindings #6454

Closed
vicuna opened this issue Jun 9, 2014 · 7 comments
Closed

Item attributes are allowed on regular let bindings #6454

vicuna opened this issue Jun 9, 2014 · 7 comments
Assignees
Labels

Comments

@vicuna
Copy link

vicuna commented Jun 9, 2014

Original bug ID: 6454
Reporter: @lpw25
Assigned to: @alainfrisch
Status: closed (set by @xavierleroy on 2015-12-11T18:28:10Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 4.02.0+dev
Category: ~DO NOT USE (was: OCaml general)
Tags: patch
Monitored by: @hcarty

Bug description

Item attributes are allowed on non-item let bindings. For example:

# let x =
    let g x = x [@@foo] in g 5;;
  val x : int = 5

the attached patch fixes this:

# let x =
    let g x = x [@@foo] in g 5;;
  Characters 24-27:
      let g x = x [@@foo] in g 5;;
                  ^^^
Error: Syntax error

File attachments

@vicuna
Copy link
Author

vicuna commented Jun 10, 2014

Comment author: @alainfrisch

Wouldn't it be simpler to reject item attributes with an explicit check in the semantic action, rather than tweaking the grammar?

@vicuna
Copy link
Author

vicuna commented Jun 10, 2014

Comment author: @lpw25

I considered that but, since the attributes don't carry location information, getting a good error message that way looked like more work than tweaking the grammar.

@vicuna
Copy link
Author

vicuna commented Jun 10, 2014

Comment author: @alainfrisch

With the attached patch:

# let x =
          let g x = x [@@foo] in g 5;;
              ^^^^^^^^^^^^^^^

Error: Syntax error: @@-attribute not expected.

I don't think that the less precise location is necessarily a bad thing. Do you agree?

@vicuna
Copy link
Author

vicuna commented Jun 10, 2014

Comment author: @lpw25

I don't think that the less precise location is necessarily a bad thing. Do you agree?

In exchange for the simpler code it seems reasonable. I think it should be "item attribute" rather than "@@-attribute".

@vicuna
Copy link
Author

vicuna commented Jun 10, 2014

Comment author: @alainfrisch

Ok, I've adapted the wording and committed that to 4.02 (commit 14982).

@vicuna
Copy link
Author

vicuna commented Jul 7, 2014

Comment author: clarus

I was actually using this bug/feature to add attributes on inner lets :).

What is the right syntax to do it now? By the way, this syntax still works with OCaml trunk, I do not know if it is expected.

@vicuna
Copy link
Author

vicuna commented Jul 7, 2014

Comment author: @alainfrisch

What is the right syntax to do it now?

let[@foo] x = ... in ...

or:

(let x = ... in ...)[@foo]

By the way, this syntax still works with OCaml trunk, I do not know if it is expected.

Yes, some recent changes on the 4.02 branch will be back-ported in batch on trunk when 4.02 is released.

@vicuna vicuna closed this as completed Dec 11, 2015
@vicuna vicuna added the bug label Mar 20, 2019
avsm pushed a commit to avsm/ocaml that referenced this issue Jun 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants