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

Pprintast omits parens for `List ((`String "A")::[]) #6546

Closed
vicuna opened this issue Sep 6, 2014 · 3 comments

Comments

Projects
None yet
2 participants
@vicuna
Copy link

commented Sep 6, 2014

Original bug ID: 6546
Reporter: @whitequark
Assigned to: @gasche
Status: closed (set by @xavierleroy on 2016-12-07T10:34:48Z)
Resolution: fixed
Priority: normal
Severity: minor
Version: 4.02.0+beta1 / +rc1
Target version: 4.02.2+dev / +rc1
Category: ~DO NOT USE (was: OCaml general)
Monitored by: @gasche @hcarty

Bug description

It is printed back as

`List (`String "A")::[]
@vicuna

This comment has been minimized.

Copy link
Author

commented Sep 18, 2014

Comment author: @gasche

I cannot reproduce this using the -dsource flag (which, if I understand correctly, is what uses Pprintast).

My test file test2.ml is the following:
let f x = List ((String "A"):: [])
let f x = List ((String "A")::x)

On my machine, "ocamlc -dsource test2.ml" under both 4.01.0 and the current 4.02 branch prints the following, which seems correct:

let f x = List [String "A"]
let f x = List ((String "A") :: x)

@vicuna

This comment has been minimized.

Copy link
Author

commented Sep 19, 2014

Comment author: @whitequark

Oh, it seems this only happens in patterns. E.g. try:

match (assert false) with `List ((`String "tea")::x::[]) -> ()
@vicuna

This comment has been minimized.

Copy link
Author

commented Sep 19, 2014

Comment author: @gasche

Thanks, fixed in 4.02.

The pprintast code is doing the non-trivial job of guessing parenthesis and syntactic resugaring, and not really pleasant to work with. The current codebase does not handle resugaring "::" in the same way in expression and patterns, and one may wonder why, but "if it ain't broke, don't fix it" -- we have better fish to fry.

@vicuna vicuna closed this Dec 7, 2016

@vicuna vicuna added this to the 4.02.2 milestone 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.