diff --git a/lib/sass/script/literal.rb b/lib/sass/script/literal.rb index 30ab87c6..cdb2cf78 100644 --- a/lib/sass/script/literal.rb +++ b/lib/sass/script/literal.rb @@ -170,5 +170,8 @@ module Sass::Script def to_i raise Sass::SyntaxError.new("#{self.inspect} is not an integer.") end + + # @raise [Sass::SyntaxError] if this literal isn't an integer + def assert_int!; to_i; end end end diff --git a/lib/sass/tree/for_node.rb b/lib/sass/tree/for_node.rb index 02675130..2c94d112 100644 --- a/lib/sass/tree/for_node.rb +++ b/lib/sass/tree/for_node.rb @@ -30,9 +30,10 @@ module Sass::Tree def _perform(environment) from = @from.perform(environment) to = @to.perform(environment) - if to.respond_to?(:coerce) - to = to.send(:coerce, from.numerator_units, from.denominator_units) - end + from.assert_int! + to.assert_int! + + to = to.send(:coerce, from.numerator_units, from.denominator_units) range = Range.new(from.to_i, to.to_i, @exclusive) children = [] diff --git a/test/sass/engine_test.rb b/test/sass/engine_test.rb index 4803c2ef..ff972abe 100755 --- a/test/sass/engine_test.rb +++ b/test/sass/engine_test.rb @@ -76,6 +76,7 @@ class SassEngineTest < Test::Unit::TestCase "@if false\n@else if " => "Invalid else directive '@else if': expected 'if '.", "a\n !b = 12\nc\n d = !b" => 'Undefined variable: "!b".', "=foo\n !b = 12\nc\n +foo\n d = !b" => 'Undefined variable: "!b".', + '@for !a from "foo" to 1' => '"foo" is not an integer.', '@for !a from 1 to "2"' => '"2" is not an integer.', '@for !a from 1 to "foo"' => '"foo" is not an integer.', '@for !a from 1 to 1.232323' => '1.232 is not an integer.',