steep 0.17.0 → 0.21.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -35,6 +35,14 @@ module Steep
35
35
  checker.factory.definition_builder
36
36
  end
37
37
 
38
+ def type_name_resolver
39
+ @type_name_resolver ||= RBS::TypeNameResolver.from_env(env)
40
+ end
41
+
42
+ def validator
43
+ @validator ||= RBS::Validator.new(env: env, resolver: type_name_resolver)
44
+ end
45
+
38
46
  def factory
39
47
  checker.factory
40
48
  end
@@ -47,57 +55,69 @@ module Steep
47
55
  validate_global
48
56
  end
49
57
 
50
- def validate_one_decl(name, decl)
51
- case decl
52
- when Declarations::Class
53
- rescue_validation_errors do
54
- Steep.logger.debug "#{Location.to_string decl.location}:\tValidating class definition `#{name}`..."
55
- builder.build_instance(decl.name.absolute!).each_type do |type|
56
- env.validate type, namespace: RBS::Namespace.root
58
+ def validate_type(type)
59
+ Steep.logger.debug "#{Location.to_string type.location}: Validating #{type}..."
60
+ validator.validate_type type, context: [RBS::Namespace.root]
61
+ end
62
+
63
+ def validate_one_class(name)
64
+ rescue_validation_errors do
65
+ Steep.logger.debug "Validating class definition `#{name}`..."
66
+ Steep.logger.tagged "#{name}" do
67
+ builder.build_instance(name).each_type do |type|
68
+ validate_type type
57
69
  end
58
- builder.build_singleton(decl.name.absolute!).each_type do |type|
59
- env.validate type, namespace: RBS::Namespace.root
70
+ builder.build_singleton(name).each_type do |type|
71
+ validate_type type
60
72
  end
61
73
  end
62
- when Declarations::Interface
63
- rescue_validation_errors do
64
- Steep.logger.debug "#{Location.to_string decl.location}:\tValidating interface `#{name}`..."
65
- builder.build_interface(decl.name.absolute!, decl).each_type do |type|
66
- env.validate type, namespace: RBS::Namespace.root
74
+ end
75
+ end
76
+
77
+ def validate_one_interface(name)
78
+ rescue_validation_errors do
79
+ Steep.logger.debug "Validating interface `#{name}`..."
80
+ Steep.logger.tagged "#{name}" do
81
+ builder.build_interface(name).each_type do |type|
82
+ validate_type type
67
83
  end
68
84
  end
69
85
  end
70
86
  end
71
87
 
72
88
  def validate_decl
73
- env.each_decl do |name, decl|
74
- validate_one_decl name, decl
89
+ env.class_decls.each_key do |name|
90
+ validate_one_class(name)
91
+ end
92
+
93
+ env.interface_decls.each_key do |name|
94
+ validate_one_interface(name)
75
95
  end
76
96
  end
77
97
 
78
98
  def validate_const
79
- env.each_constant do |name, decl|
99
+ env.constant_decls.each do |name, entry|
80
100
  rescue_validation_errors do
81
- Steep.logger.debug "#{Location.to_string decl.location}:\tValidating constant `#{name}`..."
82
- env.validate(decl.type, namespace: name.namespace)
101
+ Steep.logger.debug "Validating constant `#{name}`..."
102
+ validate_type entry.decl.type
83
103
  end
84
104
  end
85
105
  end
86
106
 
87
107
  def validate_global
88
- env.each_global do |name, decl|
108
+ env.global_decls.each do |name, entry|
89
109
  rescue_validation_errors do
90
- Steep.logger.debug "#{Location.to_string decl.location}:\tValidating global `#{name}`..."
91
- env.validate(decl.type, namespace: RBS::Namespace.root)
110
+ Steep.logger.debug "Validating global `#{name}`..."
111
+ validate_type entry.decl.type
92
112
  end
93
113
  end
94
114
  end
95
115
 
96
116
  def validate_alias
97
- env.each_alias do |name, decl|
117
+ env.alias_decls.each do |name, entry|
98
118
  rescue_validation_errors do
99
- Steep.logger.debug "#{Location.to_string decl.location}:\tValidating alias `#{name}`..."
100
- env.validate(decl.type, namespace: name.namespace)
119
+ Steep.logger.debug "Validating alias `#{name}`..."
120
+ validate_type(entry.decl.type)
101
121
  end
102
122
  end
103
123
  end
@@ -108,10 +128,10 @@ module Steep
108
128
  @errors << Errors::InvalidTypeApplicationError.new(
109
129
  name: factory.type_name(exn.type_name),
110
130
  args: exn.args.map {|ty| factory.type(ty) },
111
- params: exn.params.each.map(&:name),
131
+ params: exn.params,
112
132
  location: exn.location
113
133
  )
114
- rescue RBS::NoTypeFoundError => exn
134
+ rescue RBS::NoTypeFoundError, RBS::NoSuperclassFoundError, RBS::NoMixinFoundError => exn
115
135
  @errors << Errors::UnknownTypeNameError.new(
116
136
  name: factory.type_name(exn.type_name),
117
137
  location: exn.location
@@ -9,6 +9,84 @@ module Steep
9
9
  @cache = {}
10
10
  end
11
11
 
12
+ def instance_super_types(type_name, args:)
13
+ type_name_1 = factory.type_name_1(type_name)
14
+ ancestors = factory.definition_builder.one_instance_ancestors(type_name_1)
15
+
16
+ subst = unless args.empty?
17
+ args_ = args.map {|type| factory.type_1(type) }
18
+ RBS::Substitution.build(ancestors.params, args_)
19
+ end
20
+
21
+ ancestors.each_ancestor.map do |ancestor|
22
+ name = factory.type_name(ancestor.name)
23
+
24
+ case ancestor
25
+ when RBS::Definition::Ancestor::Instance
26
+ args = ancestor.args.map do |type|
27
+ type = type.sub(subst) if subst
28
+ factory.type(type)
29
+ end
30
+
31
+ if ancestor.name.class?
32
+ AST::Types::Name::Instance.new(
33
+ name: name,
34
+ args: args,
35
+ location: nil
36
+ )
37
+ else
38
+ AST::Types::Name::Interface.new(
39
+ name: name,
40
+ args: args,
41
+ location: nil
42
+ )
43
+ end
44
+ when RBS::Definition::Ancestor::Singleton
45
+ AST::Types::Name::Class.new(
46
+ name: name,
47
+ constructor: nil,
48
+ location: nil
49
+ )
50
+ end
51
+ end
52
+ end
53
+
54
+ def singleton_super_types(type_name)
55
+ type_name_1 = factory.type_name_1(type_name)
56
+ ancestors = factory.definition_builder.one_singleton_ancestors(type_name_1)
57
+
58
+ ancestors.each_ancestor.map do |ancestor|
59
+ name = factory.type_name(ancestor.name)
60
+
61
+ case ancestor
62
+ when RBS::Definition::Ancestor::Instance
63
+ args = ancestor.args.map do |type|
64
+ factory.type(type)
65
+ end
66
+
67
+ if ancestor.name.class?
68
+ AST::Types::Name::Instance.new(
69
+ name: name,
70
+ args: args,
71
+ location: nil
72
+ )
73
+ else
74
+ AST::Types::Name::Interface.new(
75
+ name: name,
76
+ args: args,
77
+ location: nil
78
+ )
79
+ end
80
+ when RBS::Definition::Ancestor::Singleton
81
+ AST::Types::Name::Class.new(
82
+ name: name,
83
+ constructor: nil,
84
+ location: nil
85
+ )
86
+ end
87
+ end
88
+ end
89
+
12
90
  def check(relation, constraints:, self_type:, assumption: Set.new, trace: Trace.new)
13
91
  Steep.logger.tagged "#{relation.sub_type} <: #{relation.super_type}" do
14
92
  prefix = trace.size
@@ -175,30 +253,45 @@ module Steep
175
253
  failure(error: Result::Failure::UnknownPairError.new(relation: relation),
176
254
  trace: trace)
177
255
 
178
- when relation.sub_type.is_a?(AST::Types::Name::Base) && relation.super_type.is_a?(AST::Types::Name::Base)
179
- if (pairs = extract_nominal_pairs(relation))
180
- results = pairs.flat_map do |(sub, sup)|
181
- Relation.new(sub_type: sub, super_type: sup).yield_self do |rel|
182
- [rel, rel.flip]
183
- end
184
- end.map do |relation|
185
- check(relation,
186
- self_type: self_type,
187
- assumption: assumption,
188
- trace: trace,
189
- constraints: constraints)
190
- end
256
+ when relation.super_type.is_a?(AST::Types::Name::Interface)
257
+ sub_interface = factory.interface(relation.sub_type, private: false)
258
+ super_interface = factory.interface(relation.super_type, private: false)
191
259
 
192
- if results.all?(&:success?)
193
- results.first
260
+ check_interface(sub_interface,
261
+ super_interface,
262
+ self_type: self_type,
263
+ assumption: assumption,
264
+ trace: trace,
265
+ constraints: constraints)
266
+
267
+ when relation.sub_type.is_a?(AST::Types::Name::Base) && relation.super_type.is_a?(AST::Types::Name::Base)
268
+ if relation.sub_type.name == relation.super_type.name && relation.sub_type.class == relation.super_type.class
269
+ if arg_type?(relation.sub_type) && arg_type?(relation.super_type)
270
+ check_type_arg(relation, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints)
194
271
  else
195
- results.find(&:failure?)
272
+ success(constraints: constraints)
196
273
  end
197
274
  else
198
- sub_interface = factory.interface(relation.sub_type, private: false)
199
- super_interface = factory.interface(relation.super_type, private: false)
200
-
201
- check_interface(sub_interface, super_interface, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints)
275
+ possible_sub_types = case relation.sub_type
276
+ when AST::Types::Name::Instance
277
+ instance_super_types(relation.sub_type.name, args: relation.sub_type.args)
278
+ when AST::Types::Name::Class
279
+ singleton_super_types(relation.sub_type.name)
280
+ else
281
+ []
282
+ end
283
+
284
+ unless possible_sub_types.empty?
285
+ success_any?(possible_sub_types) do |sub_type|
286
+ check(Relation.new(sub_type: sub_type, super_type: relation.super_type),
287
+ self_type: self_type,
288
+ assumption: assumption,
289
+ trace: trace,
290
+ constraints: constraints)
291
+ end
292
+ else
293
+ failure(error: Result::Failure::UnknownPairError.new(relation: relation), trace: trace)
294
+ end
202
295
  end
203
296
 
204
297
  when relation.sub_type.is_a?(AST::Types::Proc) && relation.super_type.is_a?(AST::Types::Proc)
@@ -283,6 +376,80 @@ module Steep
283
376
  end
284
377
  end
285
378
 
379
+ def definition_for_type(type)
380
+ type_name = factory.type_name_1(type.name)
381
+
382
+ case type
383
+ when AST::Types::Name::Instance
384
+ factory.definition_builder.build_instance(type_name)
385
+ when AST::Types::Name::Class
386
+ factory.definition_builder.build_singleton(type_name)
387
+ when AST::Types::Name::Interface
388
+ factory.definition_builder.build_interface(type_name)
389
+ else
390
+ raise
391
+ end
392
+ end
393
+
394
+ def arg_type?(type)
395
+ case type
396
+ when AST::Types::Name::Instance, AST::Types::Name::Interface
397
+ type.args.size > 0
398
+ else
399
+ false
400
+ end
401
+ end
402
+
403
+ def check_type_arg(relation, self_type:, assumption:, trace:, constraints:)
404
+ sub_args = relation.sub_type.args
405
+ sup_args = relation.super_type.args
406
+
407
+ sup_def = definition_for_type(relation.super_type)
408
+ sup_params = sup_def.type_params_decl
409
+
410
+ success_all?(sub_args.zip(sup_args, sup_params.each)) do |sub_arg, sup_arg, sup_param|
411
+ case sup_param.variance
412
+ when :covariant
413
+ check(Relation.new(sub_type: sub_arg, super_type: sup_arg), self_type: self_type, assumption: assumption, trace: trace, constraints: constraints)
414
+ when :contravariant
415
+ check(Relation.new(sub_type: sup_arg, super_type: sub_arg), self_type: self_type, assumption: assumption, trace: trace, constraints: constraints)
416
+ when :invariant
417
+ rel = Relation.new(sub_type: sub_arg, super_type: sup_arg)
418
+ success_all?([rel, rel.flip]) do |r|
419
+ check(r, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints)
420
+ end
421
+ end
422
+ end
423
+ end
424
+
425
+ def success_all?(collection, &block)
426
+ results = collection.map do |obj|
427
+ result = yield(obj)
428
+
429
+ if result.failure?
430
+ return result
431
+ end
432
+
433
+ result
434
+ end
435
+
436
+ results[0]
437
+ end
438
+
439
+ def success_any?(collection, &block)
440
+ results = collection.map do |obj|
441
+ result = yield(obj)
442
+
443
+ if result.success?
444
+ return result
445
+ end
446
+
447
+ result
448
+ end
449
+
450
+ results[0]
451
+ end
452
+
286
453
  def extract_nominal_pairs(relation)
287
454
  sub_type = relation.sub_type
288
455
  super_type = relation.super_type
@@ -316,20 +483,7 @@ module Steep
316
483
  return true
317
484
  end
318
485
 
319
- case
320
- when relation.sub_type == relation.super_type
321
- true
322
- when relation.sub_type.is_a?(AST::Types::Name::Base) && relation.super_type.is_a?(AST::Types::Name::Base)
323
- if (pairs = extract_nominal_pairs(relation))
324
- pairs.all? do |(s, t)|
325
- same_type?(Relation.new(sub_type: s, super_type: t), assumption: assumption)
326
- end
327
- else
328
- false
329
- end
330
- else
331
- false
332
- end
486
+ relation.sub_type == relation.super_type
333
487
  end
334
488
 
335
489
  def check_interface(sub_interface, super_interface, self_type:, assumption:, trace:, constraints:)
@@ -37,7 +37,6 @@ module Steep
37
37
  attr_reader :source
38
38
  attr_reader :annotations
39
39
  attr_reader :typing
40
- attr_reader :type_env
41
40
 
42
41
  attr_reader :context
43
42
 
@@ -169,7 +168,7 @@ module Steep
169
168
 
170
169
  super_method = if definition
171
170
  if (this_method = definition.methods[method_name])
172
- if module_context&.class_name == checker.factory.type_name(this_method.defined_in.name.absolute!)
171
+ if module_context&.class_name == checker.factory.type_name(this_method.defined_in)
173
172
  this_method.super_method
174
173
  else
175
174
  this_method
@@ -231,6 +230,39 @@ module Steep
231
230
  )
232
231
  end
233
232
 
233
+ def implement_module(module_name:, super_name: nil, annotations:)
234
+ if (annotation = annotations.implement_module_annotation)
235
+ absolute_name(annotation.name.name).yield_self do |absolute_name|
236
+ if checker.factory.class_name?(absolute_name) || checker.factory.module_name?(absolute_name)
237
+ AST::Annotation::Implements::Module.new(
238
+ name: absolute_name,
239
+ args: annotation.name.args
240
+ )
241
+ else
242
+ Steep.logger.error "Unknown class name given to @implements: #{annotation.name.name}"
243
+ nil
244
+ end
245
+ end
246
+ else
247
+ name = nil
248
+ name ||= absolute_name(module_name).yield_self do |absolute_name|
249
+ absolute_name if checker.factory.class_name?(absolute_name) || checker.factory.module_name?(absolute_name)
250
+ end
251
+ name ||= super_name && absolute_name(super_name).yield_self do |absolute_name|
252
+ absolute_name if checker.factory.class_name?(absolute_name) || checker.factory.module_name?(absolute_name)
253
+ end
254
+
255
+ if name
256
+ absolute_name_ = checker.factory.type_name_1(name)
257
+ entry = checker.factory.env.class_decls[absolute_name_]
258
+ AST::Annotation::Implements::Module.new(
259
+ name: name,
260
+ args: entry.type_params.each.map(&:name)
261
+ )
262
+ end
263
+ end
264
+ end
265
+
234
266
  def for_module(node)
235
267
  new_module_name = Names::Module.from_node(node.children.first) or raise "Unexpected module name: #{node.children.first}"
236
268
  new_namespace = nested_namespace_for_module(new_module_name)
@@ -241,35 +273,14 @@ module Steep
241
273
  annots = source.annotations(block: node, factory: checker.factory, current_module: new_namespace)
242
274
  module_type = AST::Builtin::Module.instance_type
243
275
 
244
- implement_module_name = yield_self do
245
- if (annotation = annots.implement_module_annotation)
246
- absolute_name(annotation.name.name).yield_self do |absolute_name|
247
- if checker.factory.module_name?(absolute_name)
248
- AST::Annotation::Implements::Module.new(name: absolute_name,
249
- args: annotation.name.args)
250
- else
251
- Steep.logger.error "Unknown module name given to @implements: #{annotation.name.name}"
252
- nil
253
- end
254
- end
255
- else
256
- absolute_name(new_module_name).yield_self do |absolute_name|
257
- if checker.factory.module_name?(absolute_name)
258
- absolute_name_ = checker.factory.type_name_1(absolute_name)
259
- decl = checker.factory.env.find_class(absolute_name_)
260
- AST::Annotation::Implements::Module.new(name: absolute_name,
261
- args: decl.type_params.each.map(&:name))
262
- end
263
- end
264
- end
265
- end
276
+ implement_module_name = implement_module(module_name: new_module_name, annotations: annots)
266
277
 
267
278
  if implement_module_name
268
279
  module_name = implement_module_name.name
269
280
  module_args = implement_module_name.args.map {|x| AST::Types::Var.new(name: x)}
270
281
 
271
282
  type_name_ = checker.factory.type_name_1(implement_module_name.name)
272
- module_decl = checker.factory.definition_builder.env.find_class(type_name_)
283
+ module_entry = checker.factory.definition_builder.env.class_decls[type_name_]
273
284
  instance_def = checker.factory.definition_builder.build_instance(type_name_)
274
285
  module_def = checker.factory.definition_builder.build_singleton(type_name_)
275
286
 
@@ -277,9 +288,22 @@ module Steep
277
288
  types: [
278
289
  AST::Types::Name::Instance.new(name: module_name, args: module_args),
279
290
  AST::Builtin::Object.instance_type,
280
- module_decl.self_type&.yield_self {|ty|
281
- absolute_type = checker.factory.env.absolute_type(ty, namespace: module_decl.name.absolute!.namespace)
282
- checker.factory.type(absolute_type)
291
+ *module_entry.self_types.map {|module_self|
292
+ type = case
293
+ when module_self.name.interface?
294
+ RBS::Types::Interface.new(
295
+ name: module_self.name,
296
+ args: module_self.args,
297
+ location: module_self.location
298
+ )
299
+ when module_self.name.class?
300
+ RBS::Types::ClassInstance.new(
301
+ name: module_self.name,
302
+ args: module_self.args,
303
+ location: module_self.location
304
+ )
305
+ end
306
+ checker.factory.type(type)
283
307
  }
284
308
  ].compact
285
309
  )
@@ -340,34 +364,7 @@ module Steep
340
364
 
341
365
  annots = source.annotations(block: node, factory: checker.factory, current_module: new_namespace)
342
366
 
343
- implement_module_name = yield_self do
344
- if (annotation = annots.implement_module_annotation)
345
- absolute_name(annotation.name.name).yield_self do |absolute_name|
346
- if checker.factory.class_name?(absolute_name)
347
- AST::Annotation::Implements::Module.new(name: absolute_name,
348
- args: annotation.name.args)
349
- else
350
- Steep.logger.error "Unknown class name given to @implements: #{annotation.name.name}"
351
- nil
352
- end
353
- end
354
- else
355
- name = nil
356
- name ||= absolute_name(new_class_name).yield_self do |absolute_name|
357
- absolute_name if checker.factory.class_name?(absolute_name)
358
- end
359
- name ||= super_class_name && absolute_name(super_class_name).yield_self do |absolute_name|
360
- absolute_name if checker.factory.class_name?(absolute_name)
361
- end
362
-
363
- if name
364
- absolute_name_ = checker.factory.type_name_1(name)
365
- decl = checker.factory.env.find_class(absolute_name_)
366
- AST::Annotation::Implements::Module.new(name: name,
367
- args: decl.type_params.each.map(&:name))
368
- end
369
- end
370
- end
367
+ implement_module_name = implement_module(module_name: new_class_name, super_name: super_class_name, annotations: annots)
371
368
 
372
369
  if annots.implement_module_annotation
373
370
  new_class_name = implement_module_name.name
@@ -436,6 +433,83 @@ module Steep
436
433
  )
437
434
  end
438
435
 
436
+ def for_sclass(node, type)
437
+ annots = source.annotations(block: node, factory: checker.factory, current_module: current_namespace)
438
+
439
+ instance_type = if type.is_a?(AST::Types::Self)
440
+ context.self_type
441
+ else
442
+ type
443
+ end
444
+
445
+ module_type = case instance_type
446
+ when AST::Types::Name::Class
447
+ AST::Builtin::Class.instance_type
448
+ when AST::Types::Name::Module
449
+ AST::Builtin::Module.instance_type
450
+ when AST::Types::Name::Instance
451
+ instance_type.to_class(constructor: nil)
452
+ else
453
+ raise "Unexpected type for sclass node: #{type}"
454
+ end
455
+
456
+ instance_definition = case instance_type
457
+ when AST::Types::Name::Class, AST::Types::Name::Module
458
+ type_name = checker.factory.type_name_1(instance_type.name)
459
+ checker.factory.definition_builder.build_singleton(type_name)
460
+ when AST::Types::Name::Instance
461
+ type_name = checker.factory.type_name_1(instance_type.name)
462
+ checker.factory.definition_builder.build_instance(type_name)
463
+ end
464
+
465
+ module_definition = case module_type
466
+ when AST::Types::Name::Class, AST::Types::Name::Module
467
+ type_name = checker.factory.type_name_1(instance_type.name)
468
+ checker.factory.definition_builder.build_singleton(type_name)
469
+ else
470
+ nil
471
+ end
472
+
473
+ module_context = TypeInference::Context::ModuleContext.new(
474
+ instance_type: annots.instance_type || instance_type,
475
+ module_type: annots.self_type || annots.module_type || module_type,
476
+ implement_name: nil,
477
+ current_namespace: current_namespace,
478
+ const_env: self.module_context.const_env,
479
+ class_name: self.module_context.class_name,
480
+ module_definition: module_definition,
481
+ instance_definition: instance_definition
482
+ )
483
+
484
+ type_env = TypeInference::TypeEnv.build(annotations: annots,
485
+ subtyping: checker,
486
+ const_env: self.module_context.const_env,
487
+ signatures: checker.factory.env)
488
+
489
+ lvar_env = TypeInference::LocalVariableTypeEnv.empty(
490
+ subtyping: checker,
491
+ self_type: module_context.module_type
492
+ ).annotate(annots)
493
+
494
+ body_context = TypeInference::Context.new(
495
+ method_context: nil,
496
+ block_context: nil,
497
+ module_context: module_context,
498
+ break_context: nil,
499
+ self_type: module_context.module_type,
500
+ type_env: type_env,
501
+ lvar_env: lvar_env
502
+ )
503
+
504
+ self.class.new(
505
+ checker: checker,
506
+ source: source,
507
+ annotations: annots,
508
+ typing: typing,
509
+ context: body_context
510
+ )
511
+ end
512
+
439
513
  def for_branch(node, truthy_vars: Set.new, type_case_override: nil, break_context: context.break_context)
440
514
  annots = source.annotations(block: node, factory: checker.factory, current_module: current_namespace)
441
515
 
@@ -565,6 +639,7 @@ module Steep
565
639
  add_typing(node, type: AST::Builtin.any_type)
566
640
  else
567
641
  rhs_result = synthesize(rhs, hint: hint || context.lvar_env.declared_types[name]&.type)
642
+
568
643
  constr = rhs_result.constr.update_lvar_env do |lvar_env|
569
644
  lvar_env.assign(name, node: node, type: rhs_result.type) do |declared_type, actual_type, result|
570
645
  typing.add_error(Errors::IncompatibleAssignment.new(node: node,
@@ -1115,6 +1190,25 @@ module Steep
1115
1190
  add_typing(node, type: AST::Builtin.nil_type)
1116
1191
  end
1117
1192
 
1193
+ when :sclass
1194
+ yield_self do
1195
+ type, constr = synthesize(node.children[0])
1196
+ constructor = constr.for_sclass(node, type)
1197
+
1198
+ constructor.typing.add_context_for_node(node, context: constructor.context)
1199
+ constructor.typing.add_context_for_body(node, context: constructor.context)
1200
+
1201
+ constructor.synthesize(node.children[1]) if node.children[1]
1202
+
1203
+ if constructor.module_context.instance_definition && module_context.module_definition
1204
+ if constructor.module_context.instance_definition.type_name == module_context.module_definition.type_name
1205
+ module_context.defined_module_methods.merge(constructor.module_context.defined_instance_methods)
1206
+ end
1207
+ end
1208
+
1209
+ add_typing(node, type: AST::Builtin.nil_type)
1210
+ end
1211
+
1118
1212
  when :self
1119
1213
  add_typing node, type: AST::Types::Self.new
1120
1214
 
@@ -1992,9 +2086,11 @@ module Steep
1992
2086
  end
1993
2087
  end
1994
2088
  rescue => exn
1995
- $stderr.puts exn.inspect
1996
- exn.backtrace.each do |t|
1997
- $stderr.puts t
2089
+ case exn
2090
+ when RBS::NoTypeFoundError, RBS::NoMixinFoundError, RBS::NoSuperclassFoundError, RBS::InvalidTypeApplicationError
2091
+ # ignore known RBS errors.
2092
+ else
2093
+ Steep.log_error(exn, message: "Unexpected error in #type_send: #{exn.message} (#{exn.class})")
1998
2094
  end
1999
2095
 
2000
2096
  fallback_to_any node do
@@ -2750,13 +2846,18 @@ module Steep
2750
2846
  end
2751
2847
 
2752
2848
  def validate_method_definitions(node, module_name)
2849
+ module_name_1 = checker.factory.type_name_1(module_name.name)
2850
+ member_decl_count = checker.factory.env.class_decls[module_name_1].decls.count {|d| d.decl.each_member.count > 0 }
2851
+
2852
+ return unless member_decl_count == 1
2853
+
2753
2854
  expected_instance_method_names = (module_context.instance_definition&.methods || {}).each.with_object(Set[]) do |(name, method), set|
2754
- if method.implemented_in == module_context.instance_definition.declaration
2855
+ if method.implemented_in == module_context.instance_definition.type_name
2755
2856
  set << name
2756
2857
  end
2757
2858
  end
2758
2859
  expected_module_method_names = (module_context.module_definition&.methods || {}).each.with_object(Set[]) do |(name, method), set|
2759
- if method.implemented_in == module_context.module_definition.declaration
2860
+ if method.implemented_in == module_context.module_definition.type_name
2760
2861
  set << name
2761
2862
  end
2762
2863
  end
@@ -2948,7 +3049,7 @@ module Steep
2948
3049
  def to_instance_type(type, args: nil)
2949
3050
  args = args || case type
2950
3051
  when AST::Types::Name::Class, AST::Types::Name::Module
2951
- checker.factory.env.find_class(checker.factory.type_name_1(type.name)).type_params.each.map { AST::Builtin.any_type }
3052
+ checker.factory.env.class_decls[checker.factory.type_name_1(type.name)].type_params.each.map { AST::Builtin.any_type }
2952
3053
  else
2953
3054
  raise "unexpected type to to_instance_type: #{type}"
2954
3055
  end