Permalink
Browse files

Oops... && and || aren't quite *that* safe.

  • Loading branch information...
1 parent 54a4127 commit 558309ee38574b62bc7a1ff7e46ad59db3e53f0f @matthewd committed Dec 10, 2010
Showing with 14 additions and 4 deletions.
  1. +14 −4 lib/capuchin/generator.rb
View
@@ -7,8 +7,6 @@ class Capuchin::Generator < Rubinius::Generator
RKelly::Nodes::FalseNode
RKelly::Nodes::NullNode
RKelly::Nodes::LogicalNotNode
- RKelly::Nodes::LogicalAndNode
- RKelly::Nodes::LogicalOrNode
RKelly::Nodes::EqualNode
RKelly::Nodes::StrictEqualNode
RKelly::Nodes::NotEqualNode
@@ -22,8 +20,20 @@ class Capuchin::Generator < Rubinius::Generator
RKelly::Nodes::VoidNode
)
+ def bool_safe?(o)
+ if BoolSafeNodes.include?(o.class.name)
+ return true
+ end
+
+ if RKelly::Nodes::LogicalAndNode === o || RKelly::Nodes::LogicalOrNode === o
+ bool_safe?(o.left) && bool_safe?(o.value)
+ end
+
+ false
+ end
+
def giz(label, src=nil)
- if src && BoolSafeNodes.include?(src.class.name)
+ if src && bool_safe?(src)
gif label
else
not_easy = new_label
@@ -39,7 +49,7 @@ def giz(label, src=nil)
end
end
def gnz(label, src=nil)
- if src && BoolSafeNodes.include?(src.class.name)
+ if src && bool_safe?(src)
git label
else
do_pop = new_label

0 comments on commit 558309e

Please sign in to comment.