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

Remove parser transform for nil? in macro expressions #10616

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
5 changes: 5 additions & 0 deletions spec/compiler/parser/parser_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1001,6 +1001,11 @@ module Crystal
)
)

it_parses "{{ foo.nil? }}", MacroExpression.new(Call.new(Var.new("foo"), "nil?"))
it_parses "{{ foo &.nil? }}", MacroExpression.new(Call.new(nil, "foo", block: Block.new([Var.new("__arg0")], Call.new(Var.new("__arg0"), "nil?"))))
it_parses "{{ foo.nil?(foo) }}", MacroExpression.new(Call.new(Var.new("foo"), "nil?", [Var.new("foo")] of ASTNode))
it_parses "{{ nil?(foo) }}", MacroExpression.new(Call.new(nil, "nil?", [Var.new("foo")] of ASTNode))

it_parses "foo.!", Not.new("foo".call)
it_parses "foo.!.!", Not.new(Not.new("foo".call))
it_parses "foo.!( )", Not.new("foo".call)
Expand Down
10 changes: 6 additions & 4 deletions src/compiler/crystal/syntax/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ module Crystal
atomic = parse_as?(atomic).at(location)
elsif @token.value == :responds_to?
atomic = parse_responds_to(atomic).at(location)
elsif @token.value == :nil?
elsif !@in_macro_expression && @token.value == :nil?
atomic = parse_nil?(atomic).at(location)
elsif @token.type == :"!"
atomic = parse_negation_suffix(atomic).at(location)
Expand Down Expand Up @@ -1541,7 +1541,7 @@ module Crystal
elsif @token.value == :responds_to?
call = parse_responds_to(obj).at(location)
call = parse_atomic_method_suffix_special(call, location)
elsif @token.value == :nil?
elsif !@in_macro_expression && @token.value == :nil?
call = parse_nil?(obj).at(location)
call = parse_atomic_method_suffix_special(call, location)
elsif @token.type == :"!"
Expand Down Expand Up @@ -4059,8 +4059,10 @@ module Crystal
obj = Var.new("self").at(location)
return parse_responds_to(obj)
when :nil?
obj = Var.new("self").at(location)
return parse_nil?(obj)
unless @in_macro_expression
obj = Var.new("self").at(location)
return parse_nil?(obj)
end
else
# Not a special call, go on
end
Expand Down