diff --git a/lib/compiler/ast/node.rb b/lib/compiler/ast/node.rb index 99d077bd95..0b77e70ada 100644 --- a/lib/compiler/ast/node.rb +++ b/lib/compiler/ast/node.rb @@ -24,8 +24,14 @@ def self.match_send?(node, receiver, method, name) end def self.match_arguments?(arguments, count) - (arguments and arguments.body.size == count) or - (arguments.nil? and count == 0) + case arguments + when ArrayLiteral + arguments.body.size == count + when nil + count == 0 + else + false + end end def initialize(line) diff --git a/lib/compiler/ast/transforms.rb b/lib/compiler/ast/transforms.rb index e2ed9f5a69..a5c5ea4e5a 100644 --- a/lib/compiler/ast/transforms.rb +++ b/lib/compiler/ast/transforms.rb @@ -123,7 +123,8 @@ class SendFastMath < SendWithArguments } def self.match?(line, receiver, name, arguments, privately) - if op = Operators[name] and arguments.body.size == 1 + return false unless op = Operators[name] + if match_arguments? arguments, 1 node = new line, receiver, name, arguments node.operator = op node diff --git a/spec/compiler/plugins/fastmath_spec.rb b/spec/compiler/plugins/fastmath_spec.rb index 87ef29f7f7..83f799e76c 100644 --- a/spec/compiler/plugins/fastmath_spec.rb +++ b/spec/compiler/plugins/fastmath_spec.rb @@ -15,6 +15,26 @@ end end + relates "1.+(*a)" do + compile do |g| + g.push 1 + g.push :self + g.send :a, 0, true + g.cast_array + g.push :nil + g.send_with_splat :+, 0, false, false + end + + compile :fastmath do |g| + g.push 1 + g.push :self + g.send :a, 0, true + g.cast_array + g.push :nil + g.send_with_splat :+, 0, false, false + end + end + relates "1 - 1" do compile do |g| g.push 1