steep 0.49.0 → 0.49.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '0273968ec727f3b7c5c1007f9e27966c50ad7bc3128217a4ef30be4f97321037'
4
- data.tar.gz: 195eb670673894e36af5e00ef911654f2a543c71e8de1d46c15e23035bef19c8
3
+ metadata.gz: 44df04a21f7dc9d7514ad6acb34549f40fe0b4d962840c29ced4ceca926fd000
4
+ data.tar.gz: 15ac298575e8af8d29c1b1ab5e2894f3e62677dedd58b166d147d3d1649026d3
5
5
  SHA512:
6
- metadata.gz: '0908edc4a3221256f450c9fd945d7127bd9ece3fa0359b7da88be8cebea30f7c766e023b84527e89e8f0c7956752310a3b0e98343b8c4808bfde518a89284456'
7
- data.tar.gz: 4004adb0d0e8f2e0cd2629cd7e0c2bd6513a3a48bbd96d1d77621bbe0979b73686ab9c8ad718e3243081fdf492ff9728b5bf6df8e7357e1b1cf810393dad264c
6
+ metadata.gz: cdc1e1dea1ef2aa9cebd6d40a850894340e2d0ed26f8a982c81c80d384522712c442a499ef12419b0b224cd1bb659944198b8dc897eea692e4d6c06284c86381
7
+ data.tar.gz: 22a8d55bd324e3527ffd2a8886bbf7fe28e766ab2dab1e175c43a08b37d256c647f39a05e7890ed5b2726934428bb303c1fe98c45ad07166df2fb2698cc835af
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.49.1 (2022-03-11)
6
+
7
+ * Fix lambda typing ([\#506](https://github.com/soutaro/steep/pull/506))
8
+ * Validate type descendants ([\#507](https://github.com/soutaro/steep/pull/507))
9
+ * Fix print error with absolute path ([\#508](https://github.com/soutaro/steep/pull/508))
10
+ * Skip non-target ruby code on `steep stats` ([\#509](https://github.com/soutaro/steep/pull/509))
11
+
5
12
  ## 0.49.0 (2022-03-08)
6
13
 
7
14
  * Better typing for `#flat_map` ([\#504](https://github.com/soutaro/steep/pull/504))
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- steep (0.49.0)
4
+ steep (0.49.1)
5
5
  activesupport (>= 5.1)
6
6
  language_server-protocol (>= 3.15, < 4.0)
7
7
  listen (~> 3.0)
@@ -24,7 +24,7 @@ PATH
24
24
  GEM
25
25
  remote: https://rubygems.org/
26
26
  specs:
27
- activesupport (7.0.2.2)
27
+ activesupport (7.0.2.3)
28
28
  concurrent-ruby (~> 1.0, >= 1.0.2)
29
29
  i18n (>= 1.6, < 2)
30
30
  minitest (>= 5.1)
@@ -669,6 +669,19 @@ module Steep
669
669
  end
670
670
  end
671
671
 
672
+ class ProcTypeExpected < Base
673
+ attr_reader :type
674
+
675
+ def initialize(node:, type:)
676
+ super(node: node)
677
+ @type = type
678
+ end
679
+
680
+ def header_line
681
+ "Proc type is expected but `#{type.to_s}` is specified"
682
+ end
683
+ end
684
+
672
685
  class UnsupportedSyntax < Base
673
686
  attr_reader :message
674
687
 
@@ -214,8 +214,8 @@ module Steep
214
214
  total = errors.sum {|notification| notification[:diagnostics].size }
215
215
 
216
216
  errors.each do |notification|
217
- path = project.relative_path(Pathname(URI.parse(notification[:uri]).path))
218
- buffer = RBS::Buffer.new(name: path, content: path.read)
217
+ path = Pathname(URI.parse(notification[:uri]).path)
218
+ buffer = RBS::Buffer.new(name: project.relative_path(path), content: path.read)
219
219
  printer = DiagnosticPrinter.new(buffer: buffer, stdout: stdout)
220
220
 
221
221
  notification[:diagnostics].each do |diag|
@@ -269,6 +269,8 @@ module Steep
269
269
  end
270
270
 
271
271
  def typecheck_source(path:, target: project.target_for_source_path(path), &block)
272
+ return unless target
273
+
272
274
  Steep.logger.tagged "#typecheck_source(path=#{path})" do
273
275
  Steep.measure "typecheck" do
274
276
  signature_service = signature_services[target.name]
@@ -89,11 +89,7 @@ module Steep
89
89
  end
90
90
  end
91
91
 
92
- def validate_type(type)
93
- Steep.logger.debug "#{Location.to_string type.location}: Validating #{type}..."
94
-
95
- validator.validate_type type, context: [RBS::Namespace.root]
96
-
92
+ def validate_type_application(type)
97
93
  name, type_params, type_args =
98
94
  case type
99
95
  when RBS::Types::ClassInstance
@@ -123,6 +119,17 @@ module Steep
123
119
  validate_type_application_constraints(type.name, type_params, type_args, location: type.location)
124
120
  end
125
121
  end
122
+
123
+ type.each_type do |child|
124
+ validate_type_application(child)
125
+ end
126
+ end
127
+
128
+ def validate_type(type)
129
+ Steep.logger.debug "#{Location.to_string type.location}: Validating #{type}..."
130
+
131
+ validator.validate_type type, context: [RBS::Namespace.root]
132
+ validate_type_application(type)
126
133
  end
127
134
 
128
135
  def ancestor_to_type(ancestor)
@@ -2727,10 +2727,24 @@ module Steep
2727
2727
  end
2728
2728
  end
2729
2729
 
2730
+ def optional_proc?(type)
2731
+ if type.is_a?(AST::Types::Union)
2732
+ if type.types.size == 2
2733
+ if type.types.find {|t| t.is_a?(AST::Types::Nil) }
2734
+ if proc_type = type.types.find {|t| t.is_a?(AST::Types::Proc) }
2735
+ proc_type
2736
+ end
2737
+ end
2738
+ end
2739
+ end
2740
+ end
2741
+
2730
2742
  def type_lambda(node, params_node:, body_node:, type_hint:)
2731
2743
  block_annotations = source.annotations(block: node, factory: checker.factory, current_module: current_namespace)
2732
2744
  params = TypeInference::BlockParams.from_node(params_node, annotations: block_annotations)
2733
2745
 
2746
+ type_hint = deep_expand_alias(type_hint) if type_hint
2747
+
2734
2748
  case type_hint
2735
2749
  when AST::Types::Proc
2736
2750
  params_hint = type_hint.type.params
@@ -2749,6 +2763,13 @@ module Steep
2749
2763
 
2750
2764
  block_constr.typing.add_context_for_body(node, context: block_constr.context)
2751
2765
 
2766
+ default_proc_function =
2767
+ Interface::Function.new(
2768
+ params: Interface::Function::Params.empty,
2769
+ return_type: AST::Builtin.any_type,
2770
+ location: nil
2771
+ )
2772
+
2752
2773
  params.params.each do |param|
2753
2774
  _, block_constr = block_constr.synthesize(param.node, hint: param.type)
2754
2775
  end
@@ -2759,17 +2780,29 @@ module Steep
2759
2780
  case block_param_type
2760
2781
  when AST::Types::Proc
2761
2782
  Interface::Block.new(type: block_param_type.type, optional: false)
2762
- when AST::Types::Union
2763
- if block_param_type.types.size == 2
2764
- if block_param_type.types.find {|t| t.is_a?(AST::Types::Nil) }
2765
- if proc_type = block_param_type.types.find {|t| t.is_a?(AST::Types::Proc) }
2766
- Interface::Block.new(type: proc_type.type, optional: true)
2767
- end
2768
- end
2783
+ else
2784
+ if proc_type = optional_proc?(block_param_type)
2785
+ Interface::Block.new(type: proc_type.type, optional: true)
2786
+ else
2787
+ block_constr.typing.add_error(
2788
+ Diagnostic::Ruby::ProcTypeExpected.new(
2789
+ node: block_param.node,
2790
+ type: block_param_type
2791
+ )
2792
+ )
2793
+
2794
+ Interface::Block.new(
2795
+ type: Interface::Function.new(
2796
+ params: Interface::Function::Params.empty,
2797
+ return_type: AST::Builtin.any_type,
2798
+ location: nil
2799
+ ),
2800
+ optional: false
2801
+ )
2769
2802
  end
2770
2803
  end
2771
2804
  else
2772
- type_hint.block
2805
+ block_hint
2773
2806
  end
2774
2807
  end
2775
2808
 
data/lib/steep/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Steep
2
- VERSION = "0.49.0"
2
+ VERSION = "0.49.1"
3
3
  end
@@ -0,0 +1,3 @@
1
+ -> (&block) do
2
+ # @type var block: Integer
3
+ end
@@ -332,6 +332,18 @@
332
332
  severity: ERROR
333
333
  message: Type `::Integer` does not have method `foo`
334
334
  code: Ruby::NoMethod
335
+ - file: proc_type_expected.rb
336
+ diagnostics:
337
+ - range:
338
+ start:
339
+ line: 1
340
+ character: 4
341
+ end:
342
+ line: 1
343
+ character: 10
344
+ severity: ERROR
345
+ message: Proc type is expected but `::Integer` is specified
346
+ code: Ruby::ProcTypeExpected
335
347
  - file: required_block_missing.rb
336
348
  diagnostics:
337
349
  - range:
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.49.0
4
+ version: 0.49.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Soutaro Matsumoto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-08 00:00:00.000000000 Z
11
+ date: 2022-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -356,6 +356,7 @@ files:
356
356
  - smoke/diagnostics/method_return_type_annotation_mismatch.rb
357
357
  - smoke/diagnostics/missing_keyword.rb
358
358
  - smoke/diagnostics/no_method.rb
359
+ - smoke/diagnostics/proc_type_expected.rb
359
360
  - smoke/diagnostics/required_block_missing.rb
360
361
  - smoke/diagnostics/return_type_mismatch.rb
361
362
  - smoke/diagnostics/test_expectations.yml