rbs 0.18.1 → 1.0.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +31 -0
- data/Rakefile +12 -0
- data/Steepfile +2 -1
- data/bin/annotate-with-rdoc +0 -4
- data/core/builtin.rbs +4 -0
- data/core/file.rbs +3 -4
- data/core/hash.rbs +1 -3
- data/core/io.rbs +165 -7
- data/core/kernel.rbs +1 -1
- data/core/module.rbs +41 -0
- data/core/time.rbs +0 -12
- data/docs/syntax.md +0 -17
- data/goodcheck.yml +22 -2
- data/lib/rbs.rb +2 -0
- data/lib/rbs/ast/declarations.rb +7 -49
- data/lib/rbs/ast/members.rb +10 -4
- data/lib/rbs/cli.rb +10 -10
- data/lib/rbs/definition.rb +70 -3
- data/lib/rbs/definition_builder.rb +573 -984
- data/lib/rbs/definition_builder/ancestor_builder.rb +525 -0
- data/lib/rbs/definition_builder/method_builder.rb +217 -0
- data/lib/rbs/environment.rb +6 -8
- data/lib/rbs/environment_loader.rb +8 -4
- data/lib/rbs/errors.rb +88 -121
- data/lib/rbs/method_type.rb +1 -31
- data/lib/rbs/parser.rb +1082 -1014
- data/lib/rbs/parser.y +108 -76
- data/lib/rbs/prototype/rb.rb +18 -3
- data/lib/rbs/prototype/rbi.rb +6 -6
- data/lib/rbs/prototype/runtime.rb +71 -35
- data/lib/rbs/substitution.rb +4 -0
- data/lib/rbs/test.rb +3 -1
- data/lib/rbs/test/hook.rb +26 -8
- data/lib/rbs/types.rb +68 -7
- data/lib/rbs/validator.rb +4 -2
- data/lib/rbs/variance_calculator.rb +5 -1
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +13 -4
- data/schema/members.json +5 -1
- data/sig/ancestor_builder.rbs +98 -0
- data/sig/declarations.rbs +4 -16
- data/sig/definition.rbs +6 -1
- data/sig/definition_builder.rbs +15 -67
- data/sig/errors.rbs +159 -0
- data/sig/members.rbs +4 -1
- data/sig/method_builder.rbs +71 -0
- data/sig/method_types.rbs +3 -16
- data/sig/substitution.rbs +3 -0
- data/sig/type_name_resolver.rbs +4 -2
- data/sig/types.rbs +17 -15
- data/sig/validator.rbs +12 -0
- data/stdlib/csv/0/csv.rbs +3 -0
- data/stdlib/dbm/0/dbm.rbs +0 -2
- data/stdlib/logger/0/log_device.rbs +1 -2
- data/stdlib/monitor/0/monitor.rbs +119 -0
- data/stdlib/pathname/0/pathname.rbs +1 -1
- data/stdlib/prime/0/prime.rbs +6 -0
- data/stdlib/securerandom/0/securerandom.rbs +2 -0
- data/stdlib/time/0/time.rbs +327 -0
- data/stdlib/tsort/0/tsort.rbs +8 -0
- data/stdlib/uri/0/common.rbs +401 -0
- data/stdlib/uri/0/rfc2396_parser.rbs +9 -0
- data/stdlib/uri/0/rfc3986_parser.rbs +2 -0
- data/steep/Gemfile.lock +13 -14
- metadata +16 -5
data/lib/rbs/parser.y
CHANGED
@@ -20,7 +20,7 @@ class RBS::Parser
|
|
20
20
|
nonassoc kARROW
|
21
21
|
preclow
|
22
22
|
|
23
|
-
expect
|
23
|
+
expect 5
|
24
24
|
|
25
25
|
rule
|
26
26
|
|
@@ -50,7 +50,6 @@ rule
|
|
50
50
|
| interface_decl
|
51
51
|
| module_decl
|
52
52
|
| class_decl
|
53
|
-
| extension_decl
|
54
53
|
|
55
54
|
start_new_scope: { start_new_variables_scope }
|
56
55
|
start_merged_scope: { start_merged_variables_scope }
|
@@ -61,24 +60,6 @@ rule
|
|
61
60
|
result = val[1].unshift(Annotation.new(string: val[0].value, location: val[0].location))
|
62
61
|
}
|
63
62
|
|
64
|
-
extension_decl:
|
65
|
-
annotations kEXTENSION start_new_scope class_name type_params kLPAREN extension_name kRPAREN class_members kEND {
|
66
|
-
reset_variable_scope
|
67
|
-
|
68
|
-
location = val[1].location + val[9].location
|
69
|
-
result = Declarations::Extension.new(
|
70
|
-
name: val[3].value,
|
71
|
-
type_params: val[4]&.value || [],
|
72
|
-
extension_name: val[6].value.to_sym,
|
73
|
-
members: val[8],
|
74
|
-
annotations: val[0],
|
75
|
-
location: location,
|
76
|
-
comment: leading_comment(val[0].first&.location || location)
|
77
|
-
)
|
78
|
-
}
|
79
|
-
|
80
|
-
extension_name: tUIDENT | tLIDENT
|
81
|
-
|
82
63
|
class_decl:
|
83
64
|
annotations kCLASS start_new_scope class_name module_type_params super_class class_members kEND {
|
84
65
|
reset_variable_scope
|
@@ -99,11 +80,13 @@ rule
|
|
99
80
|
{ result = nil }
|
100
81
|
| kLT class_name {
|
101
82
|
result = Declarations::Class::Super.new(name: val[1].value,
|
102
|
-
args: []
|
83
|
+
args: [],
|
84
|
+
location: val[1].location)
|
103
85
|
}
|
104
86
|
| kLT class_name kLBRACKET type_list kRBRACKET {
|
105
87
|
result = Declarations::Class::Super.new(name: val[1].value,
|
106
|
-
args: val[3]
|
88
|
+
args: val[3],
|
89
|
+
location: val[1].location + val[4].location)
|
107
90
|
}
|
108
91
|
|
109
92
|
module_decl:
|
@@ -202,57 +185,67 @@ rule
|
|
202
185
|
| alias_member
|
203
186
|
| signature
|
204
187
|
|
188
|
+
attribute_kind:
|
189
|
+
{ result = :instance }
|
190
|
+
| kSELF kDOT { result = :singleton }
|
191
|
+
|
205
192
|
attribute_member:
|
206
|
-
annotations kATTRREADER keyword type {
|
207
|
-
location = val[1].location + val[
|
208
|
-
result = Members::AttrReader.new(name: val[
|
193
|
+
annotations kATTRREADER attribute_kind keyword type {
|
194
|
+
location = val[1].location + val[4].location
|
195
|
+
result = Members::AttrReader.new(name: val[3].value,
|
209
196
|
ivar_name: nil,
|
210
|
-
type: val[
|
197
|
+
type: val[4],
|
198
|
+
kind: val[2],
|
211
199
|
annotations: val[0],
|
212
200
|
location: location,
|
213
201
|
comment: leading_comment(val[0].first&.location || location))
|
214
202
|
}
|
215
|
-
| annotations kATTRREADER method_name attr_var_opt kCOLON type {
|
216
|
-
location = val[1].location + val[
|
217
|
-
result = Members::AttrReader.new(name: val[
|
218
|
-
ivar_name: val[
|
219
|
-
type: val[
|
203
|
+
| annotations kATTRREADER attribute_kind method_name attr_var_opt kCOLON type {
|
204
|
+
location = val[1].location + val[6].location
|
205
|
+
result = Members::AttrReader.new(name: val[3].value.to_sym,
|
206
|
+
ivar_name: val[4],
|
207
|
+
type: val[6],
|
208
|
+
kind: val[2],
|
220
209
|
annotations: val[0],
|
221
210
|
location: location,
|
222
211
|
comment: leading_comment(val[0].first&.location || location))
|
223
212
|
}
|
224
|
-
| annotations kATTRWRITER keyword type {
|
225
|
-
location = val[1].location + val[
|
226
|
-
result = Members::AttrWriter.new(name: val[
|
213
|
+
| annotations kATTRWRITER attribute_kind keyword type {
|
214
|
+
location = val[1].location + val[4].location
|
215
|
+
result = Members::AttrWriter.new(name: val[3].value,
|
227
216
|
ivar_name: nil,
|
228
|
-
|
217
|
+
kind: val[2],
|
218
|
+
type: val[4],
|
229
219
|
annotations: val[0],
|
230
220
|
location: location,
|
231
221
|
comment: leading_comment(val[0].first&.location || location))
|
232
222
|
}
|
233
|
-
| annotations kATTRWRITER method_name attr_var_opt kCOLON type {
|
234
|
-
location = val[1].location + val[
|
235
|
-
result = Members::AttrWriter.new(name: val[
|
236
|
-
ivar_name: val[
|
237
|
-
|
223
|
+
| annotations kATTRWRITER attribute_kind method_name attr_var_opt kCOLON type {
|
224
|
+
location = val[1].location + val[6].location
|
225
|
+
result = Members::AttrWriter.new(name: val[3].value.to_sym,
|
226
|
+
ivar_name: val[4],
|
227
|
+
kind: val[2],
|
228
|
+
type: val[6],
|
238
229
|
annotations: val[0],
|
239
230
|
location: location,
|
240
231
|
comment: leading_comment(val[0].first&.location || location))
|
241
232
|
}
|
242
|
-
| annotations kATTRACCESSOR keyword type {
|
243
|
-
location = val[1].location + val[
|
244
|
-
result = Members::AttrAccessor.new(name: val[
|
233
|
+
| annotations kATTRACCESSOR attribute_kind keyword type {
|
234
|
+
location = val[1].location + val[4].location
|
235
|
+
result = Members::AttrAccessor.new(name: val[3].value,
|
245
236
|
ivar_name: nil,
|
246
|
-
|
237
|
+
kind: val[2],
|
238
|
+
type: val[4],
|
247
239
|
annotations: val[0],
|
248
240
|
location: location,
|
249
241
|
comment: leading_comment(val[0].first&.location || location))
|
250
242
|
}
|
251
|
-
| annotations kATTRACCESSOR method_name attr_var_opt kCOLON type {
|
252
|
-
location = val[1].location + val[
|
253
|
-
result = Members::AttrAccessor.new(name: val[
|
254
|
-
ivar_name: val[
|
255
|
-
|
243
|
+
| annotations kATTRACCESSOR attribute_kind method_name attr_var_opt kCOLON type {
|
244
|
+
location = val[1].location + val[6].location
|
245
|
+
result = Members::AttrAccessor.new(name: val[3].value.to_sym,
|
246
|
+
ivar_name: val[4],
|
247
|
+
kind: val[2],
|
248
|
+
type: val[6],
|
256
249
|
annotations: val[0],
|
257
250
|
location: location,
|
258
251
|
comment: leading_comment(val[0].first&.location || location))
|
@@ -474,26 +467,13 @@ rule
|
|
474
467
|
}
|
475
468
|
|
476
469
|
method_type:
|
477
|
-
start_merged_scope type_params
|
470
|
+
start_merged_scope type_params proc_type {
|
478
471
|
reset_variable_scope
|
479
472
|
|
480
|
-
location = (val[1] || val[2]
|
473
|
+
location = (val[1] || val[2]).location + val[2].location
|
481
474
|
type_params = val[1]&.value || []
|
482
475
|
|
483
|
-
|
484
|
-
|
485
|
-
type = Types::Function.new(
|
486
|
-
required_positionals: params[0],
|
487
|
-
optional_positionals: params[1],
|
488
|
-
rest_positionals: params[2],
|
489
|
-
trailing_positionals: params[3],
|
490
|
-
required_keywords: params[4],
|
491
|
-
optional_keywords: params[5],
|
492
|
-
rest_keywords: params[6],
|
493
|
-
return_type: val[5]
|
494
|
-
)
|
495
|
-
|
496
|
-
block = val[3]&.value
|
476
|
+
type, block = val[2].value
|
497
477
|
|
498
478
|
result = MethodType.new(type_params: type_params,
|
499
479
|
type: type,
|
@@ -507,14 +487,13 @@ rule
|
|
507
487
|
result = LocatedValue.new(value: val[1], location: val[0].location + val[2].location)
|
508
488
|
}
|
509
489
|
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
block = MethodType::Block.new(type: val[1].value, required: true)
|
490
|
+
block:
|
491
|
+
kLBRACE simple_function_type kRBRACE {
|
492
|
+
block = Types::Block.new(type: val[1].value, required: true)
|
514
493
|
result = LocatedValue.new(value: block, location: val[0].location + val[2].location)
|
515
494
|
}
|
516
|
-
| kQUESTION kLBRACE
|
517
|
-
block =
|
495
|
+
| kQUESTION kLBRACE simple_function_type kRBRACE {
|
496
|
+
block = Types::Block.new(type: val[2].value, required: false)
|
518
497
|
result = LocatedValue.new(value: block, location: val[0].location + val[3].location)
|
519
498
|
}
|
520
499
|
|
@@ -797,8 +776,9 @@ rule
|
|
797
776
|
result = Types::ClassSingleton.new(name: val[2].value,
|
798
777
|
location: val[0].location + val[3].location)
|
799
778
|
}
|
800
|
-
| kHAT
|
801
|
-
|
779
|
+
| kHAT proc_type {
|
780
|
+
type, block = val[1].value
|
781
|
+
result = Types::Proc.new(type: type, block: block, location: val[0].location + val[1].location)
|
802
782
|
}
|
803
783
|
| simple_type kQUESTION {
|
804
784
|
result = Types::Optional.new(type: val[0], location: val[0].location + val[1].location)
|
@@ -842,6 +822,15 @@ rule
|
|
842
822
|
| keyword type {
|
843
823
|
result = { val[0].value => val[1] }
|
844
824
|
}
|
825
|
+
| identifier_keywords kCOLON type {
|
826
|
+
result = { val[0].value => val[2] }
|
827
|
+
}
|
828
|
+
| tQUOTEDIDENT kCOLON type {
|
829
|
+
result = { val[0].value => val[2] }
|
830
|
+
}
|
831
|
+
| tQUOTEDMETHOD kCOLON type {
|
832
|
+
result = { val[0].value => val[2] }
|
833
|
+
}
|
845
834
|
|
846
835
|
keyword_name:
|
847
836
|
keyword
|
@@ -851,7 +840,32 @@ rule
|
|
851
840
|
|
852
841
|
keyword: tLKEYWORD | tUKEYWORD | tLKEYWORD_Q_E | tUKEYWORD_Q_E
|
853
842
|
|
854
|
-
|
843
|
+
proc_type:
|
844
|
+
params_opt block kARROW simple_type {
|
845
|
+
location = (val[0] || val[1] || val[2]).location + val[3].location
|
846
|
+
|
847
|
+
params = val[0]&.value || [[], [], nil, [], {}, {}, nil]
|
848
|
+
|
849
|
+
type = Types::Function.new(
|
850
|
+
required_positionals: params[0],
|
851
|
+
optional_positionals: params[1],
|
852
|
+
rest_positionals: params[2],
|
853
|
+
trailing_positionals: params[3],
|
854
|
+
required_keywords: params[4],
|
855
|
+
optional_keywords: params[5],
|
856
|
+
rest_keywords: params[6],
|
857
|
+
return_type: val[3]
|
858
|
+
)
|
859
|
+
|
860
|
+
block = val[1].value
|
861
|
+
|
862
|
+
result = LocatedValue.new(value: [type, block], location: location)
|
863
|
+
}
|
864
|
+
| simple_function_type {
|
865
|
+
result = LocatedValue.new(value: [val[0].value, nil], location: val[0].location)
|
866
|
+
}
|
867
|
+
|
868
|
+
simple_function_type:
|
855
869
|
kLPAREN params kRPAREN kARROW simple_type {
|
856
870
|
location = val[0].location + val[4].location
|
857
871
|
type = Types::Function.new(
|
@@ -883,7 +897,7 @@ rule
|
|
883
897
|
result = LocatedValue.new(value: type, location: location)
|
884
898
|
}
|
885
899
|
|
886
|
-
|
900
|
+
params:
|
887
901
|
required_positional kCOMMA params {
|
888
902
|
result = val[2]
|
889
903
|
result[0].unshift(val[0])
|
@@ -1294,6 +1308,10 @@ ANNOTATION_RE = Regexp.union(/%a\{.*?\}/,
|
|
1294
1308
|
/%a\(.*?\)/,
|
1295
1309
|
/%a\<.*?\>/,
|
1296
1310
|
/%a\|.*?\|/)
|
1311
|
+
|
1312
|
+
escape_sequences = %w[a b e f n r s t v "].map { |l| "\\\\#{l}" }
|
1313
|
+
DBL_QUOTE_STR_ESCAPE_SEQUENCES_RE = /(#{escape_sequences.join("|")})/
|
1314
|
+
|
1297
1315
|
def next_token
|
1298
1316
|
if @type
|
1299
1317
|
type = @type
|
@@ -1373,7 +1391,21 @@ def next_token
|
|
1373
1391
|
when input.scan(/[a-z_]\w*\b/)
|
1374
1392
|
new_token(:tLIDENT)
|
1375
1393
|
when input.scan(/"(\\"|[^"])*"/)
|
1376
|
-
s = input.matched.yield_self {|s| s[1, s.length - 2] }
|
1394
|
+
s = input.matched.yield_self {|s| s[1, s.length - 2] }
|
1395
|
+
.gsub(DBL_QUOTE_STR_ESCAPE_SEQUENCES_RE) do |match|
|
1396
|
+
case match
|
1397
|
+
when '\\a' then "\a"
|
1398
|
+
when '\\b' then "\b"
|
1399
|
+
when '\\e' then "\e"
|
1400
|
+
when '\\f' then "\f"
|
1401
|
+
when '\\n' then "\n"
|
1402
|
+
when '\\r' then "\r"
|
1403
|
+
when '\\s' then "\s"
|
1404
|
+
when '\\t' then "\t"
|
1405
|
+
when '\\v' then "\v"
|
1406
|
+
when '\\"' then '"'
|
1407
|
+
end
|
1408
|
+
end
|
1377
1409
|
new_token(:tSTRING, s)
|
1378
1410
|
when input.scan(/'(\\'|[^'])*'/)
|
1379
1411
|
s = input.matched.yield_self {|s| s[1, s.length - 2] }.gsub(/\\'/, "'")
|
data/lib/rbs/prototype/rb.rb
CHANGED
@@ -15,6 +15,14 @@ module RBS
|
|
15
15
|
:instance
|
16
16
|
end
|
17
17
|
end
|
18
|
+
|
19
|
+
def attribute_kind
|
20
|
+
if singleton
|
21
|
+
:singleton
|
22
|
+
else
|
23
|
+
:instance
|
24
|
+
end
|
25
|
+
end
|
18
26
|
end
|
19
27
|
|
20
28
|
attr_reader :source_decls
|
@@ -77,7 +85,7 @@ module RBS
|
|
77
85
|
class_name, super_class, *class_body = node.children
|
78
86
|
kls = AST::Declarations::Class.new(
|
79
87
|
name: const_to_name(class_name),
|
80
|
-
super_class: super_class && AST::Declarations::Class::Super.new(name: const_to_name(super_class), args: []),
|
88
|
+
super_class: super_class && AST::Declarations::Class::Super.new(name: const_to_name(super_class), args: [], location: nil),
|
81
89
|
type_params: AST::Declarations::ModuleTypeParams.empty,
|
82
90
|
members: [],
|
83
91
|
annotations: [],
|
@@ -121,9 +129,13 @@ module RBS
|
|
121
129
|
RBS.logger.warn "`class <<` syntax with not-self may be compiled to incorrect code: #{this}"
|
122
130
|
end
|
123
131
|
|
132
|
+
accessibility = current_accessibility(decls)
|
133
|
+
|
124
134
|
ctx = Context.initial.tap { |ctx| ctx.singleton = true }
|
125
135
|
process_children(body, decls: decls, comments: comments, context: ctx)
|
126
136
|
|
137
|
+
decls << accessibility
|
138
|
+
|
127
139
|
when :DEFN, :DEFS
|
128
140
|
if node.type == :DEFN
|
129
141
|
def_name, def_body = node.children
|
@@ -202,6 +214,7 @@ module RBS
|
|
202
214
|
name: name,
|
203
215
|
ivar_name: nil,
|
204
216
|
type: Types::Bases::Any.new(location: nil),
|
217
|
+
kind: context.attribute_kind,
|
205
218
|
location: nil,
|
206
219
|
comment: comments[node.first_lineno - 1],
|
207
220
|
annotations: []
|
@@ -215,6 +228,7 @@ module RBS
|
|
215
228
|
name: name,
|
216
229
|
ivar_name: nil,
|
217
230
|
type: Types::Bases::Any.new(location: nil),
|
231
|
+
kind: context.attribute_kind,
|
218
232
|
location: nil,
|
219
233
|
comment: comments[node.first_lineno - 1],
|
220
234
|
annotations: []
|
@@ -228,6 +242,7 @@ module RBS
|
|
228
242
|
name: name,
|
229
243
|
ivar_name: nil,
|
230
244
|
type: Types::Bases::Any.new(location: nil),
|
245
|
+
kind: context.attribute_kind,
|
231
246
|
location: nil,
|
232
247
|
comment: comments[node.first_lineno - 1],
|
233
248
|
annotations: []
|
@@ -549,7 +564,7 @@ module RBS
|
|
549
564
|
method_block = nil
|
550
565
|
|
551
566
|
if block
|
552
|
-
method_block =
|
567
|
+
method_block = Types::Block.new(
|
553
568
|
required: true,
|
554
569
|
type: Types::Function.empty(untyped)
|
555
570
|
)
|
@@ -557,7 +572,7 @@ module RBS
|
|
557
572
|
|
558
573
|
if body_node
|
559
574
|
if (yields = any_node?(body_node) {|n| n.type == :YIELD })
|
560
|
-
method_block =
|
575
|
+
method_block = Types::Block.new(
|
561
576
|
required: true,
|
562
577
|
type: Types::Function.empty(untyped)
|
563
578
|
)
|
data/lib/rbs/prototype/rbi.rb
CHANGED
@@ -47,7 +47,7 @@ module RBS
|
|
47
47
|
def push_class(name, super_class, comment:)
|
48
48
|
modules.push AST::Declarations::Class.new(
|
49
49
|
name: nested_name(name),
|
50
|
-
super_class: super_class && AST::Declarations::Class::Super.new(name: const_to_name(super_class), args: []),
|
50
|
+
super_class: super_class && AST::Declarations::Class::Super.new(name: const_to_name(super_class), args: [], location: nil),
|
51
51
|
type_params: AST::Declarations::ModuleTypeParams.empty,
|
52
52
|
members: [],
|
53
53
|
annotations: [],
|
@@ -387,19 +387,19 @@ module RBS
|
|
387
387
|
if block
|
388
388
|
if (type = vars[block])
|
389
389
|
if type.is_a?(Types::Proc)
|
390
|
-
method_block =
|
390
|
+
method_block = Types::Block.new(required: true, type: type.type)
|
391
391
|
elsif type.is_a?(Types::Bases::Any)
|
392
|
-
method_block =
|
392
|
+
method_block = Types::Block.new(
|
393
393
|
required: true,
|
394
394
|
type: Types::Function.empty(Types::Bases::Any.new(location: nil))
|
395
395
|
)
|
396
396
|
# Handle an optional block like `T.nilable(T.proc.void)`.
|
397
397
|
elsif type.is_a?(Types::Optional) && type.type.is_a?(Types::Proc)
|
398
|
-
method_block =
|
398
|
+
method_block = Types::Block.new(required: false, type: type.type.type)
|
399
399
|
else
|
400
400
|
STDERR.puts "Unexpected block type: #{type}"
|
401
401
|
PP.pp args_node, STDERR
|
402
|
-
method_block =
|
402
|
+
method_block = Types::Block.new(
|
403
403
|
required: true,
|
404
404
|
type: Types::Function.empty(Types::Bases::Any.new(location: nil))
|
405
405
|
)
|
@@ -485,7 +485,7 @@ module RBS
|
|
485
485
|
Types::Tuple.new(types: types, location: nil)
|
486
486
|
else
|
487
487
|
if proc_type?(type_node)
|
488
|
-
Types::Proc.new(type: method_type(nil, type_node, variables: variables).type, location: nil)
|
488
|
+
Types::Proc.new(type: method_type(nil, type_node, variables: variables).type, block: nil, location: nil)
|
489
489
|
else
|
490
490
|
STDERR.puts "Unexpected type_node:"
|
491
491
|
PP.pp type_node, STDERR
|
@@ -61,11 +61,32 @@ module RBS
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
def
|
65
|
-
supers = Set
|
66
|
-
|
64
|
+
def each_included_module(type_name, mod)
|
65
|
+
supers = Set[]
|
66
|
+
|
67
|
+
mod.included_modules.each do |mix|
|
68
|
+
supers.merge(mix.included_modules)
|
69
|
+
end
|
70
|
+
|
71
|
+
if mod.is_a?(Class)
|
72
|
+
mod.superclass.included_modules.each do |mix|
|
73
|
+
supers << mix
|
74
|
+
supers.merge(mix.included_modules)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
mod.included_modules.each do |mix|
|
67
79
|
unless supers.include?(mix)
|
68
|
-
|
80
|
+
unless const_name(mix)
|
81
|
+
RBS.logger.warn("Skipping anonymous module #{mix} included in #{mod}")
|
82
|
+
else
|
83
|
+
module_name = module_full_name = to_type_name(const_name(mix))
|
84
|
+
if module_full_name.namespace == type_name.namespace
|
85
|
+
module_name = TypeName.new(name: module_full_name.name, namespace: Namespace.empty)
|
86
|
+
end
|
87
|
+
|
88
|
+
yield module_name, module_full_name, mix
|
89
|
+
end
|
69
90
|
end
|
70
91
|
end
|
71
92
|
end
|
@@ -103,7 +124,7 @@ module RBS
|
|
103
124
|
when :keyrest
|
104
125
|
rest_keywords = Types::Function::Param.new(name: nil, type: untyped)
|
105
126
|
when :block
|
106
|
-
block =
|
127
|
+
block = Types::Block.new(
|
107
128
|
type: Types::Function.empty(untyped).update(rest_positionals: Types::Function::Param.new(name: nil, type: untyped)),
|
108
129
|
required: true
|
109
130
|
)
|
@@ -298,11 +319,13 @@ module RBS
|
|
298
319
|
location: nil
|
299
320
|
)
|
300
321
|
else
|
301
|
-
|
322
|
+
value_type_name = to_type_name(const_name(value.class))
|
323
|
+
args = type_args(value_type_name)
|
324
|
+
Types::ClassInstance.new(name: value_type_name, args: args, location: nil)
|
302
325
|
end
|
303
326
|
|
304
327
|
@decls << AST::Declarations::Constant.new(
|
305
|
-
name: "#{mod
|
328
|
+
name: "#{const_name(mod)}::#{name}",
|
306
329
|
type: type,
|
307
330
|
location: nil,
|
308
331
|
comment: nil
|
@@ -311,14 +334,16 @@ module RBS
|
|
311
334
|
end
|
312
335
|
|
313
336
|
def generate_class(mod)
|
314
|
-
type_name = to_type_name(mod
|
337
|
+
type_name = to_type_name(const_name(mod))
|
315
338
|
super_class = if mod.superclass == ::Object
|
316
339
|
nil
|
317
|
-
elsif mod.superclass.
|
340
|
+
elsif const_name(mod.superclass).nil?
|
318
341
|
RBS.logger.warn("Skipping anonymous superclass #{mod.superclass} of #{mod}")
|
319
342
|
nil
|
320
343
|
else
|
321
|
-
|
344
|
+
super_name = to_type_name(const_name(mod.superclass))
|
345
|
+
super_args = type_args(super_name)
|
346
|
+
AST::Declarations::Class::Super.new(name: super_name, args: super_args, location: nil)
|
322
347
|
end
|
323
348
|
|
324
349
|
decl = AST::Declarations::Class.new(
|
@@ -331,20 +356,22 @@ module RBS
|
|
331
356
|
comment: nil
|
332
357
|
)
|
333
358
|
|
334
|
-
|
335
|
-
|
336
|
-
RBS.logger.warn("Skipping anonymous module #{included_module} included in #{mod}")
|
337
|
-
next
|
338
|
-
end
|
339
|
-
|
340
|
-
module_name = to_type_name(included_module.name)
|
341
|
-
if module_name.namespace == type_name.namespace
|
342
|
-
module_name = TypeName.new(name: module_name.name, namespace: Namespace.empty)
|
343
|
-
end
|
344
|
-
|
359
|
+
each_included_module(type_name, mod) do |module_name, module_full_name, _|
|
360
|
+
args = type_args(module_full_name)
|
345
361
|
decl.members << AST::Members::Include.new(
|
346
362
|
name: module_name,
|
347
|
-
args:
|
363
|
+
args: args,
|
364
|
+
location: nil,
|
365
|
+
comment: nil,
|
366
|
+
annotations: []
|
367
|
+
)
|
368
|
+
end
|
369
|
+
|
370
|
+
each_included_module(type_name, mod.singleton_class) do |module_name, module_full_name ,_|
|
371
|
+
args = type_args(module_full_name)
|
372
|
+
decl.members << AST::Members::Extend.new(
|
373
|
+
name: module_name,
|
374
|
+
args: args,
|
348
375
|
location: nil,
|
349
376
|
comment: nil,
|
350
377
|
annotations: []
|
@@ -378,21 +405,22 @@ module RBS
|
|
378
405
|
comment: nil
|
379
406
|
)
|
380
407
|
|
381
|
-
|
382
|
-
|
383
|
-
unless included_module_name
|
384
|
-
RBS.logger.warn("Skipping anonymous module #{included_module} included in #{mod}")
|
385
|
-
next
|
386
|
-
end
|
387
|
-
|
388
|
-
module_name = to_type_name(included_module_name)
|
389
|
-
if module_name.namespace == type_name.namespace
|
390
|
-
module_name = TypeName.new(name: module_name.name, namespace: Namespace.empty)
|
391
|
-
end
|
392
|
-
|
408
|
+
each_included_module(type_name, mod) do |module_name, module_full_name, _|
|
409
|
+
args = type_args(module_full_name)
|
393
410
|
decl.members << AST::Members::Include.new(
|
394
411
|
name: module_name,
|
395
|
-
args:
|
412
|
+
args: args,
|
413
|
+
location: nil,
|
414
|
+
comment: nil,
|
415
|
+
annotations: []
|
416
|
+
)
|
417
|
+
end
|
418
|
+
|
419
|
+
each_included_module(type_name, mod.singleton_class) do |module_name, module_full_name, _|
|
420
|
+
args = type_args(module_full_name)
|
421
|
+
decl.members << AST::Members::Extend.new(
|
422
|
+
name: module_name,
|
423
|
+
args: args,
|
396
424
|
location: nil,
|
397
425
|
comment: nil,
|
398
426
|
annotations: []
|
@@ -410,6 +438,14 @@ module RBS
|
|
410
438
|
@module_name_method ||= Module.instance_method(:name)
|
411
439
|
@module_name_method.bind(const).call
|
412
440
|
end
|
441
|
+
|
442
|
+
def type_args(type_name)
|
443
|
+
if class_decl = env.class_decls[type_name.absolute!]
|
444
|
+
class_decl.type_params.size.times.map { :untyped }
|
445
|
+
else
|
446
|
+
[]
|
447
|
+
end
|
448
|
+
end
|
413
449
|
end
|
414
450
|
end
|
415
451
|
end
|