steep 0.28.0 → 0.32.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +27 -0
  3. data/bin/steep-prof +1 -2
  4. data/lib/steep.rb +5 -3
  5. data/lib/steep/annotation_parser.rb +2 -4
  6. data/lib/steep/ast/builtin.rb +9 -1
  7. data/lib/steep/ast/types/factory.rb +177 -53
  8. data/lib/steep/ast/types/logic.rb +63 -0
  9. data/lib/steep/interface/method_type.rb +14 -4
  10. data/lib/steep/module_helper.rb +25 -0
  11. data/lib/steep/project.rb +25 -0
  12. data/lib/steep/project/completion_provider.rb +57 -58
  13. data/lib/steep/project/file_loader.rb +7 -2
  14. data/lib/steep/project/hover_content.rb +92 -83
  15. data/lib/steep/project/signature_file.rb +33 -0
  16. data/lib/steep/project/{file.rb → source_file.rb} +24 -54
  17. data/lib/steep/project/target.rb +31 -12
  18. data/lib/steep/server/code_worker.rb +30 -46
  19. data/lib/steep/server/interaction_worker.rb +42 -38
  20. data/lib/steep/server/master.rb +13 -30
  21. data/lib/steep/server/utils.rb +46 -13
  22. data/lib/steep/server/worker_process.rb +4 -2
  23. data/lib/steep/signature/validator.rb +3 -3
  24. data/lib/steep/source.rb +58 -1
  25. data/lib/steep/subtyping/check.rb +5 -7
  26. data/lib/steep/subtyping/constraints.rb +8 -0
  27. data/lib/steep/type_construction.rb +204 -207
  28. data/lib/steep/type_inference/constant_env.rb +2 -5
  29. data/lib/steep/type_inference/logic_type_interpreter.rb +225 -0
  30. data/lib/steep/type_inference/type_env.rb +2 -2
  31. data/lib/steep/version.rb +1 -1
  32. data/smoke/toplevel/Steepfile +5 -0
  33. data/smoke/toplevel/a.rb +4 -0
  34. data/smoke/toplevel/a.rbs +3 -0
  35. data/smoke/type_case/a.rb +0 -7
  36. data/steep.gemspec +2 -2
  37. metadata +18 -14
  38. data/lib/steep/ast/method_type.rb +0 -126
  39. data/lib/steep/ast/namespace.rb +0 -80
  40. data/lib/steep/names.rb +0 -86
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e15a2388cd89e6b169243007211840853be8c126e035f7aa6434b00258e1087
4
- data.tar.gz: e3bb8c7a1d816cb2667e7dc977f5e3155bcb9444e995a210bd58dc716a6a71b7
3
+ metadata.gz: 5aa3a8e2257e84d0ed22ede78f6ddc038a43bada5127863bf308ec00e5cb2ca6
4
+ data.tar.gz: fc29cc0b62e9a9c0bfdf3e1a2093e50bb6a53c474ca5de9472a7297694f6f020
5
5
  SHA512:
6
- metadata.gz: fb77f06dcef27e222984269a637966fa581cd78b3157c31a71793e8447f7059467140b7bb3f8f3e7f059a37492c9988f428234011ff7b3f7133a627f60a63cf4
7
- data.tar.gz: 9319aebc6f74f89d055098312f460b2ed86ae9cfcd5c17bd21425c69e3ebe8838dffa3f4db9c99bc23bbc4657e4ee9f453bf1a2b3b7e4afe1531c0ba0ccb386c
6
+ metadata.gz: 827e7bf852501b156d0f77b4120401ad02a5ed070335342d7b316f37c286f347cc183e2f1a68849c9f0d2f78cdd53d64a0a8151f2958d8b7562fda0afb256ccc
7
+ data.tar.gz: 72444df723fe5ffaf552e6e5e92e7318c71d5ed9b2d77048faa928368626423b59ed9046b4a16cc916819f4fef8343b5e1866f9715ed95c701770dc49ec6a47d
@@ -2,6 +2,33 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.32.0 (2020-10-09)
6
+
7
+ * Let type-case support interface types ([#237](https://github.com/soutaro/steep/pull/237))
8
+
9
+ ## 0.31.1 (2020-10-07)
10
+
11
+ * Fix `if-then-else` parsing ([#236](https://github.com/soutaro/steep/pull/236))
12
+
13
+ ## 0.31.0 (2020-10-04)
14
+
15
+ * Fix type checking performance ([#230](https://github.com/soutaro/steep/pull/230))
16
+ * Improve LSP completion/hover performance ([#232](https://github.com/soutaro/steep/pull/232))
17
+ * Fix instance variable completion ([#234](https://github.com/soutaro/steep/pull/234))
18
+ * Relax version requirements on Listen to allow installing on Ruby 3 ([#235](https://github.com/soutaro/steep/pull/235))
19
+
20
+ ## 0.30.0 (2020-10-03)
21
+
22
+ * Let top-level defs be methods of Object ([#227](https://github.com/soutaro/steep/pull/227))
23
+ * Fix error caused by attribute definitions ([#228](https://github.com/soutaro/steep/pull/228))
24
+ * LSP worker improvements ([#222](https://github.com/soutaro/steep/pull/222), [#223](https://github.com/soutaro/steep/pull/223), [#226](https://github.com/soutaro/steep/pull/226), [#229](https://github.com/soutaro/steep/pull/229))
25
+
26
+ ## 0.29.0 (2020-09-28)
27
+
28
+ * Implement reasoning on `is_a?`, `nil?`, and `===` methods. ([#218](https://github.com/soutaro/steep/pull/218))
29
+ * Better completion based on interface ([#215](https://github.com/soutaro/steep/pull/215))
30
+ * Fix begin-rescue typing ([#221](https://github.com/soutaro/steep/pull/221))
31
+
5
32
  ## 0.28.0 (2020-09-17)
6
33
 
7
34
  * Fix typing case-when with empty body ([#200](https://github.com/soutaro/steep/pull/200))
@@ -9,8 +9,7 @@ def exit(*)
9
9
 
10
10
  end
11
11
 
12
-
13
12
  STDERR.puts "Running profiler: mode=#{mode}, out=#{out}"
14
- StackProf.run(mode: mode, out: out) do
13
+ StackProf.run(mode: mode, out: out, raw: true) do
15
14
  load File.join(__dir__, "../exe/steep")
16
15
  end
@@ -16,8 +16,6 @@ require 'uri'
16
16
 
17
17
  require "rbs"
18
18
 
19
- require "steep/ast/namespace"
20
- require "steep/names"
21
19
  require "steep/ast/location"
22
20
  require "steep/ast/types/helper"
23
21
  require "steep/ast/types/any"
@@ -37,6 +35,7 @@ require "steep/ast/types/boolean"
37
35
  require "steep/ast/types/tuple"
38
36
  require "steep/ast/types/proc"
39
37
  require "steep/ast/types/record"
38
+ require "steep/ast/types/logic"
40
39
  require "steep/ast/type_params"
41
40
  require "steep/ast/annotation"
42
41
  require "steep/ast/annotation/collection"
@@ -62,6 +61,7 @@ require "steep/source"
62
61
  require "steep/annotation_parser"
63
62
  require "steep/typing"
64
63
  require "steep/errors"
64
+ require "steep/module_helper"
65
65
  require "steep/type_construction"
66
66
  require "steep/type_inference/context"
67
67
  require "steep/type_inference/context_array"
@@ -71,6 +71,7 @@ require "steep/type_inference/constant_env"
71
71
  require "steep/type_inference/type_env"
72
72
  require "steep/type_inference/local_variable_type_env"
73
73
  require "steep/type_inference/logic"
74
+ require "steep/type_inference/logic_type_interpreter"
74
75
  require "steep/ast/types"
75
76
 
76
77
  require "steep/server/utils"
@@ -82,7 +83,8 @@ require "steep/server/interaction_worker"
82
83
  require "steep/server/master"
83
84
 
84
85
  require "steep/project"
85
- require "steep/project/file"
86
+ require "steep/project/signature_file"
87
+ require "steep/project/source_file"
86
88
  require "steep/project/options"
87
89
  require "steep/project/target"
88
90
  require "steep/project/dsl"
@@ -80,9 +80,7 @@ module Steep
80
80
  name = match[:name]
81
81
  type = parse_type(match[:type])
82
82
 
83
- AST::Annotation::ConstType.new(name: Names::Module.parse(name),
84
- type: type,
85
- location: location)
83
+ AST::Annotation::ConstType.new(name: TypeName(name), type: type, location: location)
86
84
  end
87
85
 
88
86
  when keyword_subject_type("ivar", IVAR_NAME)
@@ -152,7 +150,7 @@ module Steep
152
150
 
153
151
  when /@implements\s+(?<name>#{CONST_NAME})#{TYPE_PARAMS}$/
154
152
  Regexp.last_match.yield_self do |match|
155
- type_name = Names::Module.parse(match[:name])
153
+ type_name = TypeName(match[:name])
156
154
  params = match[:params]&.yield_self {|params| params.split(/,/).map {|param| param.strip.to_sym } } || []
157
155
 
158
156
  name = AST::Annotation::Implements::Module.new(name: type_name, args: params)
@@ -6,7 +6,7 @@ module Steep
6
6
  attr_reader :arity
7
7
 
8
8
  def initialize(module_name, arity: 0)
9
- @module_name = Names::Module.parse(module_name)
9
+ @module_name = TypeName(module_name)
10
10
  @arity = arity
11
11
  end
12
12
 
@@ -81,6 +81,14 @@ module Steep
81
81
  def self.optional(type)
82
82
  AST::Types::Union.build(types: [type, nil_type])
83
83
  end
84
+
85
+ def self.true_type
86
+ AST::Types::Literal.new(value: true)
87
+ end
88
+
89
+ def self.false_type
90
+ AST::Types::Literal.new(value: false)
91
+ end
84
92
  end
85
93
  end
86
94
  end
@@ -7,11 +7,14 @@ module Steep
7
7
  attr_reader :type_name_cache
8
8
  attr_reader :type_cache
9
9
 
10
+ attr_reader :type_interface_cache
11
+
10
12
  def initialize(builder:)
11
13
  @definition_builder = builder
12
14
 
13
15
  @type_name_cache = {}
14
16
  @type_cache = {}
17
+ @type_interface_cache = {}
15
18
  end
16
19
 
17
20
  def type_name_resolver
@@ -43,18 +46,18 @@ module Steep
43
46
  when RBS::Types::Variable
44
47
  Var.new(name: type.name, location: nil)
45
48
  when RBS::Types::ClassSingleton
46
- type_name = type_name(type.name)
49
+ type_name = type.name
47
50
  Name::Singleton.new(name: type_name, location: nil)
48
51
  when RBS::Types::ClassInstance
49
- type_name = type_name(type.name)
52
+ type_name = type.name
50
53
  args = type.args.map {|arg| type(arg) }
51
54
  Name::Instance.new(name: type_name, args: args, location: nil)
52
55
  when RBS::Types::Interface
53
- type_name = type_name(type.name)
56
+ type_name = type.name
54
57
  args = type.args.map {|arg| type(arg) }
55
58
  Name::Interface.new(name: type_name, args: args, location: nil)
56
59
  when RBS::Types::Alias
57
- type_name = type_name(type.name)
60
+ type_name = type.name
58
61
  Name::Alias.new(name: type_name, args: [], location: nil)
59
62
  when RBS::Types::Union
60
63
  Union.build(types: type.types.map {|ty| type(ty) }, location: nil)
@@ -103,22 +106,22 @@ module Steep
103
106
  when Var
104
107
  RBS::Types::Variable.new(name: type.name, location: nil)
105
108
  when Name::Singleton
106
- RBS::Types::ClassSingleton.new(name: type_name_1(type.name), location: nil)
109
+ RBS::Types::ClassSingleton.new(name: type.name, location: nil)
107
110
  when Name::Instance
108
111
  RBS::Types::ClassInstance.new(
109
- name: type_name_1(type.name),
112
+ name: type.name,
110
113
  args: type.args.map {|arg| type_1(arg) },
111
114
  location: nil
112
115
  )
113
116
  when Name::Interface
114
117
  RBS::Types::Interface.new(
115
- name: type_name_1(type.name),
118
+ name: type.name,
116
119
  args: type.args.map {|arg| type_1(arg) },
117
120
  location: nil
118
121
  )
119
122
  when Name::Alias
120
123
  type.args.empty? or raise "alias type with args is not supported"
121
- RBS::Types::Alias.new(name: type_name_1(type.name), location: nil)
124
+ RBS::Types::Alias.new(name: type.name, location: nil)
122
125
  when Union
123
126
  RBS::Types::Union.new(
124
127
  types: type.types.map {|ty| type_1(ty) },
@@ -151,32 +154,6 @@ module Steep
151
154
  end
152
155
  end
153
156
 
154
- def type_name(name)
155
- n = type_name_cache[name] and return n
156
-
157
- type_name_cache[name] =
158
- (case
159
- when name.class?
160
- Names::Module.new(name: name.name, namespace: namespace(name.namespace), location: nil)
161
- when name.interface?
162
- Names::Interface.new(name: name.name, namespace: namespace(name.namespace), location: nil)
163
- when name.alias?
164
- Names::Alias.new(name: name.name, namespace: namespace(name.namespace), location: nil)
165
- end)
166
- end
167
-
168
- def type_name_1(name)
169
- RBS::TypeName.new(name: name.name, namespace: namespace_1(name.namespace))
170
- end
171
-
172
- def namespace(namespace)
173
- Namespace.parse(namespace.to_s)
174
- end
175
-
176
- def namespace_1(namespace)
177
- RBS::Namespace.parse(namespace.to_s)
178
- end
179
-
180
157
  def function_1(params, return_type)
181
158
  RBS::Types::Function.new(
182
159
  required_positionals: params.required.map {|type| RBS::Types::Function::Param.new(name: nil, type: type_1(type)) },
@@ -201,7 +178,7 @@ module Steep
201
178
  )
202
179
  end
203
180
 
204
- def method_type(method_type, self_type:, subst2: nil)
181
+ def method_type(method_type, self_type:, subst2: nil, method_def: nil)
205
182
  fvs = self_type.free_variables()
206
183
 
207
184
  type_params = []
@@ -225,14 +202,15 @@ module Steep
225
202
  type_params: type_params,
226
203
  return_type: type(method_type.type.return_type).subst(subst),
227
204
  params: params(method_type.type).subst(subst),
228
- location: nil,
229
205
  block: method_type.block&.yield_self do |block|
230
206
  Interface::Block.new(
231
207
  optional: !block.required,
232
208
  type: Proc.new(params: params(block.type).subst(subst),
233
209
  return_type: type(block.type.return_type).subst(subst), location: nil)
234
210
  )
235
- end
211
+ end,
212
+ method_def: method_def,
213
+ location: method_def&.member&.location
236
214
  )
237
215
 
238
216
  if block_given?
@@ -292,7 +270,7 @@ module Steep
292
270
  end
293
271
 
294
272
  def unfold(type_name)
295
- type_name_1(type_name).yield_self do |type_name|
273
+ type_name.yield_self do |type_name|
296
274
  type(definition_builder.expand_alias(type_name))
297
275
  end
298
276
  end
@@ -312,20 +290,129 @@ module Steep
312
290
  end
313
291
  end
314
292
 
293
+ def deep_expand_alias(type, recursive: Set.new, &block)
294
+ raise "Recursive type definition: #{type}" if recursive.member?(type)
295
+
296
+ ty = case type
297
+ when AST::Types::Name::Alias
298
+ deep_expand_alias(expand_alias(type), recursive: recursive.union([type]))
299
+ when AST::Types::Union
300
+ AST::Types::Union.build(
301
+ types: type.types.map {|ty| deep_expand_alias(ty, recursive: recursive, &block) },
302
+ location: type.location
303
+ )
304
+ else
305
+ type
306
+ end
307
+
308
+ if block_given?
309
+ yield ty
310
+ else
311
+ ty
312
+ end
313
+ end
314
+
315
+ def flatten_union(type, acc = [])
316
+ case type
317
+ when AST::Types::Union
318
+ type.types.each {|ty| flatten_union(ty, acc) }
319
+ else
320
+ acc << type
321
+ end
322
+
323
+ acc
324
+ end
325
+
326
+ def unwrap_optional(type)
327
+ case type
328
+ when AST::Types::Union
329
+ falsy_types, truthy_types = type.types.partition do |type|
330
+ (type.is_a?(AST::Types::Literal) && type.value == false) ||
331
+ type.is_a?(AST::Types::Nil)
332
+ end
333
+
334
+ [
335
+ AST::Types::Union.build(types: truthy_types),
336
+ AST::Types::Union.build(types: falsy_types)
337
+ ]
338
+ when AST::Types::Name::Alias
339
+ unwrap_optional(expand_alias(type))
340
+ else
341
+ [type, nil]
342
+ end
343
+ end
344
+
345
+ def setup_primitives(method_name, method_type)
346
+ if method_def = method_type.method_def
347
+ defined_in = method_def.defined_in
348
+ member = method_def.member
349
+
350
+ if member.is_a?(RBS::AST::Members::MethodDefinition)
351
+ case
352
+ when defined_in == RBS::BuiltinNames::Object.name && member.instance?
353
+ case method_name
354
+ when :is_a?, :kind_of?, :instance_of?
355
+ return method_type.with(
356
+ return_type: AST::Types::Logic::ReceiverIsArg.new(location: method_type.return_type.location)
357
+ )
358
+ when :nil?
359
+ return method_type.with(
360
+ return_type: AST::Types::Logic::ReceiverIsNil.new(location: method_type.return_type.location)
361
+ )
362
+ end
363
+
364
+ when defined_in == AST::Builtin::NilClass.module_name && member.instance?
365
+ case method_name
366
+ when :nil?
367
+ return method_type.with(
368
+ return_type: AST::Types::Logic::ReceiverIsNil.new(location: method_type.return_type.location)
369
+ )
370
+ end
371
+
372
+ when defined_in == RBS::BuiltinNames::BasicObject.name && member.instance?
373
+ case method_name
374
+ when :!
375
+ return method_type.with(
376
+ return_type: AST::Types::Logic::Not.new(location: method_type.return_type.location)
377
+ )
378
+ end
379
+
380
+ when defined_in == RBS::BuiltinNames::Module.name && member.instance?
381
+ case method_name
382
+ when :===
383
+ return method_type.with(
384
+ return_type: AST::Types::Logic::ArgIsReceiver.new(location: method_type.return_type.location)
385
+ )
386
+ end
387
+ end
388
+ end
389
+ end
390
+
391
+ method_type
392
+ end
393
+
315
394
  def interface(type, private:, self_type: type)
316
395
  Steep.logger.debug { "Factory#interface: #{type}, private=#{private}, self_type=#{self_type}" }
317
- type = expand_alias(type)
396
+
397
+ cache_key = [type, self_type, private]
398
+ if type_interface_cache.key?(cache_key)
399
+ return type_interface_cache[cache_key]
400
+ end
318
401
 
319
402
  case type
403
+ when Name::Alias
404
+ interface(expand_alias(type), private: private, self_type: self_type)
405
+
320
406
  when Self
321
407
  if self_type != type
322
408
  interface self_type, private: private, self_type: Self.new
323
409
  else
324
410
  raise "Unexpected `self` type interface"
325
411
  end
412
+
326
413
  when Name::Instance
327
414
  Interface::Interface.new(type: self_type, private: private).tap do |interface|
328
- definition = definition_builder.build_instance(type_name_1(type.name))
415
+ definition = definition_builder.build_instance(type.name)
329
416
 
330
417
  instance_type = Name::Instance.new(name: type.name,
331
418
  args: type.args.map { Any.new(location: nil) },
@@ -345,8 +432,14 @@ module Steep
345
432
  next if method.private? && !private
346
433
 
347
434
  interface.methods[name] = Interface::Interface::Entry.new(
348
- method_types: method.method_types.map do |type|
349
- method_type(type, self_type: self_type, subst2: subst)
435
+ method_types: method.defs.map do |type_def|
436
+ setup_primitives(
437
+ name,
438
+ method_type(type_def.type,
439
+ method_def: type_def,
440
+ self_type: self_type,
441
+ subst2: subst)
442
+ )
350
443
  end
351
444
  )
352
445
  end
@@ -355,7 +448,7 @@ module Steep
355
448
 
356
449
  when Name::Interface
357
450
  Interface::Interface.new(type: self_type, private: private).tap do |interface|
358
- type_name = type_name_1(type.name)
451
+ type_name = type.name
359
452
  definition = definition_builder.build_interface(type_name)
360
453
 
361
454
  subst = Interface::Substitution.build(
@@ -366,8 +459,8 @@ module Steep
366
459
 
367
460
  definition.methods.each do |name, method|
368
461
  interface.methods[name] = Interface::Interface::Entry.new(
369
- method_types: method.method_types.map do |type|
370
- method_type(type, self_type: self_type, subst2: subst)
462
+ method_types: method.defs.map do |type_def|
463
+ method_type(type_def.type, method_def: type_def, self_type: self_type, subst2: subst)
371
464
  end
372
465
  )
373
466
  end
@@ -375,7 +468,7 @@ module Steep
375
468
 
376
469
  when Name::Singleton
377
470
  Interface::Interface.new(type: self_type, private: private).tap do |interface|
378
- definition = definition_builder.build_singleton(type_name_1(type.name))
471
+ definition = definition_builder.build_singleton(type.name)
379
472
 
380
473
  instance_type = Name::Instance.new(name: type.name,
381
474
  args: definition.type_params.map {Any.new(location: nil)},
@@ -391,8 +484,14 @@ module Steep
391
484
  next if !private && method.private?
392
485
 
393
486
  interface.methods[name] = Interface::Interface::Entry.new(
394
- method_types: method.method_types.map do |type|
395
- method_type(type, self_type: self_type, subst2: subst)
487
+ method_types: method.defs.map do |type_def|
488
+ setup_primitives(
489
+ name,
490
+ method_type(type_def.type,
491
+ method_def: type_def,
492
+ self_type: self_type,
493
+ subst2: subst)
494
+ )
396
495
  end
397
496
  )
398
497
  end
@@ -469,6 +568,7 @@ module Steep
469
568
  rest_keywords: nil),
470
569
  block: nil,
471
570
  return_type: elem_type,
571
+ method_def: nil,
472
572
  location: nil
473
573
  )
474
574
  } + aref.method_types
@@ -488,6 +588,7 @@ module Steep
488
588
  rest_keywords: nil),
489
589
  block: nil,
490
590
  return_type: elem_type,
591
+ method_def: nil,
491
592
  location: nil
492
593
  )
493
594
  } + update.method_types
@@ -502,6 +603,7 @@ module Steep
502
603
  params: Interface::Params.empty,
503
604
  block: nil,
504
605
  return_type: type.types[0] || AST::Builtin.nil_type,
606
+ method_def: nil,
505
607
  location: nil
506
608
  )
507
609
  ]
@@ -516,6 +618,7 @@ module Steep
516
618
  params: Interface::Params.empty,
517
619
  block: nil,
518
620
  return_type: type.types.last || AST::Builtin.nil_type,
621
+ method_def: nil,
519
622
  location: nil
520
623
  )
521
624
  ]
@@ -547,6 +650,7 @@ module Steep
547
650
  rest_keywords: nil),
548
651
  block: nil,
549
652
  return_type: value_type,
653
+ method_def: nil,
550
654
  location: nil
551
655
  )
552
656
  } + ref.method_types
@@ -567,6 +671,7 @@ module Steep
567
671
  rest_keywords: nil),
568
672
  block: nil,
569
673
  return_type: value_type,
674
+ method_def: nil,
570
675
  location: nil
571
676
  )
572
677
  } + update.method_types
@@ -582,6 +687,7 @@ module Steep
582
687
  params: type.params,
583
688
  return_type: type.return_type,
584
689
  block: nil,
690
+ method_def: nil,
585
691
  location: nil
586
692
  )
587
693
 
@@ -589,19 +695,22 @@ module Steep
589
695
  interface.methods[:call] = Interface::Interface::Entry.new(method_types: [method_type])
590
696
  end
591
697
 
698
+ when Logic::Base
699
+ interface(AST::Builtin.bool_type, private: private, self_type: self_type)
700
+
592
701
  else
593
702
  raise "Unexpected type for interface: #{type}"
703
+ end.tap do |interface|
704
+ type_interface_cache[cache_key] = interface
594
705
  end
595
706
  end
596
707
 
597
708
  def module_name?(type_name)
598
- name = type_name_1(type_name)
599
- entry = env.class_decls[name] and entry.is_a?(RBS::Environment::ModuleEntry)
709
+ entry = env.class_decls[type_name] and entry.is_a?(RBS::Environment::ModuleEntry)
600
710
  end
601
711
 
602
712
  def class_name?(type_name)
603
- name = type_name_1(type_name)
604
- entry = env.class_decls[name] and entry.is_a?(RBS::Environment::ClassEntry)
713
+ entry = env.class_decls[type_name] and entry.is_a?(RBS::Environment::ClassEntry)
605
714
  end
606
715
 
607
716
  def env
@@ -616,7 +725,22 @@ module Steep
616
725
  end
617
726
 
618
727
  def absolute_type_name(type_name, namespace:)
619
- type_name_resolver.resolve(type_name, context: namespace_1(namespace).ascend)
728
+ type_name_resolver.resolve(type_name, context: namespace.ascend)
729
+ end
730
+
731
+ def instance_type(type_name, args: nil, location: nil)
732
+ raise unless type_name.class?
733
+
734
+ definition = definition_builder.build_singleton(type_name)
735
+ def_args = definition.type_params.map { Any.new(location: nil) }
736
+
737
+ if args
738
+ raise if def_args.size != args.size
739
+ else
740
+ args = def_args
741
+ end
742
+
743
+ AST::Types::Name::Instance.new(location: location, name: type_name, args: args)
620
744
  end
621
745
  end
622
746
  end