Skip to content

abstract class Crystal::ExhaustivenessChecker::Target
inherits Reference

A target to check for exhaustiveness

Every target can also have subtargets, used when matching against a tuple literal. For example, the BoolTarget will have one subtarget for the value false and one for the value true. When a pattern like {false, ...} is passed to it, only patterns for the false subtarget will be covered.

Direct known subclasses

Crystal::ExhaustivenessChecker::BoolTarget Crystal::ExhaustivenessChecker::EnumTarget Crystal::ExhaustivenessChecker::TypeTarget

Class methods

.new(type : Type)

View source

Methods

abstract #add_subtargets(type_groups : Array(Array(Type)), index : Int32) : Nil

Add subtargets for the given type groups, starting at index.

View source

abstract #cover(patterns : Array(Pattern), index : Int32) : Nil

Covers this target and subsequent subtargets with the patterns starting at index.

View source

#cover(pattern : Pattern) : Nil

Tries to cover this target with the given pattern. By default, a TypePattern will cover a target. Other, more specific, patterns will partially cover a target.

View source

abstract #covered? : Bool

Was this target covered?

View source

abstract #missing_cases : Array(String)

What are the cases that we didn't cover?

View source

abstract #reject_covered! : Bool

Removes covered subtargets from this target, and returns whether this target ended up being entirely covered.

View source

#type : Crystal::Type

The type this target is based on.

View source