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

Parser: fix a-b -c incorrectly parsed as a - (b - c) #9652

Conversation

asterite
Copy link
Member

@asterite asterite commented Aug 1, 2020

src/compiler/crystal/syntax/parser.cr Outdated Show resolved Hide resolved
src/compiler/crystal/syntax/parser.cr Outdated Show resolved Hide resolved
@asterite asterite force-pushed the bug/plus-or-minus-after-var-is-always-var branch from 665fb7b to c1289a0 Compare August 1, 2020 12:15
Assign.new("c".var, 3.int32),
Call.new(Call.new("a".var, "-", "b".var), "-", "c".var),
])
it_parses "a = 1; b = 2; c = 3; a-b -c", Expressions.new([
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose you wanted to change this to +es :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the difference is there's a space

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. How about specs for + then? :D

while current_char.ascii_whitespace?
next_char_no_column_increment
end
comes_plus_or_minus = current_char == '+' || current_char == '-'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
comes_plus_or_minus = current_char == '+' || current_char == '-'
comes_plus_or_minus = current_char.in?('+', '-')

@asterite asterite closed this Aug 1, 2020
@asterite
Copy link
Member Author

asterite commented Aug 1, 2020

Closing because I'm not sure this is the best way to solve this.

@Sija
Copy link
Contributor

Sija commented Aug 1, 2020

@asterite Perhaps it's not the best but it works, so why to throw the baby with the bathwater?

@asterite
Copy link
Member Author

asterite commented Aug 1, 2020

Nope

@asterite
Copy link
Member Author

asterite commented Aug 1, 2020

Feel free to open a PR with this diff, I won't babysit it.

@straight-shoota
Copy link
Member

There should still be a bug report for this.

@asterite asterite reopened this Aug 19, 2020
@asterite
Copy link
Member Author

I think this one should be merged before 1.0

@asterite asterite added breaking-change kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:parser labels Aug 19, 2020
Copy link
Member

@bcardiff bcardiff left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix seems good enough to me. I've been validating with ast_helper a couple of expressions, trying to break things, but all seems good 👍 .

@bcardiff bcardiff added this to the 1.0.0 milestone Aug 24, 2020
@asterite asterite merged commit 203de4e into crystal-lang:master Aug 24, 2020
@asterite asterite deleted the bug/plus-or-minus-after-var-is-always-var branch August 24, 2020 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:parser
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants