steep 1.5.0 → 1.5.2

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: d2971f6bf7e70b227ac38de9682f640c8b274d8c27db2e02ec6920163d9e26df
4
+ data.tar.gz: 6f756247c85e018f5b2feaac36238480438495d242994f9dd23ccacd52e195d2
5
5
  SHA512:
6
- metadata.gz: 6f3190f0ca65a931f9c88d99cbd67836478d754439b5630b1b68f89e9fa6d84a84cc8bde32335d4bdb38b3f13aefaeaf93a75b53722a0b6841eab27e9b689ed8
7
- data.tar.gz: 94576f1eedcb8c46ca8228e84e4100e860c0e3ed2a28dc209afa80abdeeed188118f1589dcb15d0a8edb0cd8c751f611035a15b613d284113c8cbebcce42dc6e
6
+ metadata.gz: f4ae7293b7ba2f8a33c96e470346f853f83afff373f5724a094c788841602cff54ad911ea74d73cc63471383f8fe043b217fef6528d4d6a6d91cb3351dc358e7
7
+ data.tar.gz: 720040f41d6a7c0fa11facd1bc0b8e0860cd54d3572fd698807894ff6c4fe33beea6c9fff8a4a1bd115e3b494021590ef33bfcd7035556a46cbcc00455943292
@@ -8,6 +8,13 @@ updates:
8
8
  time: "20:00"
9
9
  open-pull-requests-limit: 10
10
10
 
11
+ - package-ecosystem: bundler
12
+ directory: "/gemfile_steep"
13
+ schedule:
14
+ interval: daily
15
+ time: "20:00"
16
+ open-pull-requests-limit: 10
17
+
11
18
  - package-ecosystem: "github-actions"
12
19
  directory: "/"
13
20
  schedule:
data/CHANGELOG.md CHANGED
@@ -2,6 +2,29 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 1.5.2 (2023-07-27)
6
+
7
+ ### Type checker core
8
+
9
+ * Avoid inifinite loop in `#shape` ([#884](https://github.com/soutaro/steep/pull/884))
10
+ * Fix `nil?` typing with `untyped` receiver ([#882](https://github.com/soutaro/steep/pull/882))
11
+
12
+ ### Language server
13
+
14
+ * Avoid breaking the original source code through `CompletionProvider` ([#883](https://github.com/soutaro/steep/pull/883))
15
+
16
+ ## 1.5.1 (2023-07-20)
17
+
18
+ ### Type checker core
19
+
20
+ * Support unreachable branch detection with `elsif` ([#879](https://github.com/soutaro/steep/pull/879))
21
+ * Give an optional type hint to lhs of `||` ([#874](https://github.com/soutaro/steep/pull/874))
22
+
23
+ ### Miscellaneous
24
+
25
+ * Update steep ([#878](https://github.com/soutaro/steep/pull/878))
26
+ * Update inline type comments ([#875](https://github.com/soutaro/steep/pull/875))
27
+
5
28
  ## 1.5.0 (2023-07-13)
6
29
 
7
30
  ### Type checker core
data/Gemfile CHANGED
@@ -4,7 +4,7 @@ source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
6
  gem "rake"
7
- gem "minitest", "~> 5.18"
7
+ gem "minitest", "~> 5.19"
8
8
  gem "minitest-hooks"
9
9
  group :stackprof, optional: true do
10
10
  gem "stackprof"
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.2)
5
5
  activesupport (>= 5.1)
6
6
  concurrent-ruby (>= 1.1.10)
7
7
  csv (>= 3.0.9)
@@ -38,7 +38,7 @@ GEM
38
38
  rb-fsevent (~> 0.10, >= 0.10.3)
39
39
  rb-inotify (~> 0.9, >= 0.9.10)
40
40
  logger (1.5.3)
41
- minitest (5.18.1)
41
+ minitest (5.19.0)
42
42
  minitest-hooks (1.5.0)
43
43
  minitest (> 5.3)
44
44
  minitest-slow_test (0.2.0)
@@ -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
@@ -74,7 +74,7 @@ PLATFORMS
74
74
  ruby
75
75
 
76
76
  DEPENDENCIES
77
- minitest (~> 5.18)
77
+ minitest (~> 5.19)
78
78
  minitest-hooks
79
79
  minitest-slow_test
80
80
  rake
data/Gemfile.steep CHANGED
@@ -1,3 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gem 'steep', require: false
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")
data/bin/rbs CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env bash
2
2
 
3
3
  BINSTUB_DIR=$(cd $(dirname $0); pwd)
4
- GEMFILE=$(readlink -f ${BINSTUB_DIR}/../Gemfile.steep)
4
+ GEMFILE=$(readlink -f ${BINSTUB_DIR}/../gemfile_steep/Gemfile)
5
5
  COLLECTION=$(readlink -f ${BINSTUB_DIR}/../rbs_collection.steep.yaml)
6
6
  ROOT_DIR=$(readlink -f ${BINSTUB_DIR}/..)
7
7
 
data/bin/setup CHANGED
@@ -5,5 +5,5 @@ set -vx
5
5
 
6
6
  bundle install
7
7
 
8
- bundle install --gemfile=Gemfile.steep
8
+ bundle install --gemfile=gemfile_steep/Gemfile
9
9
  bin/rbs collection install
data/bin/steep CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env bash
2
2
 
3
3
  BINSTUB_DIR=$(cd $(dirname $0); pwd)
4
- GEMFILE=$(readlink -f ${BINSTUB_DIR}/../Gemfile.steep)
4
+ GEMFILE=$(readlink -f ${BINSTUB_DIR}/../gemfile_steep/Gemfile)
5
5
  ROOT_DIR=$(readlink -f ${BINSTUB_DIR}/..)
6
6
 
7
7
  STEEP="bundle exec --gemfile=${GEMFILE} steep"
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem 'steep', require: false
@@ -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.1)
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)
@@ -53,6 +55,7 @@ GEM
53
55
  PLATFORMS
54
56
  arm64-darwin-21
55
57
  arm64-darwin-22
58
+ x86_64-linux
56
59
 
57
60
  DEPENDENCIES
58
61
  steep
@@ -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 << [
@@ -68,6 +68,24 @@ module Steep
68
68
  )
69
69
  end
70
70
  end
71
+
72
+ def self_type?
73
+ unless self_type.is_a?(AST::Types::Self)
74
+ self_type
75
+ end
76
+ end
77
+
78
+ def instance_type?
79
+ unless instance_type.is_a?(AST::Types::Instance)
80
+ instance_type
81
+ end
82
+ end
83
+
84
+ def class_type?
85
+ unless class_type.is_a?(AST::Types::Class)
86
+ class_type
87
+ end
88
+ end
71
89
  end
72
90
 
73
91
  attr_reader :factory, :cache, :raw_object_cache
@@ -122,16 +140,18 @@ module Steep
122
140
  fetch_cache(type, public_only, config) do
123
141
  case type
124
142
  when AST::Types::Self
125
- self_type = config.self_type.subst(config.subst)
126
- shape(self_type, public_only: public_only, config: config.update(resolve_self: false))
143
+ if self_type = config.self_type?
144
+ self_type = self_type.subst(config.subst)
145
+ shape(self_type, public_only: public_only, config: config.update(resolve_self: false))
146
+ end
127
147
  when AST::Types::Instance
128
- if config.instance_type
129
- instance_type = config.instance_type.subst(config.subst)
148
+ if instance_type = config.instance_type?
149
+ instance_type = instance_type.subst(config.subst)
130
150
  shape(instance_type, public_only: public_only, config: config.update(resolve_instance: false))
131
151
  end
132
152
  when AST::Types::Class
133
- if config.class_type
134
- class_type = config.class_type.subst(config.subst)
153
+ if class_type = config.class_type?
154
+ class_type = class_type.subst(config.subst)
135
155
  shape(class_type, public_only: public_only, config: config.update(resolve_class: false))
136
156
  end
137
157
  when AST::Types::Name::Instance, AST::Types::Name::Interface, AST::Types::Name::Singleton
@@ -159,7 +179,7 @@ module Steep
159
179
  instance_var = AST::Types::Var.fresh(:INSTANCE)
160
180
 
161
181
  bounds = config.variable_bounds.merge({ self_var.name => config.self_type, instance_var.name => config.instance_type, class_var.name => config.class_type })
162
- type_ = type.subst(Substitution.build([], [], self_type: self_var, instance_type: instance_var, module_type: class_var))
182
+ type_ = type.subst(Substitution.build([], [], self_type: self_var, instance_type: instance_var, module_type: class_var)) #: AST::Types::Union
163
183
 
164
184
  config_ = config.update(resolve_self: false, resolve_class: true, resolve_instance: true, variable_bounds: bounds)
165
185
 
@@ -203,7 +223,7 @@ module Steep
203
223
  instance_var = AST::Types::Var.fresh(:INSTANCE)
204
224
 
205
225
  bounds = config.variable_bounds.merge({ self_var.name => config.self_type, instance_var.name => config.instance_type, class_var.name => config.class_type })
206
- type_ = type.subst(Substitution.build([], [], self_type: self_var, instance_type: instance_var, module_type: class_var))
226
+ type_ = type.subst(Substitution.build([], [], self_type: self_var, instance_type: instance_var, module_type: class_var)) #: AST::Types::Intersection
207
227
 
208
228
  config_ = config.update(resolve_self: false, resolve_class: true, resolve_instance: true, variable_bounds: bounds)
209
229
 
@@ -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
@@ -244,6 +244,9 @@ module Steep
244
244
 
245
245
  rescue Parser::SyntaxError => exn
246
246
  Steep.logger.info "recovering syntax error: #{exn.inspect}"
247
+
248
+ @source_text = source_text.dup
249
+
247
250
  case possible_trigger
248
251
  when "."
249
252
  if source_text[index-2] == "&"
@@ -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"
@@ -292,7 +292,7 @@ module Steep
292
292
  )
293
293
 
294
294
  truthy_result = Result.new(type: TRUE, env: truthy_env, unreachable: false)
295
- truthy_result.unreachable! if unwrap == receiver_type
295
+ truthy_result.unreachable! if no_subtyping?(sub_type: AST::Builtin.nil_type, super_type: receiver_type)
296
296
 
297
297
  falsy_result = Result.new(type: FALSE, env: falsy_env, unreachable: false)
298
298
  falsy_result.unreachable! unless unwrap
@@ -529,15 +529,14 @@ module Steep
529
529
  # 3. K <: T (example: T = Numeric, K = Integer)
530
530
  # 4. none of the above (example: T = String, K = Integer)
531
531
 
532
- relation = Subtyping::Relation.new(sub_type: type, super_type: instance_type)
533
- if subtyping.check(relation, constraints: Subtyping::Constraints.empty, self_type: AST::Types::Self.instance, instance_type: AST::Types::Instance.instance, class_type: AST::Types::Class.instance).success?
532
+ if subtyping?(sub_type: type, super_type: instance_type)
534
533
  # 1 or 2. Satisfies the condition, no narrowing because `type` is already more specific than/equals to `instance_type`
535
534
  [
536
535
  [type],
537
536
  []
538
537
  ]
539
538
  else
540
- if subtyping.check(relation.flip, constraints: Subtyping::Constraints.empty, self_type: AST::Types::Self.instance, instance_type: AST::Types::Instance.instance, class_type: AST::Types::Class.instance).success?
539
+ if subtyping?(sub_type: instance_type, super_type: type)
541
540
  # 3. Satisfied the condition, narrows to `instance_type`, but cannot remove it from *falsy* list
542
541
  [
543
542
  [instance_type],
@@ -554,6 +553,19 @@ module Steep
554
553
  end
555
554
  end
556
555
 
556
+ def no_subtyping?(sub_type:, super_type:)
557
+ relation = Subtyping::Relation.new(sub_type: sub_type, super_type: super_type)
558
+ result = subtyping.check(relation, constraints: Subtyping::Constraints.empty, self_type: AST::Types::Self.instance, instance_type: AST::Types::Instance.instance, class_type: AST::Types::Class.instance)
559
+
560
+ if result.failure?
561
+ result
562
+ end
563
+ end
564
+
565
+ def subtyping?(sub_type:, super_type:)
566
+ !no_subtyping?(sub_type: sub_type, super_type: super_type)
567
+ end
568
+
557
569
  def try_convert(type, method)
558
570
  if shape = subtyping.builder.shape(type, public_only: true, config: config)
559
571
  if entry = shape.methods[method]
@@ -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.2"
3
3
  end
@@ -103,4 +103,4 @@ gems:
103
103
  version: '0'
104
104
  source:
105
105
  type: stdlib
106
- gemfile_lock_path: Gemfile.steep.lock
106
+ gemfile_lock_path: gemfile_steep/Gemfile.lock
@@ -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
@@ -71,6 +71,18 @@ module Steep
71
71
 
72
72
  # Substitution for immediate type expressions
73
73
  def subst: () -> Substitution
74
+
75
+ # Returns `self_type`, or `nil` when it is `Types::Self`
76
+ #
77
+ def self_type?: () -> AST::Types::t?
78
+
79
+ # Returns `class_type`, or `nil` when it is `Types::Class`
80
+ #
81
+ def class_type?: () -> AST::Types::t?
82
+
83
+ # Returns `instanc_type`, or `nil` when it is `Types::Instance`
84
+ #
85
+ def instance_type?: () -> AST::Types::t?
74
86
  end
75
87
 
76
88
  attr_reader factory: AST::Types::Factory
@@ -99,6 +99,10 @@ module Steep
99
99
  def type_case_select0: (AST::Types::t `type`, RBS::TypeName klass) -> [Array[AST::Types::t], Array[AST::Types::t]]
100
100
 
101
101
  def try_convert: (AST::Types::t, Symbol) -> AST::Types::t?
102
+
103
+ def no_subtyping?: (sub_type: AST::Types::t, super_type: AST::Types::t) -> Subtyping::Result::t?
104
+
105
+ def subtyping?: (sub_type: AST::Types::t, super_type: AST::Types::t) -> bool
102
106
  end
103
107
  end
104
108
  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.2
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-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: parser
@@ -242,7 +242,6 @@ files:
242
242
  - Gemfile
243
243
  - Gemfile.lock
244
244
  - Gemfile.steep
245
- - Gemfile.steep.lock
246
245
  - LICENSE
247
246
  - README.md
248
247
  - Rakefile
@@ -255,6 +254,8 @@ files:
255
254
  - bin/steep
256
255
  - bin/steep-prof
257
256
  - exe/steep
257
+ - gemfile_steep/Gemfile
258
+ - gemfile_steep/Gemfile.lock
258
259
  - guides/README.md
259
260
  - guides/src/gem-rbs-collection/gem-rbs-collection.md
260
261
  - guides/src/getting-started/getting-started.md
@@ -266,7 +267,6 @@ files:
266
267
  - lib/steep/ast/builtin.rb
267
268
  - lib/steep/ast/node/type_application.rb
268
269
  - lib/steep/ast/node/type_assertion.rb
269
- - lib/steep/ast/type_params.rb
270
270
  - lib/steep/ast/types/any.rb
271
271
  - lib/steep/ast/types/boolean.rb
272
272
  - lib/steep/ast/types/bot.rb
@@ -401,7 +401,6 @@ files:
401
401
  - sig/steep/ast/builtin.rbs
402
402
  - sig/steep/ast/node/type_application.rbs
403
403
  - sig/steep/ast/node/type_assertion.rbs
404
- - sig/steep/ast/type_params.rbs
405
404
  - sig/steep/ast/types.rbs
406
405
  - sig/steep/ast/types/any.rbs
407
406
  - sig/steep/ast/types/boolean.rbs
@@ -757,7 +756,6 @@ files:
757
756
  - smoke/type_case/test_expectations.yml
758
757
  - smoke/unexpected/Steepfile
759
758
  - smoke/unexpected/test_expectations.yml
760
- - smoke/unexpected/unexpected.rb
761
759
  - smoke/unexpected/unexpected.rbs
762
760
  - smoke/yield/Steepfile
763
761
  - 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