lib/rbs/variance_calculator.rb in rbs-0.11.0 vs lib/rbs/variance_calculator.rb in rbs-0.12.0

- old
+ new

@@ -71,15 +71,15 @@ method_type.type.each_param do |param| type(param.type, result: result, context: :contravariant) end - if method_type.block - method_type.block.type.each_param do |param| + if block = method_type.block + block.type.each_param do |param| type(param.type, result: result, context: :covariant) end - type(method_type.block.type.return_type, result: result, context: :contravariant) + type(block.type.return_type, result: result, context: :contravariant) end type(method_type.type.return_type, result: result, context: :covariant) result @@ -111,29 +111,32 @@ env: env, location: type.location) type_params = case type when Types::ClassInstance - env.class_decls[type.name]&.type_params + env.class_decls[type.name].type_params when Types::Interface - env.interface_decls[type.name]&.decl&.type_params + env.interface_decls[type.name].decl.type_params end type.args.each.with_index do |ty, i| var = type_params.params[i] case var.variance when :invariant type(ty, result: result, context: :invariant) when :covariant type(ty, result: result, context: context) when :contravariant + # @type var con: variance con = case context when :invariant :invariant when :covariant :contravariant when :contravariant :covariant + else + raise end type(ty, result: result, context: con) end end when Types::Tuple, Types::Record, Types::Union, Types::Intersection