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

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

Comments

Projects
None yet
4 participants
@jruderman
Contributor

jruderman commented Jan 8, 2012

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

This comment has been minimized.

Show comment
Hide comment
@graydon

graydon Feb 15, 2012

Contributor

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.

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@brson

brson Jul 31, 2012

Contributor

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;
}
Contributor

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

This comment has been minimized.

Show comment
Hide comment
@catamorphism

catamorphism Oct 25, 2012

Contributor

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

Contributor

catamorphism commented Oct 25, 2012

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

catamorphism added a commit that referenced this issue Oct 30, 2012

Preserve parenthesization in the AST
for better pretty-printing, as per #1458
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment