Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion spec/compiler/parser/to_s_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ describe "ASTNode#to_s" do
expect_to_s "def foo(@[Foo] x, @[Bar] **args, @[Baz] &block)\nend"
expect_to_s "{% [1, 2, 3].each { |v| pp(v) } %}", "{% [1, 2, 3].each do |v| pp(v) end %}"
expect_to_s "{%\n [1, 2, 3].each { |v| pp(v) }\n%}", "{%\n [1, 2, 3].each do |v| pp(v) end\n%}"
expect_to_s "{% [1, 2, 3].find(&.!.even?) %}", "{% [1, 2, 3].find() do |__arg0| !__arg0.even? end %}"
expect_to_s "{% [1, 2, 3].find(&.even?.!) %}", "{% [1, 2, 3].find() do |__arg0| !__arg0.even? end %}"
expect_to_s <<-'CR'
{%
[1, 2, 3].find do |e|
Expand Down Expand Up @@ -161,6 +161,10 @@ describe "ASTNode#to_s" do
expect_to_s "!a"
expect_to_s "!(1 < 2)"
expect_to_s "!a.b && true"
expect_to_s "x.!.foo", "(!x).foo"
expect_to_s "x.!.!.foo", "(!(!x)).foo"
expect_to_s "x.foo.!", "!x.foo"
expect_to_s "x.foo.!.!", "!!x.foo"
expect_to_s "(1 + 2)..3"
expect_to_s "macro foo\n{{ @type }}\nend"
expect_to_s "macro foo\n\\{{ @type }}\nend"
Expand Down
9 changes: 8 additions & 1 deletion src/compiler/crystal/syntax/to_s.cr
Original file line number Diff line number Diff line change
Expand Up @@ -578,9 +578,16 @@ module Crystal
true
end
end
when Not
case exp = obj.exp
when Call
exp.obj.nil?
else
!obj.exp.is_a? Call
end
when Var, NilLiteral, BoolLiteral, CharLiteral, NumberLiteral, StringLiteral,
StringInterpolation, Path, Generic, InstanceVar, ClassVar, Global,
ImplicitObj, TupleLiteral, NamedTupleLiteral, IsA, Not
ImplicitObj, TupleLiteral, NamedTupleLiteral, IsA
false
when ArrayLiteral
!!obj.of
Expand Down
Loading