steep 1.5.0 → 1.5.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77aea7baf36285cf4a5b0941e63cc8f5f95d52132d3a5d4933a396a79b949721
4
- data.tar.gz: 2506370595dde6633abbab74b1e370d435579415a154b4a82b4da3bb1b065627
3
+ metadata.gz: d7775c9db83acf70b19f27b4983923ee40e8d1a39043c981726573b0c06eb1c8
4
+ data.tar.gz: 1d9f2753a19a577cce778f6ec1ee924534523812764c0350c21280d82a0e1c69
5
5
  SHA512:
6
- metadata.gz: 6f3190f0ca65a931f9c88d99cbd67836478d754439b5630b1b68f89e9fa6d84a84cc8bde32335d4bdb38b3f13aefaeaf93a75b53722a0b6841eab27e9b689ed8
7
- data.tar.gz: 94576f1eedcb8c46ca8228e84e4100e860c0e3ed2a28dc209afa80abdeeed188118f1589dcb15d0a8edb0cd8c751f611035a15b613d284113c8cbebcce42dc6e
6
+ metadata.gz: 6bd6340dfecc114df47a959d25a4201a87ccccbc0b1e59238962de51c28218b01aa25499ae8a760e678481192131dfdd3c99b6c89412ce4b6e0b3fad2bf34ca5
7
+ data.tar.gz: 87437181a053c65f297192eb9e339c0b58ad074d4c6716eef2a1019116d3ed06d0525eebcc49855ae99a8393bffac82640d77f608479b98f67e158b42c54d327
data/CHANGELOG.md CHANGED
@@ -2,6 +2,18 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 1.5.1 (2023-07-20)
6
+
7
+ ### Type checker core
8
+
9
+ * Support unreachable branch detection with `elsif` ([#879](https://github.com/soutaro/steep/pull/879))
10
+ * Give an optional type hint to lhs of `||` ([#874](https://github.com/soutaro/steep/pull/874))
11
+
12
+ ### Miscellaneous
13
+
14
+ * Update steep ([#878](https://github.com/soutaro/steep/pull/878))
15
+ * Update inline type comments ([#875](https://github.com/soutaro/steep/pull/875))
16
+
5
17
  ## 1.5.0 (2023-07-13)
6
18
 
7
19
  ### Type checker core
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- steep (1.5.0)
4
+ steep (1.5.1)
5
5
  activesupport (>= 5.1)
6
6
  concurrent-ruby (>= 1.1.10)
7
7
  csv (>= 3.0.9)
@@ -53,7 +53,7 @@ GEM
53
53
  rb-fsevent (0.11.2)
54
54
  rb-inotify (0.10.1)
55
55
  ffi (~> 1.0)
56
- rbs (3.1.0)
56
+ rbs (3.1.1)
57
57
  ruby-lsp (0.5.1)
58
58
  language_server-protocol (~> 3.17.0)
59
59
  sorbet-runtime
data/Gemfile.steep.lock CHANGED
@@ -1,17 +1,17 @@
1
1
  GEM
2
2
  remote: https://rubygems.org/
3
3
  specs:
4
- activesupport (7.0.5)
4
+ activesupport (7.0.6)
5
5
  concurrent-ruby (~> 1.0, >= 1.0.2)
6
6
  i18n (>= 1.6, < 2)
7
7
  minitest (>= 5.1)
8
8
  tzinfo (~> 2.0)
9
9
  ast (2.4.2)
10
10
  concurrent-ruby (1.2.2)
11
- csv (3.2.6)
11
+ csv (3.2.7)
12
12
  ffi (1.15.5)
13
13
  fileutils (1.7.1)
14
- i18n (1.13.0)
14
+ i18n (1.14.1)
15
15
  concurrent-ruby (~> 1.0)
16
16
  json (2.6.3)
17
17
  language_server-protocol (3.17.0.3)
@@ -19,18 +19,20 @@ GEM
19
19
  rb-fsevent (~> 0.10, >= 0.10.3)
20
20
  rb-inotify (~> 0.9, >= 0.9.10)
21
21
  logger (1.5.3)
22
- minitest (5.18.0)
23
- parser (3.2.2.1)
22
+ minitest (5.18.1)
23
+ parser (3.2.2.3)
24
24
  ast (~> 2.4.1)
25
+ racc
26
+ racc (1.7.1)
25
27
  rainbow (3.1.1)
26
28
  rb-fsevent (0.11.2)
27
29
  rb-inotify (0.10.1)
28
30
  ffi (~> 1.0)
29
- rbs (3.1.0)
31
+ rbs (3.1.1)
30
32
  securerandom (0.2.2)
31
- steep (1.4.0)
33
+ steep (1.5.0)
32
34
  activesupport (>= 5.1)
33
- concurrent-ruby (>= 1.2.2)
35
+ concurrent-ruby (>= 1.1.10)
34
36
  csv (>= 3.0.9)
35
37
  fileutils (>= 1.1.0)
36
38
  json (>= 2.1.0)
@@ -39,7 +41,7 @@ GEM
39
41
  logger (>= 1.3.0)
40
42
  parser (>= 3.1)
41
43
  rainbow (>= 2.2.2, < 4.0)
42
- rbs (>= 2.8.0)
44
+ rbs (>= 3.1.0)
43
45
  securerandom (>= 0.1)
44
46
  strscan (>= 1.0.0)
45
47
  terminal-table (>= 2, < 4)
data/Steepfile CHANGED
@@ -3,13 +3,12 @@ D = Steep::Diagnostic
3
3
  target :app do
4
4
  check "lib"
5
5
  ignore "lib/steep/shims"
6
-
6
+
7
7
  signature "sig"
8
8
 
9
9
  collection_config "rbs_collection.steep.yaml"
10
10
 
11
- configure_code_diagnostics do |hash| # You can setup everything yourself
12
- hash[D::Ruby::MethodDefinitionMissing] = :hint
11
+ configure_code_diagnostics(D::Ruby.strict) do |hash|
13
12
  end
14
13
 
15
14
  FileUtils.mkpath("tmp")
@@ -110,20 +110,20 @@ module Steep
110
110
  end
111
111
 
112
112
  def lvar_types
113
- var_type_annotations.each_key.with_object({}) do |name, hash|
114
- hash[name] = var_type(lvar: name)
113
+ var_type_annotations.each_key.with_object({}) do |name, hash| #$ Hash[Symbol, Types::t]
114
+ hash[name] = var_type(lvar: name) || raise
115
115
  end
116
116
  end
117
117
 
118
118
  def ivar_types
119
- ivar_type_annotations.each_key.with_object({}) do |name, hash|
120
- hash[name] = var_type(ivar: name)
119
+ ivar_type_annotations.each_key.with_object({}) do |name, hash| #$ Hash[Symbol, Types::t]
120
+ hash[name] = var_type(ivar: name) || raise
121
121
  end
122
122
  end
123
123
 
124
124
  def const_types
125
- const_type_annotations.each_key.with_object({}) do |name, hash|
126
- hash[name] = var_type(const: name)
125
+ const_type_annotations.each_key.with_object({}) do |name, hash| #$ Hash[RBS::TypeName, Types::t]
126
+ hash[name] = var_type(const: name) || raise
127
127
  end
128
128
  end
129
129
 
@@ -841,7 +841,6 @@ module Steep
841
841
  end
842
842
 
843
843
  class UnexpectedError < Base
844
- attr_reader :message
845
844
  attr_reader :error
846
845
 
847
846
  def initialize(node:, error:)
@@ -850,7 +849,28 @@ module Steep
850
849
  end
851
850
 
852
851
  def header_line
853
- "UnexpectedError: #{error.message}"
852
+ "UnexpectedError: #{error.message}(#{error.class})"
853
+ end
854
+
855
+ def detail_lines
856
+ if trace = error.backtrace
857
+ io = StringIO.new
858
+
859
+ total = trace.size
860
+ if total > 30
861
+ trace = trace.take(15)
862
+ end
863
+
864
+ trace.each.with_index do |line, index|
865
+ io.puts "#{index+1}. #{line}"
866
+ end
867
+
868
+ if trace.size != total
869
+ io.puts " (#{total - trace.size} more backtrace)"
870
+ end
871
+
872
+ io.string
873
+ end
854
874
  end
855
875
  end
856
876
 
@@ -168,8 +168,7 @@ module Steep
168
168
 
169
169
  Steep.logger.info { "Starting type checking: #{request_guid}" }
170
170
 
171
- diagnostic_notifications = []
172
- error_messages = []
171
+ error_messages = [] #: Array[String]
173
172
  client_reader.read do |response|
174
173
  case
175
174
  when response[:method] == "textDocument/publishDiagnostics"
@@ -54,7 +54,7 @@ module Steep
54
54
  end
55
55
 
56
56
  def print(stats_result)
57
- rows = []
57
+ rows = [] #: Array[Array[untyped]]
58
58
  stats_result.sort_by {|row| row[:path] }.each do |row|
59
59
  if row[:type] == "success"
60
60
  rows << [
@@ -471,8 +471,8 @@ module Steep
471
471
 
472
472
  # For overloading
473
473
  def +(other)
474
- requireds = {}
475
- optionals = {}
474
+ requireds = {} #: Hash[Symbol, AST::Types::t]
475
+ optionals = {} #: Hash[Symbol, AST::Types::t]
476
476
 
477
477
  all_keys = Set[] + self.requireds.keys + self.optionals.keys + other.requireds.keys + other.optionals.keys
478
478
  all_keys.each do |key|
@@ -535,8 +535,8 @@ module Steep
535
535
 
536
536
  # For union
537
537
  def |(other)
538
- requireds = {}
539
- optionals = {}
538
+ requireds = {} #: Hash[Symbol, AST::Types::t]
539
+ optionals = {} #: Hash[Symbol, AST::Types::t]
540
540
 
541
541
  all_keys = Set[] + self.requireds.keys + self.optionals.keys + other.requireds.keys + other.optionals.keys
542
542
  all_keys.each do |key|
@@ -600,8 +600,8 @@ module Steep
600
600
 
601
601
  # For intersection
602
602
  def &(other)
603
- requireds = {}
604
- optionals = {}
603
+ requireds = {} #: Hash[Symbol, AST::Types::t]
604
+ optionals = {} #: Hash[Symbol, AST::Types::t]
605
605
 
606
606
  all_keys = Set[] + self.requireds.keys + self.optionals.keys + other.requireds.keys + other.optionals.keys
607
607
  all_keys.each do |key|
@@ -665,7 +665,7 @@ module Steep
665
665
  end
666
666
 
667
667
  def required
668
- array = []
668
+ array = [] #: Array[AST::Types::t]
669
669
 
670
670
  positional_params&.each do |param|
671
671
  case param
@@ -680,7 +680,7 @@ module Steep
680
680
  end
681
681
 
682
682
  def optional
683
- array = []
683
+ array = [] #: Array[AST::Types::t]
684
684
 
685
685
  positional_params&.each do |param|
686
686
  case param
@@ -66,7 +66,7 @@ module Steep
66
66
  def typing_options(level = nil, **hash)
67
67
  Steep.logger.error "#typing_options is deprecated and has no effect as of version 0.46.0. Update your Steepfile as follows for (almost) equivalent setting:"
68
68
 
69
- messages = []
69
+ messages = [] #: Array[String]
70
70
 
71
71
  messages << "# D = Steep::Diagnostic # Define a constant to shorten namespace"
72
72
 
@@ -83,7 +83,7 @@ module Steep
83
83
  Steep.logger.error " #{msg}"
84
84
  end
85
85
 
86
- config = []
86
+ config = [] #: Array[String]
87
87
 
88
88
  if hash[:allow_missing_definitions]
89
89
  config << "hash[D::Ruby::MethodDefinitionMissing] = nil # allow_missing_definitions"
@@ -122,7 +122,7 @@ module Steep
122
122
  items = begin
123
123
  provider.run(line: job.line, column: job.column)
124
124
  rescue Parser::SyntaxError
125
- []
125
+ [] #: Array[Services::CompletionProvider::item]
126
126
  end
127
127
 
128
128
  completion_items = items.map do |item|
@@ -157,7 +157,7 @@ module Steep
157
157
  locator = RBS::Locator.new(buffer: buffer, dirs: dirs, decls: decls)
158
158
 
159
159
  _hd, tail = locator.find2(line: job.line, column: job.column)
160
- tail ||= []
160
+ tail ||= [] #: Array[RBS::Locator::component]
161
161
 
162
162
  tail.reverse_each do |t|
163
163
  case t
@@ -430,7 +430,7 @@ module Steep
430
430
  when AST::Types::Name::Singleton
431
431
  singleton_super_types(relation.sub_type.name)
432
432
  else
433
- []
433
+ [] #: Array[super_type]
434
434
  end
435
435
 
436
436
  unless possible_sub_types.empty?
@@ -743,7 +743,7 @@ module Steep
743
743
  args.each {|arg| constraints.unknown!(arg.name) }
744
744
 
745
745
  upper_bounds = {}
746
- relations = []
746
+ relations = [] #: Array[Relation]
747
747
 
748
748
  args.zip(sub_type.type_params, super_type.type_params).each do |arg, sub_param, sup_param|
749
749
  sub_ub = sub_param.upper_bound
@@ -249,8 +249,8 @@ module Steep
249
249
  class_type = context.class_type
250
250
  end
251
251
 
252
- vars = []
253
- types = []
252
+ vars = [] #: Array[Symbol]
253
+ types = [] #: Array[AST::Types::t]
254
254
 
255
255
  dictionary.each_key do |var|
256
256
  if variables.include?(var)
@@ -1778,7 +1778,10 @@ module Steep
1778
1778
  yield_self do
1779
1779
  left_node, right_node = node.children
1780
1780
 
1781
- left_type, constr, left_context = synthesize(left_node, hint: hint, condition: true).to_ary
1781
+ if hint
1782
+ left_hint = union_type_unify(hint, AST::Builtin.nil_type, AST::Builtin.false_type)
1783
+ end
1784
+ left_type, constr, left_context = synthesize(left_node, hint: left_hint, condition: true).to_ary
1782
1785
 
1783
1786
  interpreter = TypeInference::LogicTypeInterpreter.new(subtyping: checker, typing: typing, config: builder_config)
1784
1787
  left_truthy, left_falsy = interpreter.eval(env: left_context.type_env, node: left_node)
@@ -1888,7 +1891,7 @@ module Steep
1888
1891
  if loc.respond_to?(:keyword)
1889
1892
  condition_loc = loc #: NodeHelper::condition_loc
1890
1893
  case condition_loc.keyword.source
1891
- when "if"
1894
+ when "if", "elsif"
1892
1895
  location = condition_loc.begin || condition_loc.keyword
1893
1896
  when "unless"
1894
1897
  # `else` token always exists
@@ -1913,8 +1916,9 @@ module Steep
1913
1916
 
1914
1917
  if loc.respond_to?(:keyword)
1915
1918
  condition_loc = loc #: NodeHelper::condition_loc
1919
+
1916
1920
  case condition_loc.keyword.source
1917
- when "if"
1921
+ when "if", "elsif"
1918
1922
  # `else` token always exists
1919
1923
  location = condition_loc.else || raise
1920
1924
  when "unless"
@@ -9,7 +9,7 @@ module Steep
9
9
  attr_reader :pure_method_calls
10
10
 
11
11
  def to_s
12
- array = []
12
+ array = [] #: Array[String]
13
13
 
14
14
  local_variable_types.each do |name, entry|
15
15
  if enforced_type = entry[1]
@@ -108,7 +108,7 @@ module Steep
108
108
  end
109
109
 
110
110
  def assign_local_variables(assignments)
111
- local_variable_types = {}
111
+ local_variable_types = {} #: Hash[Symbol, local_variable_entry]
112
112
  invalidated_nodes = Set[]
113
113
 
114
114
  assignments.each do |name, new_type|
@@ -135,7 +135,7 @@ module Steep
135
135
  end
136
136
 
137
137
  def refine_types(local_variable_types: {}, pure_call_types: {})
138
- local_variable_updates = {}
138
+ local_variable_updates = {} #: Hash[Symbol, local_variable_entry]
139
139
 
140
140
  local_variable_types.each do |name, type|
141
141
  local_variable_name!(name)
data/lib/steep/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Steep
2
- VERSION = "1.5.0"
2
+ VERSION = "1.5.1"
3
3
  end
@@ -32,3 +32,8 @@ class HogeHoge
32
32
  bar(self, ...).to_s
33
33
  end
34
34
  end
35
+
36
+
37
+
38
+ conference = nil #: Conference?
39
+
@@ -2,7 +2,7 @@ module Steep
2
2
  module AST
3
3
  module Annotation
4
4
  class Collection
5
- attr_reader annotations: untyped
5
+ attr_reader annotations: Array[Annotation::t]
6
6
 
7
7
  attr_reader factory: Types::Factory
8
8
 
@@ -14,31 +14,34 @@ module Steep
14
14
 
15
15
  attr_reader ivar_type_annotations: Hash[Symbol, IvarType]
16
16
 
17
- attr_reader method_type_annotations: untyped
17
+ attr_reader method_type_annotations: Hash[Symbol, MethodType?]
18
18
 
19
- attr_reader block_type_annotation: untyped
19
+ attr_reader block_type_annotation: BlockType?
20
20
 
21
- attr_reader return_type_annotation: untyped
21
+ attr_reader return_type_annotation: ReturnType?
22
22
 
23
- attr_reader self_type_annotation: untyped
23
+ attr_reader self_type_annotation: SelfType?
24
24
 
25
- attr_reader instance_type_annotation: untyped
25
+ attr_reader instance_type_annotation: InstanceType?
26
26
 
27
- attr_reader module_type_annotation: untyped
27
+ attr_reader module_type_annotation: ModuleType?
28
28
 
29
29
  attr_reader implement_module_annotation: Implements?
30
30
 
31
- attr_reader dynamic_annotations: untyped
31
+ attr_reader dynamic_annotations: Array[Dynamic]
32
32
 
33
- attr_reader break_type_annotation: untyped
33
+ attr_reader break_type_annotation: BreakType?
34
34
 
35
- def initialize: (annotations: untyped, factory: untyped, context: untyped) -> void
35
+ def initialize: (annotations: Array[Annotation::t], factory: Types::Factory, context: RBS::Resolver::context) -> void
36
36
 
37
- def absolute_type: (untyped `type`) -> (untyped | nil)
37
+ def absolute_type: (Types::t) -> Types::t
38
+ | (Types::t?) -> Types::t?
38
39
 
39
- def var_type: (?lvar: untyped?, ?ivar: untyped?, ?const: untyped?) -> untyped
40
+ def var_type: (lvar: Symbol) -> Types::t?
41
+ | (ivar: Symbol) -> Types::t?
42
+ | (const: RBS::TypeName) -> Types::t?
40
43
 
41
- def method_type: (untyped name) -> (untyped | nil)
44
+ def method_type: (Symbol name) -> Interface::MethodType?
42
45
 
43
46
  %a{pure} def block_type: () -> Types::t?
44
47
 
@@ -52,23 +55,23 @@ module Steep
52
55
 
53
56
  %a{pure} def break_type: () -> Types::t?
54
57
 
55
- def lvar_types: () -> untyped
58
+ def lvar_types: () -> Hash[Symbol, Types::t]
56
59
 
57
- def ivar_types: () -> untyped
60
+ def ivar_types: () -> Hash[Symbol, Types::t]
58
61
 
59
- def const_types: () -> untyped
62
+ def const_types: () -> Hash[RBS::TypeName, Types::t]
60
63
 
61
- def instance_dynamics: () -> untyped
64
+ def instance_dynamics: () -> Array[Symbol]
62
65
 
63
- def module_dynamics: () -> untyped
66
+ def module_dynamics: () -> Array[Symbol]
64
67
 
65
- def merge_block_annotations: (untyped annotations) -> untyped
68
+ def merge_block_annotations: (Collection annotations) -> Collection
66
69
 
67
- def any?: () { () -> untyped } -> untyped
70
+ def any?: () { (Annotation::t) -> boolish } -> bool
68
71
 
69
- def size: () -> untyped
72
+ def size: () -> Integer
70
73
 
71
- def include?: (untyped obj) -> untyped
74
+ def include?: (Annotation::t obj) -> bool
72
75
  end
73
76
  end
74
77
  end
@@ -546,11 +546,9 @@ module Steep
546
546
  end
547
547
 
548
548
  class UnexpectedError < Base
549
- attr_reader message: untyped
550
-
551
- attr_reader error: untyped
549
+ attr_reader error: Exception
552
550
 
553
- def initialize: (node: untyped, error: untyped) -> void
551
+ def initialize: (node: Parser::AST::Node, error: Exception) -> void
554
552
 
555
553
  def header_line: () -> ::String
556
554
  end
@@ -1,16 +1,4 @@
1
1
  ---
2
- - file: unexpected.rb
3
- diagnostics:
4
- - range:
5
- start:
6
- line: 1
7
- character: 0
8
- end:
9
- line: 1
10
- character: 14
11
- severity: ERROR
12
- message: 'UnexpectedError: unexpected.rbs:2:17...2:24: Could not find String1'
13
- code: Ruby::UnexpectedError
14
2
  - file: unexpected.rbs
15
3
  diagnostics:
16
4
  - 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: 1.5.0
4
+ version: 1.5.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: 2023-07-13 00:00:00.000000000 Z
11
+ date: 2023-07-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -266,7 +266,6 @@ files:
266
266
  - lib/steep/ast/builtin.rb
267
267
  - lib/steep/ast/node/type_application.rb
268
268
  - lib/steep/ast/node/type_assertion.rb
269
- - lib/steep/ast/type_params.rb
270
269
  - lib/steep/ast/types/any.rb
271
270
  - lib/steep/ast/types/boolean.rb
272
271
  - lib/steep/ast/types/bot.rb
@@ -401,7 +400,6 @@ files:
401
400
  - sig/steep/ast/builtin.rbs
402
401
  - sig/steep/ast/node/type_application.rbs
403
402
  - sig/steep/ast/node/type_assertion.rbs
404
- - sig/steep/ast/type_params.rbs
405
403
  - sig/steep/ast/types.rbs
406
404
  - sig/steep/ast/types/any.rbs
407
405
  - sig/steep/ast/types/boolean.rbs
@@ -757,7 +755,6 @@ files:
757
755
  - smoke/type_case/test_expectations.yml
758
756
  - smoke/unexpected/Steepfile
759
757
  - smoke/unexpected/test_expectations.yml
760
- - smoke/unexpected/unexpected.rb
761
758
  - smoke/unexpected/unexpected.rbs
762
759
  - smoke/yield/Steepfile
763
760
  - smoke/yield/a.rb
@@ -1,13 +0,0 @@
1
- module Steep
2
- module AST
3
- class TypeParams
4
- attr_reader :location
5
- attr_reader :variables
6
-
7
- def initialize(location: nil, variables:)
8
- @location = location
9
- @variables = variables
10
- end
11
- end
12
- end
13
- end
@@ -1,11 +0,0 @@
1
- # module Steep
2
- # module AST
3
- # class TypeParams
4
- # attr_reader location: untyped
5
-
6
- # attr_reader variables: untyped
7
-
8
- # def initialize: (variables: untyped, ?location: untyped?) -> void
9
- # end
10
- # end
11
- # end
@@ -1 +0,0 @@
1
- Unexpected.new.foo().bar