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

Fix: incorrect to_s for Attribute AST node #4098 #4099

Merged
merged 1 commit into from Mar 3, 2017

Conversation

olbat
Copy link
Contributor

@olbat olbat commented Mar 2, 2017

Commas are missing in the result of the to_s method of Attribute nodes so the output is invalid (i.e. @[Foo(a: 1b: 2)]).

$ cat test.cr
require "compiler/crystal/syntax"
ast = Crystal::Parser.parse(%{@[Test(1, 2, n1: 1, n2: 2)]})
puts code = ast.to_s
Crystal::Parser.parse(code)

$ crystal run test.cr
@[Test(1, 2, n1: 1, n2: 2)]

@olbat olbat force-pushed the fix_compiler_to_s_attribute branch from 626313b to bda3efd Compare March 3, 2017 07:31
@olbat
Copy link
Contributor Author

olbat commented Mar 3, 2017

Oops, you're right that's a better way to fix it, done !

olbat referenced this pull request in olbat/crystal Mar 3, 2017
Commas are missing in the result of the `to_s` method of Attribute nodes
so the output is invalid (i.e. `@[Foo(a: 1b: 2)]`).
@str << ", " if printed_arg
named_args.each do |named_arg|
named_args.each_with_index do |named_arg, i|
@str << ", " if printed_arg || i > 0
Copy link
Member

Choose a reason for hiding this comment

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

The variable i is not needed here. And printed_arg = true below can remain. That's the only change needed (you only needed to move exactly one line one position down ^_^)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Again you're right ... So much changes for such a small modification, sorry for that and thank for your time :)

@asterite
Copy link
Member

asterite commented Mar 3, 2017

@olbat I added another request for change. In addition to that, I don't understand why the other specs for lib, alias and type are needed here (they are welcome, but totally unrelated with the issue)

Commas are missing in the result of the `to_s` method of Attribute nodes
so the output is invalid (i.e. `@[Foo(a: 1b: 2)]`).
@olbat
Copy link
Contributor Author

olbat commented Mar 3, 2017

In addition to that, I don't understand why the other specs for lib, alias and type are needed here (they are welcome, but totally unrelated with the issue)

It's related to a discussion in #4098, should I create another pull request for this change ?

@olbat olbat force-pushed the fix_compiler_to_s_attribute branch from bda3efd to a4c5aab Compare March 3, 2017 15:41
@asterite
Copy link
Member

asterite commented Mar 3, 2017

@olbat Ooh... I see. Yes, as another PR is good, thank you!

@asterite asterite merged commit e1cdde8 into crystal-lang:master Mar 3, 2017
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

Successfully merging this pull request may close these issues.

None yet

2 participants