Module: SimpleCov::StaticCoverageExtractor::ConditionFolding

Included in:
Visitor
Defined in:
lib/simplecov/static_coverage_extractor/condition_folding.rb

Overview

Detects the if / unless / ternary conditions CRuby folds away. When a condition is a statically-known-truthy/falsy literal the compiler eliminates the dead arm and Coverage emits NO branch, so the extractor must not synthesize one either — otherwise the arm is a phantom that no loaded run can ever hit, the same unmergeable-tuple failure mode as #1226 / #1233.

Constant Summary collapse

STATIC_CONDITION_TYPES =

Prism node types for the literals that fold. while / until do NOT fold (while true is a real branch), so only the if-like visitors consult this. Regexp and Range literals are excluded on purpose: as conditions they mean =~ $_ / flip-flop, which Coverage does branch on.

[
  ::Prism::IntegerNode, ::Prism::FloatNode, ::Prism::RationalNode,
  ::Prism::ImaginaryNode, ::Prism::SymbolNode, ::Prism::StringNode,
  ::Prism::TrueNode, ::Prism::FalseNode, ::Prism::NilNode
].freeze