Skip to content
This repository

pp omits parens needed to disambiguate call-with-block sugar #1458

Closed
jruderman opened this Issue January 07, 2012 · 3 comments

4 participants

Jesse Ruderman Tim Chevalier Graydon Hoare Brian Anderson
Jesse Ruderman
Collaborator

This is a passing Rust program:

fn plus_one(f: block() -> int) -> int {
  ret f() + 1;
}

fn ret_plus_one() -> fn(block() -> int) -> int {
  ret plus_one;
}

fn main() {
  let z = (ret_plus_one()) {|| 2};
  assert z == 3;
}

The pretty-printer omits the parens around the call in main, so the result of pretty-printing does not compile.

Graydon Hoare
Owner

Goodness!

I wonder if it might make sense to just hold on to any parens in the input, as AST nodes. expr_paren(@expr) is likely a harmless no-op at almost every level of the compiler pipeline and it would relieve the pretty printer from having to work out the (sometimes quite complicated) rules regarding the "proper" amount of parenthesization required to reproduce the input unambiguously.

Brian Anderson
Owner
brson commented July 30, 2012

Still a problem with do

fn plus_one(f: fn() -> int) -> int {
  ret f() + 1;
}

fn ret_plus_one() -> fn(fn() -> int) -> int {
  ret plus_one;
}

fn main() {
    let z = do (ret_plus_one()) || { 2 };
    assert z == 3;
}
Tim Chevalier
Collaborator

@brson 's example doesn't parse at all now. I filed #3861

Tim Chevalier catamorphism referenced this issue from a commit October 27, 2012
Commit has since been removed from the repository and is no longer available.
Tim Chevalier catamorphism referenced this issue from a commit October 27, 2012
Tim Chevalier Preserve parenthesization in the AST
for better pretty-printing, as per #1458
cf50e1d
Tim Chevalier catamorphism closed this in 4e5865f October 30, 2012
Jay Anderson jayanderson referenced this issue from a commit November 10, 2013
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.