Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revised predicate-type-checking warning.
A method foo? must be observed to return an instance of a truthy class at least once, and an instance of a falsy class at least once.
- Loading branch information
Michael Edgar
committed
Aug 27, 2011
1 parent
9e79c5f
commit a81adbf
Showing
4 changed files
with
27 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
lib/laser/analysis/method_analysis/incorrect_predicate_method_detection.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Laser | ||
module Analysis | ||
module IncorrectPredicateMethodDetection | ||
def incorrect_predicate_methods | ||
each_user_method.select do |method| | ||
method.name.end_with?('?') | ||
end.select do |method| | ||
!correct_predicate_type?(method.combined_return_type) | ||
end | ||
end | ||
|
||
def correct_predicate_type?(return_type) | ||
(Types.subtype?(Types::FALSECLASS, return_type) || | ||
Types.subtype?(Types::NILCLASS, return_type )) && | ||
!Types.subtype?(return_type, Types::FALSY) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters