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

PPrint instance for infix operators incorrect #571

Open
mieszko opened this issue Jul 4, 2023 · 1 comment
Open

PPrint instance for infix operators incorrect #571

mieszko opened this issue Jul 4, 2023 · 1 comment

Comments

@mieszko
Copy link
Collaborator

mieszko commented Jul 4, 2023

Pretty-printing BH code that has infix operators at different precedences is bugged.

Example input:

package Foo where

foo :: Integer
foo = 1 + 2 * 3 + 4

bar :: Integer
bar = 1 + (2 * 3) + 4

baz :: Integer
baz = (1 + 2) * 3 + 4

qux :: Integer
qux = 1 + 2 * (3 + 4)

Compiling with -dparsed yields:

package Foo where {
foo :: Integer;
foo =  1 + 2 * 3 + 4;;

bar :: Integer;
bar =  1 + 2 * 3 + 4;;

baz :: Integer;
baz =  1 + 2 * 3 + 4;;

qux :: Integer;
qux =  1 + 2 * 3 + 4;
}

which loses all the precedence information from the parens, so if it's fed back to bsc it produces different semantics.

This is related to #568 (although that is a separate CSyntax cons); they should probably be fixed together.

@RyanGlScott
Copy link
Contributor

The same issue also affects BSV. Given this code:

package Foo;

Integer foo;
foo = 1 + 2 * 3 + 4;

Integer bar;
bar = 1 + (2 * 3) + 4;

Integer baz;
baz = (1 + 2) * 3 + 4;

Integer qux;
qux = 1 + 2 * (3 + 4);

endpackage

Compiling this with -dparsed yields:

package Foo;
Integer foo;
foo = 1 + 2 * 3 + 4;

Integer bar;
bar = 1 + 2 * 3 + 4;

Integer baz;
baz = 1 + 2 * 3 + 4;

Integer qux;
qux = 1 + 2 * 3 + 4;

endpackage: Foo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants