steep 0.36.0 → 0.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -319,17 +319,20 @@ module Steep
319
319
  end
320
320
 
321
321
  when relation.sub_type.is_a?(AST::Types::Proc) && relation.super_type.is_a?(AST::Types::Proc)
322
- check_method_params(:__proc__,
323
- relation.sub_type.params, relation.super_type.params,
324
- self_type: self_type,
325
- assumption: assumption,
326
- trace: trace,
327
- constraints: constraints).then do
328
- check(Relation.new(sub_type: relation.sub_type.return_type, super_type: relation.super_type.return_type),
329
- self_type: self_type,
330
- assumption: assumption,
331
- trace: trace,
332
- constraints: constraints)
322
+ name = :__proc__
323
+
324
+ sub_type = relation.sub_type
325
+ super_type = relation.super_type
326
+
327
+ check_method_params(name, sub_type.type.params, super_type.type.params, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints).then do
328
+ check_block_given(name, sub_type.block, super_type.block, trace: trace, constraints: constraints).then do
329
+ check_block_params(name, sub_type.block, super_type.block, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints).then do
330
+ check_block_return(sub_type.block, super_type.block, self_type: self_type, assumption: assumption, trace: trace, constraints:constraints).then do
331
+ relation = Relation.new(super_type: super_type.type.return_type, sub_type: sub_type.type.return_type)
332
+ check(relation, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints)
333
+ end
334
+ end
335
+ end
333
336
  end
334
337
 
335
338
  when relation.sub_type.is_a?(AST::Types::Tuple) && relation.super_type.is_a?(AST::Types::Tuple)
@@ -700,12 +703,12 @@ module Steep
700
703
 
701
704
  def check_method_type(name, sub_type, super_type, self_type:, assumption:, trace:, constraints:)
702
705
  Steep.logger.tagged("#{name}: #{sub_type} <: #{super_type}") do
703
- check_method_params(name, sub_type.params, super_type.params, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints).then do
706
+ check_method_params(name, sub_type.type.params, super_type.type.params, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints).then do
704
707
  check_block_given(name, sub_type.block, super_type.block, trace: trace, constraints: constraints).then do
705
708
  check_block_params(name, sub_type.block, super_type.block, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints).then do
706
709
  check_block_return(sub_type.block, super_type.block, self_type: self_type, assumption: assumption, trace: trace, constraints:constraints).then do
707
- relation = Relation.new(super_type: super_type.return_type,
708
- sub_type: sub_type.return_type)
710
+ relation = Relation.new(super_type: super_type.type.return_type,
711
+ sub_type: sub_type.type.return_type)
709
712
  check(relation, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints)
710
713
  end
711
714
  end
@@ -750,10 +753,10 @@ module Steep
750
753
 
751
754
  def match_method_type(name, sub_type, super_type, trace:)
752
755
  [].tap do |pairs|
753
- match_params(name, sub_type.params, super_type.params, trace: trace).yield_self do |result|
756
+ match_params(name, sub_type.type.params, super_type.type.params, trace: trace).yield_self do |result|
754
757
  return result unless result.is_a?(Array)
755
758
  pairs.push(*result)
756
- pairs.push [sub_type.return_type, super_type.return_type]
759
+ pairs.push [sub_type.type.return_type, super_type.type.return_type]
757
760
 
758
761
  case
759
762
  when !super_type.block && !sub_type.block
@@ -10,12 +10,12 @@ module Steep
10
10
  end
11
11
 
12
12
  def add_method_type(method_type)
13
- method_type.params.each_type do |type|
13
+ method_type.type.params.each_type do |type|
14
14
  each_var(type) do |var|
15
15
  params << var
16
16
  end
17
17
  end
18
- each_var(method_type.return_type) do |var|
18
+ each_var(method_type.type.return_type) do |var|
19
19
  returns << var
20
20
  end
21
21
 
@@ -25,8 +25,8 @@ module Steep
25
25
  covariants = Set.new
26
26
  contravariants = Set.new
27
27
 
28
- add_params(method_type.params, block: false, contravariants: contravariants, covariants: covariants)
29
- add_type(method_type.return_type, variance: :covariant, covariants: covariants, contravariants: contravariants)
28
+ add_params(method_type.type.params, block: false, contravariants: contravariants, covariants: covariants)
29
+ add_type(method_type.type.return_type, variance: :covariant, covariants: covariants, contravariants: contravariants)
30
30
 
31
31
  method_type.block&.type&.yield_self do |proc|
32
32
  add_params(proc.params, block: true, contravariants: contravariants, covariants: covariants)
@@ -140,10 +140,10 @@ module Steep
140
140
 
141
141
  method_type = annotation_method_type || definition_method_type
142
142
 
143
- if annots&.return_type && method_type&.return_type
144
- check_relation(sub_type: annots.return_type, super_type: method_type.return_type).else do |result|
143
+ if annots&.return_type && method_type&.type&.return_type
144
+ check_relation(sub_type: annots.return_type, super_type: method_type.type.return_type).else do |result|
145
145
  typing.add_error Errors::MethodReturnTypeAnnotationMismatch.new(node: node,
146
- method_type: method_type.return_type,
146
+ method_type: method_type.type.return_type,
147
147
  annotation_type: annots.return_type,
148
148
  result: result)
149
149
  end
@@ -152,19 +152,18 @@ module Steep
152
152
  # constructor_method = method&.attributes&.include?(:constructor)
153
153
 
154
154
  if method_type
155
- var_types = TypeConstruction.parameter_types(args, method_type)
156
- unless TypeConstruction.valid_parameter_env?(var_types, args.reject {|arg| arg.type == :blockarg}, method_type.params)
155
+ var_types = TypeConstruction.parameter_types(args, method_type.type)
156
+ unless TypeConstruction.valid_parameter_env?(var_types, args.reject {|arg| arg.type == :blockarg}, method_type.type.params)
157
157
  typing.add_error Errors::MethodArityMismatch.new(node: node)
158
158
  end
159
159
  end
160
160
 
161
161
  if (block_arg = args.find {|arg| arg.type == :blockarg})
162
162
  if method_type&.block
163
- block_type = if method_type.block.optional?
164
- AST::Types::Union.build(types: [method_type.block.type, AST::Builtin.nil_type])
165
- else
166
- method_type.block.type
167
- end
163
+ block_type = AST::Types::Proc.new(type: method_type.block.type, block: nil)
164
+ if method_type.block.optional?
165
+ block_type = AST::Types::Union.build(types: [block_type, AST::Builtin.nil_type])
166
+ end
168
167
  var_types[block_arg.children[0]] = block_type
169
168
  end
170
169
  end
@@ -183,7 +182,7 @@ module Steep
183
182
  name: method_name,
184
183
  method: definition && definition.methods[method_name],
185
184
  method_type: method_type,
186
- return_type: annots.return_type || method_type&.return_type || AST::Builtin.any_type,
185
+ return_type: annots.return_type || method_type&.type&.return_type || AST::Builtin.any_type,
187
186
  constructor: false,
188
187
  super_method: super_method
189
188
  )
@@ -1404,7 +1403,7 @@ module Steep
1404
1403
  if method_context&.method
1405
1404
  if method_context.super_method
1406
1405
  types = method_context.super_method.method_types.map {|method_type|
1407
- checker.factory.method_type(method_type, self_type: self_type, method_decls: Set[]).return_type
1406
+ checker.factory.method_type(method_type, self_type: self_type, method_decls: Set[]).type.return_type
1408
1407
  }
1409
1408
  add_typing(node, type: union_type(*types))
1410
1409
  else
@@ -2022,17 +2021,25 @@ module Steep
2022
2021
  if hint.is_a?(AST::Types::Proc) && value.type == :sym
2023
2022
  if hint.one_arg?
2024
2023
  # Assumes Symbol#to_proc implementation
2025
- param_type = hint.params.required[0]
2024
+ param_type = hint.type.params.required[0]
2026
2025
  interface = checker.factory.interface(param_type, private: true)
2027
2026
  method = interface.methods[value.children[0]]
2028
2027
  if method
2029
2028
  return_types = method.method_types.select {|method_type|
2030
- method_type.params.each_type.count == 0
2031
- }.map(&:return_type)
2029
+ method_type.type.params.empty?
2030
+ }.map {|method_type|
2031
+ method_type.type.return_type
2032
+ }
2032
2033
 
2033
2034
  unless return_types.empty?
2034
- type = AST::Types::Proc.new(params: Interface::Params.empty.update(required: [param_type]),
2035
- return_type: AST::Types::Union.build(types: return_types))
2035
+ type = AST::Types::Proc.new(
2036
+ type: Interface::Function.new(
2037
+ params: Interface::Function::Params.empty.update(required: [param_type]),
2038
+ return_type: AST::Types::Union.build(types: return_types),
2039
+ location: nil
2040
+ ),
2041
+ block: nil
2042
+ )
2036
2043
  end
2037
2044
  end
2038
2045
  else
@@ -2362,8 +2369,8 @@ module Steep
2362
2369
 
2363
2370
  case type_hint
2364
2371
  when AST::Types::Proc
2365
- params_hint = type_hint.params
2366
- return_hint = type_hint.return_type
2372
+ params_hint = type_hint.type.params
2373
+ return_hint = type_hint.type.return_type
2367
2374
  end
2368
2375
 
2369
2376
  block_constr = for_block(
@@ -2393,8 +2400,12 @@ module Steep
2393
2400
  end
2394
2401
 
2395
2402
  block_type = AST::Types::Proc.new(
2396
- params: params_hint || params.params_type,
2397
- return_type: return_type
2403
+ type: Interface::Function.new(
2404
+ params: params_hint || params.params_type,
2405
+ return_type: return_type,
2406
+ location: nil
2407
+ ),
2408
+ block: nil
2398
2409
  )
2399
2410
 
2400
2411
  add_typing node, type: block_type
@@ -2600,7 +2611,7 @@ module Steep
2600
2611
 
2601
2612
  results = method.method_types.flat_map do |method_type|
2602
2613
  Steep.logger.tagged method_type.to_s do
2603
- zips = args.zips(method_type.params, method_type.block&.type)
2614
+ zips = args.zips(method_type.type.params, method_type.block&.type)
2604
2615
 
2605
2616
  zips.map do |arg_pairs|
2606
2617
  typing.new_child(node_range) do |child_typing|
@@ -2632,7 +2643,7 @@ module Steep
2632
2643
  context: context.method_context,
2633
2644
  method_name: method_name,
2634
2645
  receiver_type: receiver_type,
2635
- return_type: method_type.return_type,
2646
+ return_type: method_type.type.return_type,
2636
2647
  errors: [error],
2637
2648
  method_decls: all_decls
2638
2649
  )
@@ -2655,7 +2666,7 @@ module Steep
2655
2666
  end
2656
2667
 
2657
2668
  def check_keyword_arg(receiver_type:, node:, method_type:, constraints:)
2658
- params = method_type.params
2669
+ params = method_type.type.params
2659
2670
 
2660
2671
  case node.type
2661
2672
  when :hash
@@ -2757,7 +2768,7 @@ module Steep
2757
2768
  )
2758
2769
  else
2759
2770
  hash_elements = params.required_keywords.merge(
2760
- method_type.params.optional_keywords.transform_values do |type|
2771
+ params.optional_keywords.transform_values do |type|
2761
2772
  AST::Types::Union.build(types: [type, AST::Builtin.nil_type])
2762
2773
  end
2763
2774
  )
@@ -2840,7 +2851,7 @@ module Steep
2840
2851
  block_params: block_params_,
2841
2852
  block_param_hint: method_type.block.type.params,
2842
2853
  block_annotations: block_annotations,
2843
- node_type_hint: method_type.return_type
2854
+ node_type_hint: method_type.type.return_type
2844
2855
  )
2845
2856
  block_constr = block_constr.with_new_typing(
2846
2857
  block_constr.typing.new_child(
@@ -2870,7 +2881,7 @@ module Steep
2870
2881
  checker,
2871
2882
  self_type: self_type,
2872
2883
  variance: variance,
2873
- variables: method_type.params.free_variables + method_type.block.type.params.free_variables
2884
+ variables: method_type.type.params.free_variables + method_type.block.type.params.free_variables
2874
2885
  )
2875
2886
  method_type = method_type.subst(s)
2876
2887
  block_constr = block_constr.update_lvar_env {|env| env.subst(s) }
@@ -2896,22 +2907,36 @@ module Steep
2896
2907
  s = constraints.solution(checker, self_type: self_type, variance: variance, variables: fresh_vars)
2897
2908
  method_type = method_type.subst(s)
2898
2909
 
2899
- return_type = method_type.return_type
2910
+ return_type = method_type.type.return_type
2900
2911
  if break_type = block_annotations.break_type
2901
2912
  return_type = union_type(break_type, return_type)
2902
2913
  end
2903
2914
 
2904
2915
  when Subtyping::Result::Failure
2905
- block_type = AST::Types::Proc.new(
2906
- params: method_type.block.type.params || block_params.params_type,
2907
- return_type: block_body_type
2916
+ given_block_type = AST::Types::Proc.new(
2917
+ type: Interface::Function.new(
2918
+ params: method_type.block.type.params || block_params.params_type,
2919
+ return_type: block_body_type,
2920
+ location: nil
2921
+ ),
2922
+ block: nil
2923
+ )
2924
+
2925
+ method_block_type = AST::Types::Proc.new(
2926
+ type: Interface::Function.new(
2927
+ params: method_type.block.type.params,
2928
+ return_type: method_type.block.type.return_type,
2929
+ location: nil
2930
+ ),
2931
+ block: nil
2908
2932
  )
2933
+
2909
2934
  errors << Errors::BlockTypeMismatch.new(node: node,
2910
- expected: method_type.block.type,
2911
- actual: block_type,
2935
+ expected: method_block_type,
2936
+ actual: given_block_type,
2912
2937
  result: result)
2913
2938
 
2914
- return_type = method_type.return_type
2939
+ return_type = method_type.type.return_type
2915
2940
  end
2916
2941
 
2917
2942
  block_constr.typing.save!
@@ -2985,23 +3010,24 @@ module Steep
2985
3010
  else
2986
3011
  begin
2987
3012
  method_type = method_type.subst(constraints.solution(checker, self_type: self_type, variance: variance, variables: occurence.params))
2988
- block_type, constr = constr.synthesize(args.block_pass_arg, hint: topdown_hint ? method_type.block.type : nil)
2989
- result = check_relation(
2990
- sub_type: block_type,
2991
- super_type: method_type.block.yield_self {|expected_block|
2992
- if expected_block.optional?
2993
- AST::Builtin.optional(expected_block.type)
2994
- else
2995
- expected_block.type
2996
- end
2997
- },
2998
- constraints: constraints
2999
- )
3013
+ hint_type = if topdown_hint
3014
+ AST::Types::Proc.new(type: method_type.block.type, block: nil)
3015
+ end
3016
+ given_block_type, constr = constr.synthesize(args.block_pass_arg, hint: hint_type)
3017
+ method_block_type = method_type.block.yield_self {|expected_block|
3018
+ proc_type = AST::Types::Proc.new(type: expected_block.type, block: nil)
3019
+ if expected_block.optional?
3020
+ AST::Builtin.optional(proc_type)
3021
+ else
3022
+ proc_type
3023
+ end
3024
+ }
3000
3025
 
3026
+ result = check_relation(sub_type: given_block_type, super_type: method_block_type, constraints: constraints)
3001
3027
  result.else do |result|
3002
3028
  errors << Errors::BlockTypeMismatch.new(node: node,
3003
- expected: method_type.block.type,
3004
- actual: block_type,
3029
+ expected: method_block_type,
3030
+ actual: given_block_type,
3005
3031
  result: result)
3006
3032
  end
3007
3033
 
@@ -3018,7 +3044,7 @@ module Steep
3018
3044
  receiver_type: receiver_type,
3019
3045
  method_name: method_name,
3020
3046
  actual_method_type: method_type,
3021
- return_type: return_type || method_type.return_type,
3047
+ return_type: return_type || method_type.type.return_type,
3022
3048
  method_decls: method_type.method_decls
3023
3049
  )
3024
3050
  else
@@ -3027,7 +3053,7 @@ module Steep
3027
3053
  context: context.method_context,
3028
3054
  receiver_type: receiver_type,
3029
3055
  method_name: method_name,
3030
- return_type: return_type || method_type.return_type,
3056
+ return_type: return_type || method_type.type.return_type,
3031
3057
  method_decls: method_type.method_decls,
3032
3058
  errors: errors
3033
3059
  )
@@ -134,7 +134,7 @@ module Steep
134
134
  rest = rest_param&.yield_self {|param| param.type.args[0] }
135
135
  end
136
136
 
137
- Interface::Params.new(
137
+ Interface::Function::Params.new(
138
138
  required: leadings,
139
139
  optional: optionals,
140
140
  rest: rest,
@@ -1,3 +1,3 @@
1
1
  module Steep
2
- VERSION = "0.36.0"
2
+ VERSION = "0.37.0"
3
3
  end
@@ -0,0 +1,6 @@
1
+ target :test do
2
+ signature "."
3
+ check "."
4
+
5
+ library "tsort"
6
+ end
@@ -0,0 +1,15 @@
1
+ # ALLOW FAILURE
2
+
3
+ require "tsort"
4
+
5
+ # @type var g: Hash[Integer, Array[Integer]]
6
+ g = {1=>[2, 3], 2=>[4], 3=>[2, 4], 4=>[]}
7
+
8
+ # @type var each_node: ^() { (Integer) -> void } -> void
9
+ each_node = -> (&b) { g.each_key(&b) }
10
+ # @type var each_child: ^(Integer) { (Integer) -> void } -> void
11
+ each_child = -> (n, &b) { g[n].each(&b) }
12
+
13
+ # @type var xs: Array[String]
14
+ # !expects IncompatibleAssignment: lhs_type=::Array[::String], rhs_type=::Array[::Integer]
15
+ xs = TSort.tsort(each_node, each_child)
@@ -34,5 +34,5 @@ Gem::Specification.new do |spec|
34
34
  spec.add_runtime_dependency "rainbow", ">= 2.2.2", "< 4.0"
35
35
  spec.add_runtime_dependency "listen", "~> 3.0"
36
36
  spec.add_runtime_dependency "language_server-protocol", "~> 3.15.0.1"
37
- spec.add_runtime_dependency "rbs", "~> 0.17.0"
37
+ spec.add_runtime_dependency "rbs", ">= 0.20.0"
38
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: steep
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.36.0
4
+ version: 0.37.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-11-16 00:00:00.000000000 Z
11
+ date: 2020-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -104,16 +104,16 @@ dependencies:
104
104
  name: rbs
105
105
  requirement: !ruby/object:Gem::Requirement
106
106
  requirements:
107
- - - "~>"
107
+ - - ">="
108
108
  - !ruby/object:Gem::Version
109
- version: 0.17.0
109
+ version: 0.20.0
110
110
  type: :runtime
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
113
113
  requirements:
114
- - - "~>"
114
+ - - ">="
115
115
  - !ruby/object:Gem::Version
116
- version: 0.17.0
116
+ version: 0.20.0
117
117
  description: Gradual Typing for Ruby
118
118
  email:
119
119
  - matsumoto@soutaro.com
@@ -178,6 +178,8 @@ files:
178
178
  - lib/steep/drivers/watch.rb
179
179
  - lib/steep/drivers/worker.rb
180
180
  - lib/steep/errors.rb
181
+ - lib/steep/interface/block.rb
182
+ - lib/steep/interface/function.rb
181
183
  - lib/steep/interface/interface.rb
182
184
  - lib/steep/interface/method.rb
183
185
  - lib/steep/interface/method_type.rb
@@ -355,6 +357,8 @@ files:
355
357
  - smoke/toplevel/Steepfile
356
358
  - smoke/toplevel/a.rb
357
359
  - smoke/toplevel/a.rbs
360
+ - smoke/tsort/Steepfile
361
+ - smoke/tsort/a.rb
358
362
  - smoke/type_case/Steepfile
359
363
  - smoke/type_case/a.rb
360
364
  - smoke/yield/Steepfile