Skip to content

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

Closed
jruderman opened this Issue Jan 8, 2012 · 3 comments

4 participants

@jruderman

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
graydon commented Feb 15, 2012

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.

@brson
brson commented Jul 31, 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;
}
@catamorphism

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

@catamorphism catamorphism added a commit that referenced this issue Oct 30, 2012
@catamorphism catamorphism Preserve parenthesization in the AST
for better pretty-printing, as per #1458
cf50e1d
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.