rbs 3.1.1 → 3.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38298f073fa4b8e071ba2f38a13640e4143a4a64981e16535a214364ce99a536
4
- data.tar.gz: 0a818cb58aac7767500da1bd57b4a06d193232a1c8b0fa88537c372af542b180
3
+ metadata.gz: 7b7971d4b64c169d220fe2c0895630a36ebc6505b68689fba0660be24bcd24c0
4
+ data.tar.gz: 2f6b8a68c5817d25c3ba179eb3965751f0b406c7dcf2d0812fe41d96bbac6e7c
5
5
  SHA512:
6
- metadata.gz: cf52478cb1f82d103499796eae6e946925b79faca65cf7c52665ebb9966fcf3d8f2a344bf7806dffe7abe8d8e8f5b49e01c0e4bb58bb54fb870104582a84d2e6
7
- data.tar.gz: f63f19cff5e7246dc3d9e6fe6c1ed46256eae0f83f6c939d50bda1adb5ff78de8e71c4f9864c6059da338485046ad7b936b8b65d1d838610eebb4bf902013bad
6
+ metadata.gz: 4647a2dce17379807dae65a355d0fb2174d18062dbeb98d51c0c06f125d19d665ff32e3528c7326925ba11abed838b0ffff35e3708a25931fa1c4ea8c25d5eae
7
+ data.tar.gz: 68e20554c2941971aa99015343ef59768a653ed23fc0d6b59eeb64223dff56e8c0aa61846402f28d5f8f9e5ce33763e116cdf08cb8ca9dcfb07177d1eeab9d68
data/CHANGELOG.md CHANGED
@@ -2,6 +2,15 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 3.1.2 (2023-07-27)
6
+
7
+ ⚠️ Note that this patch level release may report additional validation errors that is caused by fix of type name resolution ([#1373](https://github.com/ruby/rbs/pull/1373)).
8
+
9
+ ### Library changes
10
+
11
+ * Make `TypeNameResolver` more compatible with Ruby ([#1373](https://github.com/ruby/rbs/pull/1373))
12
+ * Fix module alias normalizations ([#1393](https://github.com/ruby/rbs/pull/1393))
13
+
5
14
  ## 3.1.1 (2023-07-18)
6
15
 
7
16
  ### Signature updates
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rbs (3.1.1)
4
+ rbs (3.1.2)
5
5
 
6
6
  PATH
7
7
  remote: test/assets/test-gem
@@ -753,12 +753,14 @@ module RBS
753
753
  end
754
754
 
755
755
  def expand_alias1(type_name)
756
+ type_name = env.normalize_type_name(type_name)
756
757
  entry = env.type_alias_decls[type_name] or raise "Unknown alias name: #{type_name}"
757
758
  as = entry.decl.type_params.each.map { Types::Bases::Any.new(location: nil) }
758
759
  expand_alias2(type_name, as)
759
760
  end
760
761
 
761
762
  def expand_alias2(type_name, args)
763
+ type_name = env.normalize_type_name(type_name)
762
764
  entry = env.type_alias_decls[type_name] or raise "Unknown alias name: #{type_name}"
763
765
 
764
766
  ensure_namespace!(type_name.namespace, location: entry.decl.location)
@@ -811,9 +813,8 @@ module RBS
811
813
  end
812
814
 
813
815
  def validate_type_name(name, location)
814
- name = name.absolute!
815
-
816
- return if env.type_name?(name)
816
+ name = name.absolute! unless name.absolute?
817
+ return if env.type_name?(env.normalize_type_name(name))
817
818
 
818
819
  raise NoTypeFoundError.new(type_name: name, location: location)
819
820
  end
@@ -275,53 +275,96 @@ module RBS
275
275
  class_entry(type_name) || module_entry(type_name) || constant_decls[type_name]
276
276
  end
277
277
 
278
+ def normalize_type_name?(name)
279
+ if name.class?
280
+ normalize_module_name?(name)
281
+ else
282
+ unless name.namespace.empty?
283
+ parent = name.namespace.to_type_name
284
+ parent = normalize_module_name?(parent)
285
+ return parent unless parent
286
+
287
+ TypeName.new(namespace: parent.to_namespace, name: name.name)
288
+ else
289
+ name
290
+ end
291
+ end
292
+ end
293
+
294
+ def normalize_type_name!(name)
295
+ result = normalize_type_name?(name)
296
+
297
+ case result
298
+ when TypeName
299
+ result
300
+ when false
301
+ raise "Type name `#{name}` cannot be normalized because it's a cyclic definition"
302
+ when nil
303
+ raise "Type name `#{name}` cannot be normalized because of unknown type name in the path"
304
+ end
305
+ end
306
+
307
+ def normalized_type_name?(type_name)
308
+ case
309
+ when type_name.interface?
310
+ interface_decls.key?(type_name)
311
+ when type_name.class?
312
+ class_decls.key?(type_name)
313
+ when type_name.alias?
314
+ type_alias_decls.key?(type_name)
315
+ else
316
+ false
317
+ end
318
+ end
319
+
320
+ def normalized_type_name!(name)
321
+ normalized_type_name?(name) or raise "Normalized type name is expected but given `#{name}`, which is normalized to `#{normalize_type_name?(name)}`"
322
+ name
323
+ end
324
+
325
+ def normalize_type_name(name)
326
+ normalize_type_name?(name) || name
327
+ end
328
+
278
329
  def normalize_module_name(name)
279
330
  normalize_module_name?(name) or name
280
331
  end
281
332
 
282
333
  def normalize_module_name?(name)
283
334
  raise "Class/module name is expected: #{name}" unless name.class?
284
- name = name.absolute! if name.relative!
335
+ name = name.absolute! unless name.absolute?
285
336
 
286
337
  if @normalize_module_name_cache.key?(name)
287
338
  return @normalize_module_name_cache[name]
288
339
  end
289
340
 
341
+ unless name.namespace.empty?
342
+ parent = name.namespace.to_type_name
343
+ if normalized_parent = normalize_module_name?(parent)
344
+ type_name = TypeName.new(namespace: normalized_parent.to_namespace, name: name.name)
345
+ else
346
+ @normalize_module_name_cache[name] = nil
347
+ return
348
+ end
349
+ else
350
+ type_name = name
351
+ end
352
+
290
353
  @normalize_module_name_cache[name] = false
291
354
 
292
- entry = constant_entry(name)
293
- case entry
294
- when ClassEntry, ModuleEntry
295
- @normalize_module_name_cache[name] = entry.name
296
- entry.name
355
+ entry = constant_entry(type_name)
297
356
 
298
- when ClassAliasEntry, ModuleAliasEntry
299
- old_name = entry.decl.old_name
300
- if old_name.namespace.empty?
301
- @normalize_module_name_cache[name] = normalize_module_name?(old_name)
357
+ normalized_type_name =
358
+ case entry
359
+ when ClassEntry, ModuleEntry
360
+ type_name
361
+ when ClassAliasEntry, ModuleAliasEntry
362
+ normalize_module_name?(entry.decl.old_name)
302
363
  else
303
- parent = old_name.namespace.to_type_name
304
-
305
- if normalized_parent = normalize_module_name?(parent)
306
- @normalize_module_name_cache[name] =
307
- if normalized_parent == parent
308
- normalize_module_name?(old_name)
309
- else
310
- normalize_module_name?(
311
- TypeName.new(name: old_name.name, namespace: normalized_parent.to_namespace)
312
- )
313
- end
314
- else
315
- @normalize_module_name_cache[name] = nil
316
- end
364
+ nil
317
365
  end
318
366
 
319
- when ConstantEntry
320
- raise "#{name} is a constant name"
321
-
322
- else
323
- @normalize_module_name_cache[name] = nil
324
- end
367
+ @normalize_module_name_cache[name] = normalized_type_name
325
368
  end
326
369
 
327
370
  def insert_decl(decl, outer:, namespace:)
data/lib/rbs/errors.rb CHANGED
@@ -185,7 +185,8 @@ module RBS
185
185
  end
186
186
 
187
187
  def self.check!(super_decl, env:)
188
- return if env.class_decl?(super_decl.name) || env.class_alias?(super_decl.name)
188
+ super_name = env.normalize_type_name(super_decl.name)
189
+ return if env.class_decl?(super_name) || env.class_alias?(super_name)
189
190
 
190
191
  raise new(super_decl)
191
192
  end
@@ -205,9 +206,8 @@ module RBS
205
206
  end
206
207
 
207
208
  def self.check!(self_type, env:)
208
- type_name = self_type.name
209
-
210
- (env.module_name?(type_name) || env.interface_name?(type_name)) or raise new(type_name: type_name, location: self_type.location)
209
+ self_name = env.normalize_type_name(self_type.name)
210
+ (env.module_name?(self_name) || env.interface_name?(self_name)) or raise new(type_name: self_type.name, location: self_type.location)
211
211
  end
212
212
  end
213
213
 
@@ -5,10 +5,12 @@ module RBS
5
5
  class TypeNameResolver
6
6
  attr_reader :all_names
7
7
  attr_reader :cache
8
+ attr_reader :env
8
9
 
9
10
  def initialize(env)
10
11
  @all_names = Set[]
11
12
  @cache = {}
13
+ @env = env
12
14
 
13
15
  all_names.merge(env.class_decls.keys)
14
16
  all_names.merge(env.interface_decls.keys)
@@ -29,22 +31,53 @@ module RBS
29
31
  end
30
32
 
31
33
  try_cache([type_name, context]) do
32
- resolve_in(type_name, context)
34
+ head, tail = partition(type_name)
35
+
36
+ head = resolve_in(head, context)
37
+
38
+ if head
39
+ if tail
40
+ absolute_name = tail.with_prefix(head.to_namespace)
41
+ if env.normalize_type_name?(absolute_name)
42
+ absolute_name
43
+ end
44
+ else
45
+ head
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ def partition(type_name)
52
+ if type_name.namespace.empty?
53
+ head = type_name.name
54
+ tail = nil
55
+ else
56
+ head, *tail = type_name.namespace.path
57
+
58
+ head or raise
59
+
60
+ tail = TypeName.new(
61
+ name: type_name.name,
62
+ namespace: Namespace.new(absolute: false, path: tail)
63
+ )
33
64
  end
65
+
66
+ [head, tail]
34
67
  end
35
68
 
36
- def resolve_in(type_name, context)
69
+ def resolve_in(head, context)
37
70
  if context
38
71
  parent, child = context
39
72
  case child
40
73
  when false
41
- resolve_in(type_name, parent)
74
+ resolve_in(head, parent)
42
75
  when TypeName
43
- name = type_name.with_prefix(child.to_namespace)
44
- has_name?(name) || resolve_in(type_name, parent)
76
+ name = TypeName.new(name: head, namespace: child.to_namespace)
77
+ has_name?(name) || resolve_in(head, parent)
45
78
  end
46
79
  else
47
- has_name?(type_name.absolute!)
80
+ has_name?(TypeName.new(name: head, namespace: Namespace.root))
48
81
  end
49
82
  end
50
83
 
@@ -20,7 +20,7 @@ module RBS
20
20
  # Construct transitive closure, if not constructed already
21
21
  transitive_closure() unless @dependencies
22
22
 
23
- # Check for recursive type alias
23
+ alias_name = env.normalize_type_name!(alias_name)
24
24
  @dependencies[alias_name][alias_name]
25
25
  end
26
26
 
@@ -49,6 +49,16 @@ module RBS
49
49
  end
50
50
  end
51
51
 
52
+ def direct_dependencies_of(name)
53
+ name = env.normalize_type_name!(name)
54
+ @direct_dependencies[name]
55
+ end
56
+
57
+ def dependencies_of(name)
58
+ name = env.normalize_type_name!(name)
59
+ @dependencies[name].each_key.to_set
60
+ end
61
+
52
62
  private
53
63
 
54
64
  # Constructs directed graph recursively
@@ -61,7 +71,7 @@ module RBS
61
71
  end
62
72
  when RBS::Types::Alias
63
73
  # Append type name if the type is an alias
64
- result << type.name
74
+ result << env.normalize_type_name(type.name)
65
75
  end
66
76
 
67
77
  result
@@ -37,10 +37,12 @@ module RBS
37
37
  end
38
38
 
39
39
  def validate_alias_type(alias_type, names, types)
40
- if names.include?(alias_type.name)
41
- if ex_type = types[alias_type.name]
40
+ alias_name = env.normalize_type_name?(alias_type.name) or return
41
+
42
+ if names.include?(alias_name)
43
+ if ex_type = types[alias_name]
42
44
  unless compatible_args?(ex_type.args, alias_type.args)
43
- diagnostics[alias_type.name] ||=
45
+ diagnostics[alias_name] ||=
44
46
  Diagnostic.new(type_name: alias_type.name, nonregular_type: alias_type)
45
47
  end
46
48
 
@@ -49,7 +51,7 @@ module RBS
49
51
  types[alias_type.name] = alias_type
50
52
  end
51
53
 
52
- expanded = builder.expand_alias2(alias_type.name, alias_type.args)
54
+ expanded = builder.expand_alias2(alias_name, alias_type.args)
53
55
  each_alias_type(expanded) do |at|
54
56
  validate_alias_type(at, names, types)
55
57
  end
@@ -75,22 +77,27 @@ module RBS
75
77
  end
76
78
 
77
79
  def nonregular?(type_name)
78
- diagnostics[type_name]
80
+ diagnostics[env.normalize_type_name!(type_name)]
79
81
  end
80
82
 
81
83
  def each_mutual_alias_defs(&block)
82
- # @type var each_node: TSort::_EachNode[TypeName]
83
- each_node = __skip__ = -> (&block) do
84
+ # @type var each_node: ^() { (TypeName) -> void } -> void
85
+ each_node = -> (&block) do
84
86
  env.type_alias_decls.each_value do |decl|
85
- block[decl.name]
87
+ if normalized = env.normalize_type_name?(decl.name)
88
+ block[normalized]
89
+ end
86
90
  end
87
91
  end
88
- # @type var each_child: TSort::_EachChild[TypeName]
89
- each_child = __skip__ = -> (name, &block) do
92
+
93
+ # @type var each_child: ^(TypeName) { (TypeName) -> void } -> void
94
+ each_child = -> (name, &block) do
90
95
  if env.type_alias_decls.key?(name)
91
96
  type = builder.expand_alias1(name)
92
97
  each_alias_type(type) do |ty|
93
- block[ty.name]
98
+ if normalized = env.normalize_type_name?(ty.name)
99
+ block[normalized]
100
+ end
94
101
  end
95
102
  end
96
103
  end
data/lib/rbs/validator.rb CHANGED
@@ -12,9 +12,9 @@ module RBS
12
12
  @definition_builder = DefinitionBuilder.new(env: env)
13
13
  end
14
14
 
15
- def absolute_type(type, context:)
15
+ def absolute_type(type, context:, &block)
16
16
  type.map_type_name do |type_name, _, type|
17
- resolver.resolve(type_name, context: context) || yield(type)
17
+ resolver.resolve(type_name, context: context) || (block ? yield(type) : type_name)
18
18
  end
19
19
  end
20
20
 
@@ -22,33 +22,34 @@ module RBS
22
22
  def validate_type(type, context:)
23
23
  case type
24
24
  when Types::ClassInstance, Types::Interface, Types::Alias
25
- # @type var type: Types::ClassInstance | Types::Interface | Types::Alias
26
- if type.name.namespace.relative?
27
- type = _ = absolute_type(type, context: context) do |_|
28
- NoTypeFoundError.check!(type.name.absolute!, env: env, location: type.location)
29
- end
30
- end
25
+ type = absolute_type(type, context: context) #: Types::ClassInstance | Types::Interface | Types::Alias
31
26
 
32
27
  definition_builder.validate_type_name(type.name, type.location)
33
28
 
34
- type_params = case type
35
- when Types::ClassInstance
36
- entry = env.normalized_module_class_entry(type.name) or raise
37
- entry.type_params
38
- when Types::Interface
39
- env.interface_decls[type.name].decl.type_params
40
- when Types::Alias
41
- env.type_alias_decls[type.name].decl.type_params
42
- end
43
-
44
- InvalidTypeApplicationError.check!(
45
- type_name: type.name,
46
- args: type.args,
47
- params: type_params.each.map(&:name),
48
- location: type.location
49
- )
29
+ normalized_type_name = env.normalize_type_name?(type.name)
30
+
31
+ if normalized_type_name
32
+ type_params =
33
+ case type
34
+ when Types::ClassInstance
35
+ entry = env.class_decls[normalized_type_name] or raise
36
+ entry.type_params
37
+ when Types::Interface
38
+ env.interface_decls[normalized_type_name].decl.type_params
39
+ when Types::Alias
40
+ env.type_alias_decls[normalized_type_name].decl.type_params
41
+ end
42
+
43
+ InvalidTypeApplicationError.check!(
44
+ type_name: type.name,
45
+ args: type.args,
46
+ params: type_params.each.map(&:name),
47
+ location: type.location
48
+ )
49
+ end
50
50
 
51
51
  when Types::ClassSingleton
52
+ type = absolute_type(type, context: context) #: Types::ClassSingleton
52
53
  definition_builder.validate_type_presence(type)
53
54
  end
54
55
 
@@ -115,14 +116,14 @@ module RBS
115
116
  end
116
117
 
117
118
  def validate_type_params(params, type_name: , method_name: nil, location:)
118
- # @type var each_node: TSort::_EachNode[Symbol]
119
- each_node = __skip__ = -> (&block) do
119
+ # @type var each_node: ^() { (Symbol) -> void } -> void
120
+ each_node = -> (&block) do
120
121
  params.each do |param|
121
122
  block[param.name]
122
123
  end
123
124
  end
124
- # @type var each_child: TSort::_EachChild[Symbol]
125
- each_child = __skip__ = -> (name, &block) do
125
+ # @type var each_child: ^(Symbol) { (Symbol) -> void } -> void
126
+ each_child = -> (name, &block) do
126
127
  if param = params.find {|p| p.name == name }
127
128
  if b = param.upper_bound
128
129
  b.free_variables.each do |tv|
@@ -108,8 +108,11 @@ module RBS
108
108
  end
109
109
 
110
110
  def in_type_alias(name:)
111
+ env.normalized_type_name!(name)
112
+
111
113
  decl = env.type_alias_decls[name].decl or raise
112
114
  variables = decl.type_params.each.map(&:name)
115
+
113
116
  Result.new(variables: variables).tap do |result|
114
117
  type(decl.type, result: result, context: :covariant)
115
118
  end
@@ -129,30 +132,30 @@ module RBS
129
132
  end
130
133
  end
131
134
  when Types::ClassInstance, Types::Interface, Types::Alias
132
- NoTypeFoundError.check!(type.name,
133
- env: env,
134
- location: type.location)
135
-
136
- type_params = case type
137
- when Types::ClassInstance
138
- env.class_decls[env.normalize_module_name(type.name)].type_params
139
- when Types::Interface
140
- env.interface_decls[type.name].decl.type_params
141
- when Types::Alias
142
- env.type_alias_decls[type.name].decl.type_params
143
- end
144
-
145
- type.args.each.with_index do |ty, i|
146
- if var = type_params[i]
147
- case var.variance
148
- when :invariant
149
- type(ty, result: result, context: :invariant)
150
- when :covariant
151
- type(ty, result: result, context: context)
152
- when :contravariant
153
- type(ty, result: result, context: negate(context))
135
+ if type_name = env.normalize_type_name?(type.name)
136
+ type_params = case type
137
+ when Types::ClassInstance
138
+ env.class_decls[type_name].type_params
139
+ when Types::Interface
140
+ env.interface_decls[type_name].decl.type_params
141
+ when Types::Alias
142
+ env.type_alias_decls[type_name].decl.type_params
143
+ end
144
+
145
+ type.args.each.with_index do |ty, i|
146
+ if var = type_params[i]
147
+ case var.variance
148
+ when :invariant
149
+ type(ty, result: result, context: :invariant)
150
+ when :covariant
151
+ type(ty, result: result, context: context)
152
+ when :contravariant
153
+ type(ty, result: result, context: negate(context))
154
+ end
154
155
  end
155
156
  end
157
+ else
158
+ raise NoTypeFoundError.new(type_name: type.name, location: type.location)
156
159
  end
157
160
  when Types::Proc
158
161
  function(type.type, result: result, context: context)
data/lib/rbs/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RBS
4
- VERSION = "3.1.1"
4
+ VERSION = "3.1.2"
5
5
  end
@@ -71,12 +71,16 @@ module RBS
71
71
  # Assumes the type names are already resolved.
72
72
  # Raises NoTypeFoundError in case of failure.
73
73
  #
74
+ # Normalizes type names in the given type automatically.
75
+ #
74
76
  def validate_type_presence: (Types::t) -> void
75
77
 
76
78
  # Validates presence of an absolute type name
77
79
  #
78
80
  # Raises NoTypeFoundError in case of error.
79
81
  #
82
+ # Normalizes the given type name automatically.
83
+ #
80
84
  def validate_type_name: (TypeName, Location[untyped, untyped]?) -> void
81
85
 
82
86
  # Returns a new DefinitionBuilder with updated Environment, AncestorBuilder, and exceptions
data/sig/environment.rbs CHANGED
@@ -224,6 +224,33 @@ module RBS
224
224
  #
225
225
  def normalize_module_name: (TypeName) -> TypeName
226
226
 
227
+ # Returns a normalized module/class name or a type name with a normalized namespace
228
+ #
229
+ # * Calls `#absolute!` for relative module names
230
+ # * Returns `nil` if the typename cannot be found
231
+ # * Returns `false` if the name is cyclic
232
+ #
233
+ def normalize_type_name?: (TypeName) -> (TypeName | nil | false)
234
+
235
+ # Normalize the type name or raises an error
236
+ #
237
+ def normalize_type_name!: (TypeName) -> TypeName
238
+
239
+ # Returns a normalized module/class name or a type name with a normalized namespace
240
+ #
241
+ # * Calls `#absolute!` for relative module names
242
+ # * Returns the typename itself if the name cannot be normalized
243
+ #
244
+ def normalize_type_name: (TypeName) -> TypeName
245
+
246
+ # Returns `true` if given type name is normalized
247
+ #
248
+ def normalized_type_name?: (TypeName) -> bool
249
+
250
+ # Returns the given type name if it's normalized, or raises
251
+ #
252
+ def normalized_type_name!: (TypeName) -> TypeName
253
+
227
254
  # Runs generics type params validation over each class definitions
228
255
  def validate_type_params: () -> void
229
256
 
data/sig/errors.rbs CHANGED
@@ -90,6 +90,8 @@ module RBS
90
90
 
91
91
  def initialize: (type_name: TypeName, location: Location[untyped, untyped]?) -> void
92
92
 
93
+ # The type name in `self` is automatically normalized
94
+ #
93
95
  def self.check!: (AST::Declarations::Module::Self, env: Environment) -> void
94
96
  end
95
97
 
@@ -244,6 +246,10 @@ module RBS
244
246
 
245
247
  def location: () -> Location[untyped, untyped]?
246
248
 
249
+ # Confirms if `super` inherits specifies a class
250
+ #
251
+ # Automatically normalize the name of super.
252
+ #
247
253
  def self.check!: (AST::Declarations::Class::Super, env: Environment) -> void
248
254
  end
249
255
 
@@ -17,6 +17,8 @@ module RBS
17
17
 
18
18
  private
19
19
 
20
+ attr_reader env: Environment
21
+
20
22
  attr_reader all_names: Set[TypeName]
21
23
 
22
24
  attr_reader cache: Hash[query, TypeName?]
@@ -25,7 +27,9 @@ module RBS
25
27
 
26
28
  def try_cache: (query) { () -> TypeName? } -> TypeName?
27
29
 
28
- def resolve_in: (TypeName, context) -> TypeName?
30
+ def resolve_in: (Symbol, context) -> TypeName?
31
+
32
+ def partition: (TypeName) -> [Symbol, TypeName?]
29
33
  end
30
34
  end
31
35
  end
@@ -1,14 +1,45 @@
1
1
  module RBS
2
+ # TypeAliasDependency calculates the dependnecies between type aliases
3
+ #
4
+ # The dependencies are normalized automatically.
5
+ #
2
6
  class TypeAliasDependency
3
7
  attr_reader env: Environment
4
8
 
9
+ # A hash table from type alias name to it's direct dependencies
10
+ #
11
+ # The source type name and dependencies are normalized.
12
+ #
5
13
  attr_reader direct_dependencies: Hash[TypeName, Set[TypeName]]
14
+
15
+ # A hash table from type alias name to a hash name with keys of transitive dependnecies
16
+ #
17
+ # The source type name and dependencies are normalized.
18
+ #
6
19
  attr_reader dependencies: Hash[TypeName, Hash[TypeName, bool]]
7
20
 
8
21
  def initialize: (env: Environment) -> void
9
22
 
23
+ # Returns `true` if given type alias is circular
24
+ #
25
+ # Normalized given type name automatically.
26
+ #
10
27
  def circular_definition?: (TypeName alias_name) -> bool
11
28
 
29
+ # Returns the set of direct dependencies from the given type name
30
+ #
31
+ # Given type name will be normalized automatically.
32
+ # Returns normalized type names.
33
+ #
34
+ def direct_dependencies_of: (TypeName) -> Set[TypeName]
35
+
36
+ # Returns the set of dependencies from the given type name
37
+ #
38
+ # Given type name will be normalized automatically.
39
+ # Returns normalized type names.
40
+ #
41
+ def dependencies_of: (TypeName) -> Set[TypeName]
42
+
12
43
  def build_dependencies: () -> void
13
44
 
14
45
  def transitive_closure: () -> void
@@ -36,6 +36,9 @@ module RBS
36
36
 
37
37
  attr_reader builder: DefinitionBuilder
38
38
 
39
+ # Diagnostics of each type aliases.
40
+ # The type names are normalized.
41
+ #
39
42
  attr_reader diagnostics: Hash[TypeName, Diagnostic]
40
43
 
41
44
  # `Diagnostic` represents an non-regular type alias declaration error.
@@ -70,6 +73,8 @@ module RBS
70
73
  # Returns `Diagnostic` instance if the alias type is nonregular.
71
74
  # Regurns `nil` if the alias type is regular.
72
75
  #
76
+ # Normalizes the given type name automatically.
77
+ #
73
78
  def nonregular?: (TypeName) -> Diagnostic?
74
79
 
75
80
  def validate: () -> void
@@ -87,6 +92,7 @@ module RBS
87
92
 
88
93
  def each_alias_type: (Types::t) { (Types::Alias) -> void } -> void
89
94
 
95
+ # Yields set of normalized type names
90
96
  def each_mutual_alias_defs: () { (Set[TypeName]) -> void } -> void
91
97
  end
92
98
  end
data/sig/validator.rbs CHANGED
@@ -46,7 +46,7 @@ module RBS
46
46
  #
47
47
  # - The right hand side can be normalized
48
48
  # - No mixing alias declaration between class and modules
49
- #
49
+ #
50
50
  def validate_class_alias: (entry: Environment::ClassAliasEntry | Environment::ModuleAliasEntry) -> void
51
51
 
52
52
  private
@@ -54,6 +54,6 @@ module RBS
54
54
  # Resolves relative type names to absolute type names in given context.
55
55
  # Yields the type when the type name resolution using `#resolver` fails.
56
56
  #
57
- def absolute_type: (Types::t, context: Resolver::context) { (Types::t) -> TypeName } -> Types::t
57
+ def absolute_type: (Types::t, context: Resolver::context) ?{ (Types::t) -> TypeName } -> Types::t
58
58
  end
59
59
  end
@@ -72,6 +72,8 @@ module RBS
72
72
 
73
73
  def in_inherit: (name: TypeName, args: Array[Types::t], variables: Array[Symbol]) -> Result
74
74
 
75
+ # The type name must be normalized
76
+ #
75
77
  def in_type_alias: (name: TypeName) -> Result
76
78
 
77
79
  private
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbs
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.1.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-18 00:00:00.000000000 Z
11
+ date: 2023-07-27 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: RBS is the language for type signatures for Ruby and standard library
14
14
  definitions.