rbs 3.2.2 → 3.3.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/comments.yml +1 -1
- data/.github/workflows/ruby.yml +7 -2
- data/CHANGELOG.md +85 -0
- data/Gemfile.lock +14 -14
- data/README.md +11 -2
- data/Rakefile +10 -7
- data/Steepfile +7 -7
- data/core/basic_object.rbs +7 -7
- data/core/binding.rbs +3 -3
- data/core/builtin.rbs +171 -5
- data/core/constants.rbs +17 -17
- data/core/dir.rbs +3 -3
- data/core/encoding.rbs +434 -628
- data/core/enumerator.rbs +37 -0
- data/core/exception.rbs +11 -11
- data/core/false_class.rbs +5 -11
- data/core/fiber.rbs +3 -3
- data/core/file_test.rbs +28 -26
- data/core/kernel.rbs +900 -21
- data/core/marshal.rbs +24 -14
- data/core/match_data.rbs +8 -8
- data/core/math.rbs +57 -53
- data/core/method.rbs +3 -1
- data/core/module.rbs +38 -36
- data/core/nil_class.rbs +7 -13
- data/core/object.rbs +3 -966
- data/core/process.rbs +3 -3
- data/core/ractor.rbs +2 -2
- data/core/rb_config.rbs +64 -43
- data/core/regexp.rbs +3 -3
- data/core/signal.rbs +10 -4
- data/core/struct.rbs +1 -1
- data/core/thread.rbs +7 -7
- data/core/thread_group.rbs +9 -9
- data/core/true_class.rbs +5 -11
- data/core/unbound_method.rbs +56 -7
- data/core/warning.rbs +33 -0
- data/docs/collection.md +56 -6
- data/docs/data_and_struct.md +57 -0
- data/docs/stdlib.md +61 -2
- data/docs/syntax.md +123 -2
- data/ext/rbs_extension/lexer.c +624 -569
- data/ext/rbs_extension/lexer.h +1 -0
- data/ext/rbs_extension/lexer.re +1 -0
- data/ext/rbs_extension/lexstate.c +1 -0
- data/ext/rbs_extension/parser.c +6 -0
- data/goodcheck.yml +2 -2
- data/lib/rbs/annotate/formatter.rb +13 -3
- data/lib/rbs/annotate/rdoc_source.rb +10 -1
- data/lib/rbs/cli/colored_io.rb +48 -0
- data/lib/rbs/cli/diff.rb +80 -0
- data/lib/rbs/cli.rb +151 -16
- data/lib/rbs/collection/config/lockfile.rb +0 -25
- data/lib/rbs/collection/config/lockfile_generator.rb +0 -6
- data/lib/rbs/collection/installer.rb +1 -1
- data/lib/rbs/collection/sources/git.rb +6 -4
- data/lib/rbs/collection/sources/local.rb +7 -5
- data/lib/rbs/diff.rb +104 -0
- data/lib/rbs/environment.rb +1 -1
- data/lib/rbs/method_type.rb +23 -0
- data/lib/rbs/prototype/rb.rb +2 -9
- data/lib/rbs/prototype/runtime/helpers.rb +59 -0
- data/lib/rbs/prototype/runtime/value_object_generator.rb +236 -0
- data/lib/rbs/prototype/runtime.rb +234 -150
- data/lib/rbs/sorter.rb +144 -117
- data/lib/rbs/test/guaranteed.rb +31 -0
- data/lib/rbs/test/type_check.rb +4 -4
- data/lib/rbs/test.rb +3 -0
- data/lib/rbs/types.rb +184 -3
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +4 -4
- data/lib/rbs.rb +1 -0
- data/rbs.gemspec +1 -0
- data/sig/annotate/formatter.rbs +2 -2
- data/sig/annotate/rdoc_annotater.rbs +1 -1
- data/sig/cli/colored_io.rbs +15 -0
- data/sig/cli/diff.rbs +21 -0
- data/sig/cli.rbs +2 -0
- data/sig/collection/config/lockfile.rbs +0 -6
- data/sig/diff.rbs +23 -0
- data/sig/errors.rbs +1 -5
- data/sig/method_types.rbs +6 -0
- data/sig/prototype/runtime.rbs +108 -0
- data/sig/rdoc/rbs.rbs +4 -0
- data/sig/shims/bundler.rbs +5 -0
- data/sig/sorter.rbs +23 -5
- data/sig/types.rbs +29 -0
- data/stdlib/benchmark/0/benchmark.rbs +1 -1
- data/stdlib/cgi/0/core.rbs +2 -2
- data/stdlib/did_you_mean/0/did_you_mean.rbs +2 -2
- data/stdlib/digest/0/digest.rbs +1 -1
- data/stdlib/fileutils/0/fileutils.rbs +1 -1
- data/stdlib/forwardable/0/forwardable.rbs +4 -4
- data/stdlib/io-console/0/io-console.rbs +1 -1
- data/stdlib/json/0/json.rbs +37 -0
- data/stdlib/logger/0/logger.rbs +2 -2
- data/stdlib/net-http/0/manifest.yaml +1 -1
- data/stdlib/net-http/0/net-http.rbs +16 -63
- data/stdlib/net-protocol/0/manifest.yaml +2 -0
- data/stdlib/net-protocol/0/net-protocol.rbs +56 -0
- data/stdlib/openssl/0/openssl.rbs +1 -1
- data/stdlib/pp/0/manifest.yaml +2 -0
- data/stdlib/pp/0/pp.rbs +301 -0
- data/stdlib/{yaml → psych}/0/dbm.rbs +3 -3
- data/stdlib/psych/0/manifest.yaml +3 -0
- data/stdlib/psych/0/psych.rbs +391 -0
- data/stdlib/{yaml → psych}/0/store.rbs +2 -2
- data/stdlib/rdoc/0/code_object.rbs +55 -0
- data/stdlib/rdoc/0/comment.rbs +60 -0
- data/stdlib/rdoc/0/context.rbs +153 -0
- data/stdlib/rdoc/0/markup.rbs +119 -0
- data/stdlib/rdoc/0/parser.rbs +56 -0
- data/stdlib/rdoc/0/rdoc.rbs +0 -372
- data/stdlib/rdoc/0/ri.rbs +17 -0
- data/stdlib/rdoc/0/store.rbs +48 -0
- data/stdlib/rdoc/0/top_level.rbs +97 -0
- data/stdlib/socket/0/basic_socket.rbs +1 -1
- data/stdlib/socket/0/socket.rbs +1 -1
- data/stdlib/uri/0/common.rbs +1 -1
- data/stdlib/yaml/0/manifest.yaml +1 -2
- data/stdlib/yaml/0/yaml.rbs +1 -199
- metadata +46 -9
- data/sig/shims/pp.rbs +0 -3
- data/sig/shims.rbs +0 -47
data/lib/rbs/sorter.rb
CHANGED
@@ -28,140 +28,167 @@ module RBS
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
def group(member)
|
32
|
-
case member
|
33
|
-
when Declarations::TypeAlias
|
34
|
-
-3
|
35
|
-
when Declarations::Constant
|
36
|
-
-2
|
37
|
-
when Declarations::Class, Declarations::Module, Declarations::Interface
|
38
|
-
-1
|
39
|
-
when Members::Include
|
40
|
-
0.0
|
41
|
-
when Members::Prepend
|
42
|
-
0.2
|
43
|
-
when Members::Extend
|
44
|
-
0.4
|
45
|
-
when Members::ClassVariable
|
46
|
-
1
|
47
|
-
when Members::ClassInstanceVariable
|
48
|
-
2
|
49
|
-
when Members::InstanceVariable
|
50
|
-
3
|
51
|
-
when Members::AttrAccessor, Members::AttrWriter, Members::AttrReader
|
52
|
-
if member.kind == :singleton
|
53
|
-
5.0
|
54
|
-
else
|
55
|
-
6.0
|
56
|
-
end
|
57
|
-
when Members::MethodDefinition
|
58
|
-
case member.kind
|
59
|
-
when :singleton_instance
|
60
|
-
4
|
61
|
-
when :singleton
|
62
|
-
if member.name == :new
|
63
|
-
5.2
|
64
|
-
elsif member.visibility == :public
|
65
|
-
5.4
|
66
|
-
else
|
67
|
-
5.6
|
68
|
-
end
|
69
|
-
else
|
70
|
-
if member.name == :initialize
|
71
|
-
6.2
|
72
|
-
elsif member.visibility == :public
|
73
|
-
6.4
|
74
|
-
else
|
75
|
-
6.6
|
76
|
-
end
|
77
|
-
end
|
78
|
-
when Members::Alias
|
79
|
-
if member.singleton?
|
80
|
-
5.4
|
81
|
-
else
|
82
|
-
6.4
|
83
|
-
end
|
84
|
-
else
|
85
|
-
raise
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
def key(member)
|
90
|
-
case member
|
91
|
-
when Members::Include, Members::Extend, Members::Prepend
|
92
|
-
member.name.to_s
|
93
|
-
when Members::ClassVariable, Members::ClassInstanceVariable, Members::InstanceVariable
|
94
|
-
member.name.to_s
|
95
|
-
when Members::AttrAccessor, Members::AttrWriter, Members::AttrReader
|
96
|
-
member.name.to_s
|
97
|
-
when Members::MethodDefinition
|
98
|
-
member.name.to_s
|
99
|
-
when Members::Alias
|
100
|
-
member.new_name.to_s
|
101
|
-
when Declarations::Constant
|
102
|
-
member.name.to_s
|
103
|
-
when Declarations::TypeAlias
|
104
|
-
member.name.to_s
|
105
|
-
when Declarations::Class, Declarations::Module, Declarations::Interface
|
106
|
-
member.name.to_s
|
107
|
-
else
|
108
|
-
raise
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
31
|
def sort_decl!(decl)
|
113
32
|
case decl
|
114
33
|
when Declarations::Class, Declarations::Module, Declarations::Interface
|
34
|
+
partitioned = {
|
35
|
+
type_alias_decls: [],
|
36
|
+
constant_decls: [],
|
37
|
+
class_decls: [],
|
38
|
+
mixin_includes: [],
|
39
|
+
mixin_prepends: [],
|
40
|
+
mixin_extends: [],
|
41
|
+
class_variables: [],
|
42
|
+
class_instance_variables: [],
|
43
|
+
instance_variables: [],
|
44
|
+
singleton_attributes: [],
|
45
|
+
instance_attributes: [],
|
46
|
+
module_functions: [],
|
47
|
+
singleton_new_methods: [],
|
48
|
+
public_singleton_methods: [],
|
49
|
+
private_singleton_methods: [],
|
50
|
+
instance_initialize_methods: [],
|
51
|
+
public_instance_methods: [],
|
52
|
+
private_instance_methods: [],
|
53
|
+
} #: partitioned
|
54
|
+
|
115
55
|
decl.members.each { |m| sort_decl! m }
|
116
56
|
|
117
|
-
|
118
|
-
|
119
|
-
|
57
|
+
visibility_annotated_members = [] #: Array[member]
|
58
|
+
|
59
|
+
decl.members.inject(:public) do |current_visibility, member| #$ AST::Members::visibility
|
60
|
+
case member
|
120
61
|
when Members::Public
|
121
|
-
|
122
|
-
nil
|
62
|
+
:public
|
123
63
|
when Members::Private
|
124
|
-
|
125
|
-
nil
|
64
|
+
:private
|
126
65
|
when Members::MethodDefinition, Members::AttrReader, Members::AttrWriter, Members::AttrAccessor
|
127
|
-
|
66
|
+
visibility_annotated_members << member.update(visibility: member.visibility || current_visibility)
|
67
|
+
current_visibility
|
128
68
|
else
|
129
|
-
|
69
|
+
visibility_annotated_members << member
|
70
|
+
current_visibility
|
130
71
|
end
|
131
72
|
end
|
132
|
-
decl.members.compact!
|
133
|
-
|
134
|
-
decl.members.sort! do |m1, m2|
|
135
|
-
group1 = group(m1)
|
136
|
-
group2 = group(m2)
|
137
73
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
when Members::
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
74
|
+
visibility_annotated_members.each do |member|
|
75
|
+
case member
|
76
|
+
when Declarations::TypeAlias
|
77
|
+
partitioned[:type_alias_decls] << member
|
78
|
+
when Declarations::Constant
|
79
|
+
partitioned[:constant_decls] << member
|
80
|
+
when Declarations::Class, Declarations::Module, Declarations::Interface
|
81
|
+
partitioned[:class_decls] << member
|
82
|
+
when Members::Include
|
83
|
+
partitioned[:mixin_includes] << member
|
84
|
+
when Members::Prepend
|
85
|
+
partitioned[:mixin_prepends] << member
|
86
|
+
when Members::Extend
|
87
|
+
partitioned[:mixin_extends] << member
|
88
|
+
when Members::ClassVariable
|
89
|
+
partitioned[:class_variables] << member
|
90
|
+
when Members::ClassInstanceVariable
|
91
|
+
partitioned[:class_instance_variables] << member
|
92
|
+
when Members::InstanceVariable
|
93
|
+
partitioned[:instance_variables] << member
|
94
|
+
when Members::AttrAccessor, Members::AttrWriter, Members::AttrReader
|
95
|
+
if member.kind == :singleton
|
96
|
+
partitioned[:singleton_attributes] << member.update(visibility: nil)
|
97
|
+
else
|
98
|
+
partitioned[:instance_attributes] << member.update(visibility: nil)
|
99
|
+
end
|
100
|
+
when Members::MethodDefinition
|
101
|
+
case member.kind
|
102
|
+
when :singleton_instance
|
103
|
+
partitioned[:module_functions] << member.update(visibility: nil)
|
104
|
+
when :singleton
|
105
|
+
if member.name == :new
|
106
|
+
partitioned[:singleton_new_methods] << member.update(visibility: nil)
|
107
|
+
elsif member.visibility == :public
|
108
|
+
partitioned[:public_singleton_methods] << member.update(visibility: nil)
|
109
|
+
else
|
110
|
+
partitioned[:private_singleton_methods] << member.update(visibility: nil)
|
111
|
+
end
|
157
112
|
else
|
158
|
-
|
113
|
+
if member.name == :initialize
|
114
|
+
partitioned[:instance_initialize_methods] << member.update(visibility: nil)
|
115
|
+
elsif member.visibility == :public
|
116
|
+
partitioned[:public_instance_methods] << member.update(visibility: nil)
|
117
|
+
else
|
118
|
+
partitioned[:private_instance_methods] << member.update(visibility: nil)
|
119
|
+
end
|
159
120
|
end
|
121
|
+
when Members::Alias
|
122
|
+
if member.singleton?
|
123
|
+
partitioned[:public_singleton_methods] << member
|
124
|
+
else
|
125
|
+
partitioned[:public_instance_methods] << member
|
126
|
+
end
|
127
|
+
when Members::Public, Members::Private
|
128
|
+
raise
|
160
129
|
else
|
161
|
-
|
130
|
+
partitioned[:other_decls] << member
|
162
131
|
end
|
163
132
|
end
|
164
|
-
|
133
|
+
|
134
|
+
partitioned[:type_alias_decls].sort_by! {|decl| decl.name.to_s }
|
135
|
+
partitioned[:constant_decls].sort_by! {|decl| decl.name.to_s }
|
136
|
+
partitioned[:class_decls].sort_by! {|decl| decl.name.to_s }
|
137
|
+
partitioned[:mixin_includes].sort_by! {|decl| decl.name.to_s }
|
138
|
+
partitioned[:mixin_prepends].sort_by! {|decl| decl.name.to_s }
|
139
|
+
partitioned[:mixin_extends].sort_by! {|decl| decl.name.to_s }
|
140
|
+
partitioned[:class_variables].sort_by! {|decl| decl.name.to_s }
|
141
|
+
partitioned[:class_instance_variables].sort_by! {|decl| decl.name.to_s }
|
142
|
+
partitioned[:instance_variables].sort_by! {|decl| decl.name.to_s }
|
143
|
+
partitioned[:singleton_attributes].sort_by! {|decl| decl.name.to_s }
|
144
|
+
partitioned[:instance_attributes].sort_by! {|decl| decl.name.to_s }
|
145
|
+
partitioned[:module_functions].sort_by! {|decl| decl.name.to_s }
|
146
|
+
partitioned[:public_singleton_methods].sort_by! {|decl| decl.is_a?(Members::MethodDefinition) ? decl.name.to_s : decl.new_name.to_s }
|
147
|
+
partitioned[:private_singleton_methods].sort_by! {|decl| decl.name.to_s }
|
148
|
+
partitioned[:public_instance_methods].sort_by! {|decl| decl.is_a?(Members::MethodDefinition) ? decl.name.to_s : decl.new_name.to_s }
|
149
|
+
partitioned[:private_instance_methods].sort_by! {|decl| decl.name.to_s }
|
150
|
+
|
151
|
+
members = [] #: Array[member]
|
152
|
+
members.push(*partitioned[:type_alias_decls])
|
153
|
+
members.push(*partitioned[:constant_decls])
|
154
|
+
members.push(*partitioned[:class_decls])
|
155
|
+
members.push(*partitioned[:mixin_includes])
|
156
|
+
members.push(*partitioned[:mixin_prepends])
|
157
|
+
members.push(*partitioned[:mixin_extends])
|
158
|
+
members.push(*partitioned[:class_variables])
|
159
|
+
members.push(*partitioned[:class_instance_variables])
|
160
|
+
members.push(*partitioned[:instance_variables])
|
161
|
+
members.push(*partitioned[:module_functions])
|
162
|
+
members.push(*partitioned[:singleton_attributes])
|
163
|
+
|
164
|
+
current_visibility = :public #: AST::Members::visibility
|
165
|
+
|
166
|
+
members.push(*partitioned[:singleton_new_methods])
|
167
|
+
members.push(*partitioned[:public_singleton_methods])
|
168
|
+
|
169
|
+
if !partitioned[:private_singleton_methods].empty?
|
170
|
+
current_visibility = :private
|
171
|
+
members.push Members::Private.new(location: nil)
|
172
|
+
end
|
173
|
+
members.push(*partitioned[:private_singleton_methods])
|
174
|
+
|
175
|
+
if current_visibility == :private && !partitioned[:public_instance_methods].empty?
|
176
|
+
current_visibility = :public
|
177
|
+
members.push Members::Public.new(location: nil)
|
178
|
+
end
|
179
|
+
members.push(*partitioned[:instance_attributes])
|
180
|
+
members.push(*partitioned[:instance_initialize_methods])
|
181
|
+
members.push(*partitioned[:public_instance_methods])
|
182
|
+
|
183
|
+
if current_visibility == :public && !partitioned[:private_instance_methods].empty?
|
184
|
+
current_visibility = :private
|
185
|
+
members.push Members::Private.new(location: nil)
|
186
|
+
end
|
187
|
+
members.push(*partitioned[:private_instance_methods])
|
188
|
+
|
189
|
+
members.push(*partitioned[:other_decls])
|
190
|
+
|
191
|
+
decl.members.replace(_ = members)
|
165
192
|
end
|
166
193
|
end
|
167
194
|
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module RBS
|
4
|
+
module Test
|
5
|
+
module Guaranteed
|
6
|
+
module Inspect
|
7
|
+
EQUAL = ::BasicObject.instance_method(:equal?)
|
8
|
+
INSPECT = ::Kernel.instance_method(:inspect)
|
9
|
+
private_constant :EQUAL, :INSPECT
|
10
|
+
|
11
|
+
module_function def guaranteed_inspect(obj)
|
12
|
+
obj.inspect
|
13
|
+
rescue NoMethodError => err
|
14
|
+
raise unless err.name == :inspect && EQUAL.bind_call(obj, err.receiver)
|
15
|
+
INSPECT.bind_call(obj)
|
16
|
+
end
|
17
|
+
|
18
|
+
def inspect
|
19
|
+
string = "<#{self.class.name}:"
|
20
|
+
|
21
|
+
instance_variables.each_with_index do |variable, index|
|
22
|
+
string.concat ', ' unless index.zero?
|
23
|
+
string.concat "#{variable}: #{guaranteed_inspect(variable)}"
|
24
|
+
end
|
25
|
+
|
26
|
+
string.concat '>'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/rbs/test/type_check.rb
CHANGED
@@ -136,7 +136,7 @@ module RBS
|
|
136
136
|
end
|
137
137
|
|
138
138
|
def keyword?(value)
|
139
|
-
|
139
|
+
Hash === value && value.each_key.all?(Symbol)
|
140
140
|
end
|
141
141
|
|
142
142
|
def zip_args(args, fun, &block)
|
@@ -302,7 +302,7 @@ module RBS
|
|
302
302
|
val.is_a?(singleton_class)
|
303
303
|
when Types::Interface
|
304
304
|
methods = Set.new(Test.call(val, METHODS))
|
305
|
-
if (definition = builder.build_interface(type.name))
|
305
|
+
if (definition = builder.build_interface(type.name.absolute!))
|
306
306
|
definition.methods.each_key.all? do |method_name|
|
307
307
|
methods.member?(method_name)
|
308
308
|
end
|
@@ -310,7 +310,7 @@ module RBS
|
|
310
310
|
when Types::Variable
|
311
311
|
true
|
312
312
|
when Types::Literal
|
313
|
-
|
313
|
+
type.literal == val
|
314
314
|
when Types::Union
|
315
315
|
type.types.any? {|type| value(val, type) }
|
316
316
|
when Types::Intersection
|
@@ -318,7 +318,7 @@ module RBS
|
|
318
318
|
when Types::Optional
|
319
319
|
Test.call(val, IS_AP, ::NilClass) || value(val, type.type)
|
320
320
|
when Types::Alias
|
321
|
-
value(val, builder.
|
321
|
+
value(val, builder.expand_alias2(type.name.absolute!, type.args))
|
322
322
|
when Types::Tuple
|
323
323
|
Test.call(val, IS_AP, ::Array) &&
|
324
324
|
type.types.map.with_index {|ty, index| value(val[index], ty) }.all?
|
data/lib/rbs/test.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "securerandom"
|
4
|
+
require "rbs/test/guaranteed"
|
4
5
|
require "rbs/test/observer"
|
5
6
|
require "rbs/test/spy"
|
6
7
|
require "rbs/test/errors"
|
@@ -23,6 +24,8 @@ module RBS
|
|
23
24
|
METHODS = Kernel.instance_method(:methods)
|
24
25
|
|
25
26
|
class ArgumentsReturn
|
27
|
+
include Guaranteed::Inspect
|
28
|
+
|
26
29
|
attr_reader :arguments
|
27
30
|
attr_reader :exit_value
|
28
31
|
attr_reader :exit_type
|
data/lib/rbs/types.rb
CHANGED
@@ -73,7 +73,7 @@ module RBS
|
|
73
73
|
when Types::Bases::Void
|
74
74
|
'void'
|
75
75
|
when Types::Bases::Any
|
76
|
-
|
76
|
+
raise
|
77
77
|
when Types::Bases::Nil
|
78
78
|
'nil'
|
79
79
|
when Types::Bases::Top
|
@@ -90,11 +90,32 @@ module RBS
|
|
90
90
|
raise "Unexpected base type: #{inspect}"
|
91
91
|
end
|
92
92
|
end
|
93
|
+
|
94
|
+
def has_self_type?
|
95
|
+
self.is_a?(Types::Bases::Self)
|
96
|
+
end
|
97
|
+
|
98
|
+
def has_classish_type?
|
99
|
+
self.is_a?(Bases::Instance) || self.is_a?(Bases::Class)
|
100
|
+
end
|
101
|
+
|
102
|
+
def with_nonreturn_void?
|
103
|
+
self.is_a?(Bases::Void)
|
104
|
+
end
|
93
105
|
end
|
94
106
|
|
95
107
|
class Bool < Base; end
|
96
108
|
class Void < Base; end
|
97
|
-
class Any < Base
|
109
|
+
class Any < Base
|
110
|
+
def to_s(level=0)
|
111
|
+
@string || "untyped"
|
112
|
+
end
|
113
|
+
|
114
|
+
def todo!
|
115
|
+
@string = '__todo__'
|
116
|
+
self
|
117
|
+
end
|
118
|
+
end
|
98
119
|
class Nil < Base; end
|
99
120
|
class Top < Base; end
|
100
121
|
class Bottom < Base; end
|
@@ -162,6 +183,18 @@ module RBS
|
|
162
183
|
end
|
163
184
|
|
164
185
|
include EmptyEachType
|
186
|
+
|
187
|
+
def has_self_type?
|
188
|
+
false
|
189
|
+
end
|
190
|
+
|
191
|
+
def has_classish_type?
|
192
|
+
false
|
193
|
+
end
|
194
|
+
|
195
|
+
def with_nonreturn_void?
|
196
|
+
false
|
197
|
+
end
|
165
198
|
end
|
166
199
|
|
167
200
|
class ClassSingleton
|
@@ -202,6 +235,18 @@ module RBS
|
|
202
235
|
location: location
|
203
236
|
)
|
204
237
|
end
|
238
|
+
|
239
|
+
def has_self_type?
|
240
|
+
false
|
241
|
+
end
|
242
|
+
|
243
|
+
def has_classish_type?
|
244
|
+
false
|
245
|
+
end
|
246
|
+
|
247
|
+
def with_nonreturn_void?
|
248
|
+
false
|
249
|
+
end
|
205
250
|
end
|
206
251
|
|
207
252
|
module Application
|
@@ -241,6 +286,25 @@ module RBS
|
|
241
286
|
enum_for :each_type
|
242
287
|
end
|
243
288
|
end
|
289
|
+
|
290
|
+
def has_self_type?
|
291
|
+
each_type.any? {|type| type.has_self_type? }
|
292
|
+
end
|
293
|
+
|
294
|
+
def has_classish_type?
|
295
|
+
each_type.any? {|type| type.has_classish_type? }
|
296
|
+
end
|
297
|
+
|
298
|
+
def with_nonreturn_void?
|
299
|
+
each_type.any? do |type|
|
300
|
+
if type.is_a?(Bases::Void)
|
301
|
+
# `void` in immediate generics parameter is allowed
|
302
|
+
false
|
303
|
+
else
|
304
|
+
type.with_nonreturn_void?
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|
244
308
|
end
|
245
309
|
|
246
310
|
class Interface
|
@@ -436,6 +500,18 @@ module RBS
|
|
436
500
|
enum_for :map_type
|
437
501
|
end
|
438
502
|
end
|
503
|
+
|
504
|
+
def has_self_type?
|
505
|
+
each_type.any? {|type| type.has_self_type? }
|
506
|
+
end
|
507
|
+
|
508
|
+
def has_classish_type?
|
509
|
+
each_type.any? {|type| type.has_classish_type? }
|
510
|
+
end
|
511
|
+
|
512
|
+
def with_nonreturn_void?
|
513
|
+
each_type.any? {|type| type.with_nonreturn_void? }
|
514
|
+
end
|
439
515
|
end
|
440
516
|
|
441
517
|
class Record
|
@@ -478,7 +554,7 @@ module RBS
|
|
478
554
|
return "{ }" if self.fields.empty?
|
479
555
|
|
480
556
|
fields = self.fields.map do |key, type|
|
481
|
-
if key.is_a?(Symbol) && key.match?(/\A[A-Za-z_][A-Za-
|
557
|
+
if key.is_a?(Symbol) && key.match?(/\A[A-Za-z_][A-Za-z_0-9]*\z/)
|
482
558
|
"#{key}: #{type}"
|
483
559
|
else
|
484
560
|
"#{key.inspect} => #{type}"
|
@@ -512,6 +588,18 @@ module RBS
|
|
512
588
|
enum_for :map_type
|
513
589
|
end
|
514
590
|
end
|
591
|
+
|
592
|
+
def has_self_type?
|
593
|
+
each_type.any? {|type| type.has_self_type? }
|
594
|
+
end
|
595
|
+
|
596
|
+
def has_classish_type?
|
597
|
+
each_type.any? {|type| type.has_classish_type? }
|
598
|
+
end
|
599
|
+
|
600
|
+
def with_nonreturn_void?
|
601
|
+
each_type.any? {|type| type.with_nonreturn_void? }
|
602
|
+
end
|
515
603
|
end
|
516
604
|
|
517
605
|
class Optional
|
@@ -552,6 +640,8 @@ module RBS
|
|
552
640
|
when Symbol
|
553
641
|
return "#{type.to_s(1)} ?"
|
554
642
|
end
|
643
|
+
when RBS::Types::Proc
|
644
|
+
return "(#{type.to_s(1)})?"
|
555
645
|
end
|
556
646
|
|
557
647
|
"#{type.to_s(1)}?"
|
@@ -582,6 +672,18 @@ module RBS
|
|
582
672
|
enum_for :map_type
|
583
673
|
end
|
584
674
|
end
|
675
|
+
|
676
|
+
def has_self_type?
|
677
|
+
each_type.any? {|type| type.has_self_type? }
|
678
|
+
end
|
679
|
+
|
680
|
+
def has_classish_type?
|
681
|
+
each_type.any? {|type| type.has_classish_type? }
|
682
|
+
end
|
683
|
+
|
684
|
+
def with_nonreturn_void?
|
685
|
+
each_type.any? {|type| type.with_nonreturn_void? }
|
686
|
+
end
|
585
687
|
end
|
586
688
|
|
587
689
|
class Union
|
@@ -650,6 +752,18 @@ module RBS
|
|
650
752
|
location: location
|
651
753
|
)
|
652
754
|
end
|
755
|
+
|
756
|
+
def has_self_type?
|
757
|
+
each_type.any? {|type| type.has_self_type? }
|
758
|
+
end
|
759
|
+
|
760
|
+
def has_classish_type?
|
761
|
+
each_type.any? {|type| type.has_classish_type? }
|
762
|
+
end
|
763
|
+
|
764
|
+
def with_nonreturn_void?
|
765
|
+
each_type.any? {|type| type.with_nonreturn_void? }
|
766
|
+
end
|
653
767
|
end
|
654
768
|
|
655
769
|
class Intersection
|
@@ -719,6 +833,18 @@ module RBS
|
|
719
833
|
location: location
|
720
834
|
)
|
721
835
|
end
|
836
|
+
|
837
|
+
def has_self_type?
|
838
|
+
each_type.any? {|type| type.has_self_type? }
|
839
|
+
end
|
840
|
+
|
841
|
+
def has_classish_type?
|
842
|
+
each_type.any? {|type| type.has_classish_type? }
|
843
|
+
end
|
844
|
+
|
845
|
+
def with_nonreturn_void?
|
846
|
+
each_type.any? {|type| type.with_nonreturn_void? }
|
847
|
+
end
|
722
848
|
end
|
723
849
|
|
724
850
|
class Function
|
@@ -1029,6 +1155,26 @@ module RBS
|
|
1029
1155
|
false
|
1030
1156
|
end
|
1031
1157
|
end
|
1158
|
+
|
1159
|
+
def has_self_type?
|
1160
|
+
each_type.any? {|type| type.has_self_type? }
|
1161
|
+
end
|
1162
|
+
|
1163
|
+
def has_classish_type?
|
1164
|
+
each_type.any? {|type| type.has_classish_type? }
|
1165
|
+
end
|
1166
|
+
|
1167
|
+
def with_nonreturn_void?
|
1168
|
+
if each_param.any? {|param| param.type.with_nonreturn_void? }
|
1169
|
+
true
|
1170
|
+
else
|
1171
|
+
if return_type.is_a?(Bases::Void)
|
1172
|
+
false
|
1173
|
+
else
|
1174
|
+
return_type.with_nonreturn_void?
|
1175
|
+
end
|
1176
|
+
end
|
1177
|
+
end
|
1032
1178
|
end
|
1033
1179
|
|
1034
1180
|
class Block
|
@@ -1155,6 +1301,9 @@ module RBS
|
|
1155
1301
|
if block
|
1156
1302
|
type.each_type(&block)
|
1157
1303
|
self.block&.type&.each_type(&block)
|
1304
|
+
if self_type = self.block&.self_type
|
1305
|
+
yield self_type
|
1306
|
+
end
|
1158
1307
|
else
|
1159
1308
|
enum_for :each_type
|
1160
1309
|
end
|
@@ -1181,6 +1330,26 @@ module RBS
|
|
1181
1330
|
enum_for :map_type
|
1182
1331
|
end
|
1183
1332
|
end
|
1333
|
+
|
1334
|
+
def has_self_type?
|
1335
|
+
each_type.any? {|type| type.has_self_type? }
|
1336
|
+
end
|
1337
|
+
|
1338
|
+
def has_classish_type?
|
1339
|
+
each_type.any? {|type| type.has_classish_type? }
|
1340
|
+
end
|
1341
|
+
|
1342
|
+
def with_nonreturn_void?
|
1343
|
+
if type.with_nonreturn_void?
|
1344
|
+
true
|
1345
|
+
else
|
1346
|
+
if block = block()
|
1347
|
+
block.type.with_nonreturn_void? || block.self_type&.with_nonreturn_void? || false
|
1348
|
+
else
|
1349
|
+
false
|
1350
|
+
end
|
1351
|
+
end
|
1352
|
+
end
|
1184
1353
|
end
|
1185
1354
|
|
1186
1355
|
class Literal
|
@@ -1214,6 +1383,18 @@ module RBS
|
|
1214
1383
|
def to_s(level = 0)
|
1215
1384
|
literal.inspect
|
1216
1385
|
end
|
1386
|
+
|
1387
|
+
def has_self_type?
|
1388
|
+
false
|
1389
|
+
end
|
1390
|
+
|
1391
|
+
def has_classish_type?
|
1392
|
+
false
|
1393
|
+
end
|
1394
|
+
|
1395
|
+
def with_nonreturn_void?
|
1396
|
+
false
|
1397
|
+
end
|
1217
1398
|
end
|
1218
1399
|
end
|
1219
1400
|
end
|
data/lib/rbs/version.rb
CHANGED
data/lib/rbs/writer.rb
CHANGED
@@ -107,7 +107,7 @@ module RBS
|
|
107
107
|
"#{clause.namespace}*"
|
108
108
|
end
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
111
|
puts "use #{clauses.join(", ")}"
|
112
112
|
end
|
113
113
|
|
@@ -264,8 +264,8 @@ module RBS
|
|
264
264
|
when AST::Members::Alias
|
265
265
|
write_comment member.comment
|
266
266
|
write_annotation member.annotations
|
267
|
-
new_name = member.singleton? ? "self.#{member.new_name}" : member.new_name
|
268
|
-
old_name = member.singleton? ? "self.#{member.old_name}" : member.old_name
|
267
|
+
new_name = member.singleton? ? "self.#{method_name(member.new_name)}" : method_name(member.new_name)
|
268
|
+
old_name = member.singleton? ? "self.#{method_name(member.old_name)}" : method_name(member.old_name)
|
269
269
|
puts "alias #{new_name} #{old_name}"
|
270
270
|
when AST::Members::InstanceVariable
|
271
271
|
write_comment member.comment
|
@@ -385,7 +385,7 @@ module RBS
|
|
385
385
|
""
|
386
386
|
end
|
387
387
|
|
388
|
-
"#{visibility}attr_#{kind} #{receiver}#{attr.name}#{var}: #{attr.type}"
|
388
|
+
"#{visibility}attr_#{kind} #{receiver}#{method_name(attr.name)}#{var}: #{attr.type}"
|
389
389
|
end
|
390
390
|
|
391
391
|
def preserve_empty_line(prev, decl)
|