lib/raap/method_property.rb in raap-0.6.0 vs lib/raap/method_property.rb in raap-0.8.0

- old
+ new

@@ -48,11 +48,11 @@ end private def call(size:, stats:) - if @method_type.rbs.type.each_type.find { |t| t.instance_of?(::RBS::Types::Bases::Any) } + if @method_type.rbs.type.each_param.find { |param| param.type.each_type.find { |t| t.instance_of?(::RBS::Types::Bases::Any) } } RaaP.logger.info { "Skip type check since `#{@method_type.rbs}` includes `untyped`" } stats.break = true throw :break end receiver_value = @receiver_type.to_symbolic_call(size: size) @@ -65,12 +65,13 @@ check = [:failure] if return_type.instance_of?(::RBS::Types::Bases::Bottom) begin return_value = symbolic_caller.eval rescue StandardError, NotImplementedError - check = [:success] return_value = Value::Bottom.new + coverage("return", return_value, return_type) + check = [:success] rescue Timeout::ExitException raise rescue Exception => e # rubocop:disable Lint/RescueException RaaP.logger.error("[#{e.class}] class is not supported to check `bot` type") raise @@ -111,10 +112,11 @@ def check_return(receiver_value:, return_value:) if BindCall.is_a?(receiver_value, Module) if BindCall.is_a?(return_type, ::RBS::Types::ClassSingleton) # ::RBS::Test::TypeCheck cannot support to check singleton class if receiver_value == return_value + coverage("return", return_value, return_type) [:success] else [:failure] end end @@ -133,10 +135,11 @@ sample_size: 100, unchecked_classes: [] ) begin if type_check.value(return_value, return_type) + coverage("return", return_value, return_type, type_check) [:success] else [:failure] end rescue => e @@ -145,8 +148,36 @@ end end def return_type @method_type.rbs.type.return_type + end + + def coverage(position, return_value, return_type, type_check = nil) + return unless Coverage.running? + + case return_type + when ::RBS::Types::Tuple + return_type.types.zip(return_value).each_with_index do |(type, value), i| + if type_check&.value(value, type) + coverage("#{position}_tuple_#{i}", value, type, type_check) + end + end + when ::RBS::Types::Union + return_type.types.each_with_index do |type, i| + if type_check&.value(return_value, type) + coverage("#{position}_union_#{i}", return_value, type, type_check) + break + end + end + when ::RBS::Types::Optional + if return_value.nil? + Coverage.log("#{position}_optional_right") + else + coverage("#{position}_optional_left", return_value, return_type.type, type_check) + end + else + Coverage.log(position) + end end end end