steep 0.16.0 → 0.16.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +0 -3
- data/CHANGELOG.md +6 -0
- data/Rakefile +0 -13
- data/bin/setup +0 -2
- data/bin/smoke_runner.rb +0 -1
- data/exe/steep +0 -1
- data/lib/steep/project/file.rb +1 -1
- data/lib/steep/project/hover_content.rb +1 -1
- data/lib/steep/server/code_worker.rb +1 -1
- data/lib/steep/server/signature_worker.rb +4 -4
- data/lib/steep/type_construction.rb +10 -16
- data/lib/steep/type_inference/constant_env.rb +2 -10
- data/lib/steep/type_inference/context.rb +1 -0
- data/lib/steep/version.rb +1 -1
- data/steep.gemspec +1 -5
- metadata +17 -135
- data/exe/rbs +0 -3
- data/vendor/ruby-signature/.github/workflows/ruby.yml +0 -27
- data/vendor/ruby-signature/.gitignore +0 -12
- data/vendor/ruby-signature/.rubocop.yml +0 -15
- data/vendor/ruby-signature/BSDL +0 -22
- data/vendor/ruby-signature/COPYING +0 -56
- data/vendor/ruby-signature/Gemfile +0 -6
- data/vendor/ruby-signature/README.md +0 -93
- data/vendor/ruby-signature/Rakefile +0 -142
- data/vendor/ruby-signature/bin/annotate-with-rdoc +0 -157
- data/vendor/ruby-signature/bin/console +0 -14
- data/vendor/ruby-signature/bin/query-rdoc +0 -103
- data/vendor/ruby-signature/bin/setup +0 -10
- data/vendor/ruby-signature/bin/sort +0 -89
- data/vendor/ruby-signature/bin/test_runner.rb +0 -16
- data/vendor/ruby-signature/docs/CONTRIBUTING.md +0 -97
- data/vendor/ruby-signature/docs/sigs.md +0 -148
- data/vendor/ruby-signature/docs/stdlib.md +0 -152
- data/vendor/ruby-signature/docs/syntax.md +0 -528
- data/vendor/ruby-signature/exe/rbs +0 -7
- data/vendor/ruby-signature/lib/rbs.rb +0 -64
- data/vendor/ruby-signature/lib/rbs/ast/annotation.rb +0 -27
- data/vendor/ruby-signature/lib/rbs/ast/comment.rb +0 -27
- data/vendor/ruby-signature/lib/rbs/ast/declarations.rb +0 -395
- data/vendor/ruby-signature/lib/rbs/ast/members.rb +0 -362
- data/vendor/ruby-signature/lib/rbs/buffer.rb +0 -50
- data/vendor/ruby-signature/lib/rbs/builtin_names.rb +0 -55
- data/vendor/ruby-signature/lib/rbs/cli.rb +0 -558
- data/vendor/ruby-signature/lib/rbs/constant.rb +0 -26
- data/vendor/ruby-signature/lib/rbs/constant_table.rb +0 -150
- data/vendor/ruby-signature/lib/rbs/definition.rb +0 -170
- data/vendor/ruby-signature/lib/rbs/definition_builder.rb +0 -919
- data/vendor/ruby-signature/lib/rbs/environment.rb +0 -281
- data/vendor/ruby-signature/lib/rbs/environment_loader.rb +0 -136
- data/vendor/ruby-signature/lib/rbs/environment_walker.rb +0 -124
- data/vendor/ruby-signature/lib/rbs/errors.rb +0 -187
- data/vendor/ruby-signature/lib/rbs/location.rb +0 -102
- data/vendor/ruby-signature/lib/rbs/method_type.rb +0 -123
- data/vendor/ruby-signature/lib/rbs/namespace.rb +0 -91
- data/vendor/ruby-signature/lib/rbs/parser.y +0 -1344
- data/vendor/ruby-signature/lib/rbs/prototype/rb.rb +0 -553
- data/vendor/ruby-signature/lib/rbs/prototype/rbi.rb +0 -587
- data/vendor/ruby-signature/lib/rbs/prototype/runtime.rb +0 -381
- data/vendor/ruby-signature/lib/rbs/substitution.rb +0 -46
- data/vendor/ruby-signature/lib/rbs/test.rb +0 -26
- data/vendor/ruby-signature/lib/rbs/test/errors.rb +0 -61
- data/vendor/ruby-signature/lib/rbs/test/hook.rb +0 -294
- data/vendor/ruby-signature/lib/rbs/test/setup.rb +0 -58
- data/vendor/ruby-signature/lib/rbs/test/spy.rb +0 -325
- data/vendor/ruby-signature/lib/rbs/test/test_helper.rb +0 -183
- data/vendor/ruby-signature/lib/rbs/test/type_check.rb +0 -254
- data/vendor/ruby-signature/lib/rbs/type_name.rb +0 -70
- data/vendor/ruby-signature/lib/rbs/types.rb +0 -936
- data/vendor/ruby-signature/lib/rbs/variance_calculator.rb +0 -138
- data/vendor/ruby-signature/lib/rbs/vendorer.rb +0 -47
- data/vendor/ruby-signature/lib/rbs/version.rb +0 -3
- data/vendor/ruby-signature/lib/rbs/writer.rb +0 -269
- data/vendor/ruby-signature/lib/ruby/signature.rb +0 -7
- data/vendor/ruby-signature/rbs.gemspec +0 -46
- data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -60
- data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -71
- data/vendor/ruby-signature/stdlib/benchmark/benchmark.rbs +0 -372
- data/vendor/ruby-signature/stdlib/builtin/array.rbs +0 -1997
- data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +0 -280
- data/vendor/ruby-signature/stdlib/builtin/binding.rbs +0 -177
- data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +0 -45
- data/vendor/ruby-signature/stdlib/builtin/class.rbs +0 -145
- data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +0 -116
- data/vendor/ruby-signature/stdlib/builtin/complex.rbs +0 -400
- data/vendor/ruby-signature/stdlib/builtin/constants.rbs +0 -37
- data/vendor/ruby-signature/stdlib/builtin/data.rbs +0 -5
- data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +0 -2
- data/vendor/ruby-signature/stdlib/builtin/dir.rbs +0 -413
- data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -607
- data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +0 -404
- data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +0 -260
- data/vendor/ruby-signature/stdlib/builtin/errno.rbs +0 -781
- data/vendor/ruby-signature/stdlib/builtin/errors.rbs +0 -582
- data/vendor/ruby-signature/stdlib/builtin/exception.rbs +0 -194
- data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +0 -40
- data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +0 -68
- data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +0 -12
- data/vendor/ruby-signature/stdlib/builtin/file.rbs +0 -1076
- data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +0 -59
- data/vendor/ruby-signature/stdlib/builtin/float.rbs +0 -696
- data/vendor/ruby-signature/stdlib/builtin/gc.rbs +0 -243
- data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
- data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -707
- data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
- data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -576
- data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -161
- data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -271
- data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -369
- data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -185
- data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -1104
- data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +0 -82
- data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +0 -409
- data/vendor/ruby-signature/stdlib/builtin/object.rbs +0 -824
- data/vendor/ruby-signature/stdlib/builtin/proc.rbs +0 -429
- data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -1227
- data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -267
- data/vendor/ruby-signature/stdlib/builtin/range.rbs +0 -226
- data/vendor/ruby-signature/stdlib/builtin/rational.rbs +0 -424
- data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +0 -57
- data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +0 -1083
- data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +0 -14
- data/vendor/ruby-signature/stdlib/builtin/signal.rbs +0 -55
- data/vendor/ruby-signature/stdlib/builtin/string.rbs +0 -1901
- data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -284
- data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
- data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -228
- data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1108
- data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
- data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -1047
- data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -290
- data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
- data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -153
- data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
- data/vendor/ruby-signature/stdlib/coverage/coverage.rbs +0 -62
- data/vendor/ruby-signature/stdlib/csv/csv.rbs +0 -773
- data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -392
- data/vendor/ruby-signature/stdlib/find/find.rbs +0 -40
- data/vendor/ruby-signature/stdlib/ipaddr/ipaddr.rbs +0 -247
- data/vendor/ruby-signature/stdlib/json/json.rbs +0 -335
- data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -1093
- data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +0 -23
- data/vendor/ruby-signature/stdlib/prime/prime.rbs +0 -188
- data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +0 -9
- data/vendor/ruby-signature/stdlib/set/set.rbs +0 -301
- data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +0 -53
@@ -1,183 +0,0 @@
|
|
1
|
-
module RBS
|
2
|
-
module Test
|
3
|
-
module TypeAssertions
|
4
|
-
module ClassMethods
|
5
|
-
attr_reader :target
|
6
|
-
|
7
|
-
def library(*libs)
|
8
|
-
@libs = libs
|
9
|
-
@env = nil
|
10
|
-
@target = nil
|
11
|
-
end
|
12
|
-
|
13
|
-
def env
|
14
|
-
@env ||= begin
|
15
|
-
loader = RBS::EnvironmentLoader.new
|
16
|
-
(@libs || []).each do |lib|
|
17
|
-
loader.add library: lib
|
18
|
-
end
|
19
|
-
|
20
|
-
RBS::Environment.new.tap do |env|
|
21
|
-
loader.load(env: env)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def builder
|
27
|
-
@builder ||= DefinitionBuilder.new(env: env)
|
28
|
-
end
|
29
|
-
|
30
|
-
def testing(type_or_string)
|
31
|
-
type = case type_or_string
|
32
|
-
when String
|
33
|
-
RBS::Parser.parse_type(type_or_string, variables: [])
|
34
|
-
else
|
35
|
-
type_or_string
|
36
|
-
end
|
37
|
-
|
38
|
-
definition = case type
|
39
|
-
when Types::ClassInstance
|
40
|
-
builder.build_instance(type.name)
|
41
|
-
when Types::ClassSingleton
|
42
|
-
builder.build_singleton(type.name)
|
43
|
-
else
|
44
|
-
raise "Test target should be class instance or class singleton: #{type}"
|
45
|
-
end
|
46
|
-
|
47
|
-
@target = [type, definition]
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
def self.included(base)
|
52
|
-
base.extend ClassMethods
|
53
|
-
end
|
54
|
-
|
55
|
-
def env
|
56
|
-
self.class.env
|
57
|
-
end
|
58
|
-
|
59
|
-
def builder
|
60
|
-
self.class.builder
|
61
|
-
end
|
62
|
-
|
63
|
-
def targets
|
64
|
-
@targets ||= []
|
65
|
-
end
|
66
|
-
|
67
|
-
def target
|
68
|
-
targets.last || self.class.target
|
69
|
-
end
|
70
|
-
|
71
|
-
def testing(type_or_string)
|
72
|
-
type = case type_or_string
|
73
|
-
when String
|
74
|
-
RBS::Parser.parse_type(type_or_string, variables: [])
|
75
|
-
else
|
76
|
-
type_or_string
|
77
|
-
end
|
78
|
-
|
79
|
-
definition = case type
|
80
|
-
when Types::ClassInstance
|
81
|
-
builder.build_instance(type.name)
|
82
|
-
when Types::ClassSingleton
|
83
|
-
builder.build_singleton(type.name)
|
84
|
-
else
|
85
|
-
raise "Test target should be class instance or class singleton: #{type}"
|
86
|
-
end
|
87
|
-
|
88
|
-
targets.push [type, definition]
|
89
|
-
|
90
|
-
if block_given?
|
91
|
-
begin
|
92
|
-
yield
|
93
|
-
ensure
|
94
|
-
targets.pop
|
95
|
-
end
|
96
|
-
else
|
97
|
-
[type, definition]
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
ruby2_keywords def assert_send_type(method_type, receiver, method, *args, &block)
|
102
|
-
trace = []
|
103
|
-
spy = Spy.wrap(receiver, method)
|
104
|
-
spy.callback = -> (result) { trace << result }
|
105
|
-
|
106
|
-
exception = nil
|
107
|
-
|
108
|
-
begin
|
109
|
-
spy.wrapped_object.__send__(method, *args, &block)
|
110
|
-
rescue => exn
|
111
|
-
exception = exn
|
112
|
-
end
|
113
|
-
|
114
|
-
mt = case method_type
|
115
|
-
when String
|
116
|
-
RBS::Parser.parse_method_type(method_type, variables: [])
|
117
|
-
when RBS::MethodType
|
118
|
-
method_type
|
119
|
-
end
|
120
|
-
|
121
|
-
typecheck = TypeCheck.new(self_class: receiver.class, builder: builder)
|
122
|
-
errors = typecheck.method_call(method, mt, trace.last, errors: [])
|
123
|
-
|
124
|
-
assert_empty errors.map {|x| RBS::Test::Errors.to_string(x) }, "Call trace does not match with given method type: #{trace.last.inspect}"
|
125
|
-
|
126
|
-
type, definition = target
|
127
|
-
method_types = case
|
128
|
-
when definition.instance_type?
|
129
|
-
subst = Substitution.build(definition.declaration.type_params.each.map(&:name),
|
130
|
-
type.args)
|
131
|
-
definition.methods[method].method_types.map do |method_type|
|
132
|
-
method_type.sub(subst)
|
133
|
-
end
|
134
|
-
when definition.class_type?
|
135
|
-
definition.methods[method].method_types
|
136
|
-
end
|
137
|
-
|
138
|
-
all_errors = method_types.map {|t| typecheck.method_call(method, t, trace.last, errors: []) }
|
139
|
-
assert all_errors.any? {|es| es.empty? }, "Call trace does not match one of method definitions:\n #{trace.last.inspect}\n #{method_types.join(" | ")}"
|
140
|
-
|
141
|
-
if exception
|
142
|
-
raise exception
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
ruby2_keywords def refute_send_type(method_type, receiver, method, *args, &block)
|
147
|
-
trace = []
|
148
|
-
spy = Spy.wrap(receiver, method)
|
149
|
-
spy.callback = -> (result) { trace << result }
|
150
|
-
|
151
|
-
exception = nil
|
152
|
-
begin
|
153
|
-
spy.wrapped_object.__send__(method, *args, &block)
|
154
|
-
rescue Exception => exn
|
155
|
-
exception = exn
|
156
|
-
end
|
157
|
-
|
158
|
-
mt = case method_type
|
159
|
-
when String
|
160
|
-
RBS::Parser.parse_method_type(method_type, variables: [])
|
161
|
-
when RBS::MethodType
|
162
|
-
method_type
|
163
|
-
end
|
164
|
-
|
165
|
-
mt = mt.update(block: if mt.block
|
166
|
-
MethodType::Block.new(
|
167
|
-
type: mt.block.type.with_return_type(Types::Bases::Any.new(location: nil)),
|
168
|
-
required: mt.block.required
|
169
|
-
)
|
170
|
-
end,
|
171
|
-
type: mt.type.with_return_type(Types::Bases::Any.new(location: nil)))
|
172
|
-
|
173
|
-
typecheck = TypeCheck.new(self_class: receiver.class, builder: builder)
|
174
|
-
errors = typecheck.method_call(method, mt, trace.last, errors: [])
|
175
|
-
|
176
|
-
assert_operator exception, :is_a?, ::Exception
|
177
|
-
assert_empty errors.map {|x| RBS::Test::Errors.to_string(x) }
|
178
|
-
|
179
|
-
exception
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
@@ -1,254 +0,0 @@
|
|
1
|
-
module RBS
|
2
|
-
module Test
|
3
|
-
class TypeCheck
|
4
|
-
attr_reader :self_class
|
5
|
-
attr_reader :builder
|
6
|
-
|
7
|
-
def initialize(self_class:, builder:)
|
8
|
-
@self_class = self_class
|
9
|
-
@builder = builder
|
10
|
-
end
|
11
|
-
|
12
|
-
def method_call(method_name, method_type, call, errors:)
|
13
|
-
args(method_name, method_type, method_type.type, call.method_call, errors, type_error: Errors::ArgumentTypeError, argument_error: Errors::ArgumentError)
|
14
|
-
self.return(method_name, method_type, method_type.type, call.method_call, errors, return_error: Errors::ReturnTypeError)
|
15
|
-
|
16
|
-
if method_type.block
|
17
|
-
case
|
18
|
-
when !call.block_calls.empty?
|
19
|
-
call.block_calls.each do |block_call|
|
20
|
-
args(method_name, method_type, method_type.block.type, block_call, errors, type_error: Errors::BlockArgumentTypeError, argument_error: Errors::BlockArgumentError)
|
21
|
-
self.return(method_name, method_type, method_type.block.type, block_call, errors, return_error: Errors::BlockReturnTypeError)
|
22
|
-
end
|
23
|
-
when !call.block_given
|
24
|
-
# Block is not given
|
25
|
-
if method_type.block.required
|
26
|
-
errors << Errors::MissingBlockError.new(klass: self_class, method_name: method_name, method_type: method_type)
|
27
|
-
end
|
28
|
-
else
|
29
|
-
# Block is given, but not yielded
|
30
|
-
end
|
31
|
-
else
|
32
|
-
if call.block_given
|
33
|
-
errors << Errors::UnexpectedBlockError.new(klass: self_class, method_name: method_name, method_type: method_type)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
errors
|
38
|
-
end
|
39
|
-
|
40
|
-
def args(method_name, method_type, fun, call, errors, type_error:, argument_error:)
|
41
|
-
test = zip_args(call.arguments, fun) do |val, param|
|
42
|
-
unless self.value(val, param.type)
|
43
|
-
errors << type_error.new(klass: self_class,
|
44
|
-
method_name: method_name,
|
45
|
-
method_type: method_type,
|
46
|
-
param: param,
|
47
|
-
value: val)
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
unless test
|
52
|
-
errors << argument_error.new(klass: self_class,
|
53
|
-
method_name: method_name,
|
54
|
-
method_type: method_type)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def return(method_name, method_type, fun, call, errors, return_error:)
|
59
|
-
unless call.exception
|
60
|
-
unless value(call.return_value, fun.return_type)
|
61
|
-
errors << return_error.new(klass: self_class,
|
62
|
-
method_name: method_name,
|
63
|
-
method_type: method_type,
|
64
|
-
type: fun.return_type,
|
65
|
-
value: call.return_value)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
def zip_keyword_args(hash, fun)
|
71
|
-
fun.required_keywords.each do |name, param|
|
72
|
-
if hash.key?(name)
|
73
|
-
yield(hash[name], param)
|
74
|
-
else
|
75
|
-
return false
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
fun.optional_keywords.each do |name, param|
|
80
|
-
if hash.key?(name)
|
81
|
-
yield(hash[name], param)
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
hash.each do |name, value|
|
86
|
-
next if fun.required_keywords.key?(name)
|
87
|
-
next if fun.optional_keywords.key?(name)
|
88
|
-
|
89
|
-
if fun.rest_keywords
|
90
|
-
yield value, fun.rest_keywords
|
91
|
-
else
|
92
|
-
return false
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
true
|
97
|
-
end
|
98
|
-
|
99
|
-
def keyword?(value)
|
100
|
-
value.is_a?(Hash) && value.keys.all? {|key| key.is_a?(Symbol) }
|
101
|
-
end
|
102
|
-
|
103
|
-
def zip_args(args, fun, &block)
|
104
|
-
case
|
105
|
-
when args.empty?
|
106
|
-
if fun.required_positionals.empty? && fun.trailing_positionals.empty? && fun.required_keywords.empty?
|
107
|
-
true
|
108
|
-
else
|
109
|
-
false
|
110
|
-
end
|
111
|
-
when !fun.required_positionals.empty?
|
112
|
-
yield_self do
|
113
|
-
param, fun_ = fun.drop_head
|
114
|
-
yield(args.first, param)
|
115
|
-
zip_args(args.drop(1), fun_, &block)
|
116
|
-
end
|
117
|
-
when fun.has_keyword?
|
118
|
-
yield_self do
|
119
|
-
hash = args.last
|
120
|
-
if keyword?(hash)
|
121
|
-
zip_keyword_args(hash, fun, &block) &&
|
122
|
-
zip_args(args.take(args.size - 1),
|
123
|
-
fun.update(required_keywords: {}, optional_keywords: {}, rest_keywords: nil),
|
124
|
-
&block)
|
125
|
-
else
|
126
|
-
fun.required_keywords.empty? &&
|
127
|
-
zip_args(args,
|
128
|
-
fun.update(required_keywords: {}, optional_keywords: {}, rest_keywords: nil),
|
129
|
-
&block)
|
130
|
-
end
|
131
|
-
end
|
132
|
-
when !fun.trailing_positionals.empty?
|
133
|
-
yield_self do
|
134
|
-
param, fun_ = fun.drop_tail
|
135
|
-
yield(args.last, param)
|
136
|
-
zip_args(args.take(args.size - 1), fun_, &block)
|
137
|
-
end
|
138
|
-
when !fun.optional_positionals.empty?
|
139
|
-
yield_self do
|
140
|
-
param, fun_ = fun.drop_head
|
141
|
-
yield(args.first, param)
|
142
|
-
zip_args(args.drop(1), fun_, &block)
|
143
|
-
end
|
144
|
-
when fun.rest_positionals
|
145
|
-
yield_self do
|
146
|
-
yield(args.first, fun.rest_positionals)
|
147
|
-
zip_args(args.drop(1), fun, &block)
|
148
|
-
end
|
149
|
-
else
|
150
|
-
false
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
def value(val, type)
|
155
|
-
case type
|
156
|
-
when Types::Bases::Any
|
157
|
-
true
|
158
|
-
when Types::Bases::Bool
|
159
|
-
true
|
160
|
-
when Types::Bases::Top
|
161
|
-
true
|
162
|
-
when Types::Bases::Bottom
|
163
|
-
false
|
164
|
-
when Types::Bases::Void
|
165
|
-
true
|
166
|
-
when Types::Bases::Self
|
167
|
-
Test.call(val, IS_AP, self_class)
|
168
|
-
when Types::Bases::Nil
|
169
|
-
Test.call(val, IS_AP, ::NilClass)
|
170
|
-
when Types::Bases::Class
|
171
|
-
Test.call(val, IS_AP, Class)
|
172
|
-
when Types::Bases::Instance
|
173
|
-
Test.call(val, IS_AP, self_class)
|
174
|
-
when Types::ClassInstance
|
175
|
-
klass = Object.const_get(type.name.to_s)
|
176
|
-
case
|
177
|
-
when klass == ::Array
|
178
|
-
Test.call(val, IS_AP, klass) && val.all? {|v| value(v, type.args[0]) }
|
179
|
-
when klass == ::Hash
|
180
|
-
Test.call(val, IS_AP, klass) && val.all? {|k, v| value(k, type.args[0]) && value(v, type.args[1]) }
|
181
|
-
when klass == ::Range
|
182
|
-
Test.call(val, IS_AP, klass) && value(val.begin, type.args[0]) && value(val.end, type.args[0])
|
183
|
-
when klass == ::Enumerator
|
184
|
-
if Test.call(val, IS_AP, klass)
|
185
|
-
case val.size
|
186
|
-
when Float::INFINITY
|
187
|
-
values = []
|
188
|
-
ret = self
|
189
|
-
val.lazy.take(10).each do |*args|
|
190
|
-
values << args
|
191
|
-
nil
|
192
|
-
end
|
193
|
-
else
|
194
|
-
values = []
|
195
|
-
ret = val.each do |*args|
|
196
|
-
values << args
|
197
|
-
nil
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
values.all? do |v|
|
202
|
-
if v.size == 1
|
203
|
-
# Only one block argument.
|
204
|
-
value(v[0], type.args[0]) || value(v, type.args[0])
|
205
|
-
else
|
206
|
-
value(v, type.args[0])
|
207
|
-
end
|
208
|
-
end &&
|
209
|
-
if ret.equal?(self)
|
210
|
-
type.args[1].is_a?(Types::Bases::Bottom)
|
211
|
-
else
|
212
|
-
value(ret, type.args[1])
|
213
|
-
end
|
214
|
-
end
|
215
|
-
else
|
216
|
-
Test.call(val, IS_AP, klass)
|
217
|
-
end
|
218
|
-
when Types::ClassSingleton
|
219
|
-
klass = Object.const_get(type.name.to_s)
|
220
|
-
val == klass
|
221
|
-
when Types::Interface
|
222
|
-
methods = Set.new(Test.call(val, METHODS))
|
223
|
-
decl = builder.env.find_class(type.name)
|
224
|
-
if (definition = builder.build_interface(type.name, decl))
|
225
|
-
definition.methods.each_key.all? do |method_name|
|
226
|
-
methods.member?(method_name)
|
227
|
-
end
|
228
|
-
end
|
229
|
-
when Types::Variable
|
230
|
-
true
|
231
|
-
when Types::Literal
|
232
|
-
val == type.literal
|
233
|
-
when Types::Union
|
234
|
-
type.types.any? {|type| value(val, type) }
|
235
|
-
when Types::Intersection
|
236
|
-
type.types.all? {|type| value(val, type) }
|
237
|
-
when Types::Optional
|
238
|
-
Test.call(val, IS_AP, ::NilClass) || value(val, type.type)
|
239
|
-
when Types::Alias
|
240
|
-
value(val, builder.expand_alias(type.name))
|
241
|
-
when Types::Tuple
|
242
|
-
Test.call(val, IS_AP, ::Array) &&
|
243
|
-
type.types.map.with_index {|ty, index| value(val[index], ty) }.all?
|
244
|
-
when Types::Record
|
245
|
-
Test::call(val, IS_AP, ::Hash)
|
246
|
-
when Types::Proc
|
247
|
-
Test::call(val, IS_AP, ::Proc)
|
248
|
-
else
|
249
|
-
false
|
250
|
-
end
|
251
|
-
end
|
252
|
-
end
|
253
|
-
end
|
254
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
module RBS
|
2
|
-
class TypeName
|
3
|
-
attr_reader :namespace
|
4
|
-
attr_reader :name
|
5
|
-
attr_reader :kind
|
6
|
-
|
7
|
-
def initialize(namespace:, name:)
|
8
|
-
@namespace = namespace
|
9
|
-
@name = name
|
10
|
-
@kind = case name.to_s[0,1]
|
11
|
-
when /[A-Z]/
|
12
|
-
:class
|
13
|
-
when /[a-z]/
|
14
|
-
:alias
|
15
|
-
when "_"
|
16
|
-
:interface
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def ==(other)
|
21
|
-
other.is_a?(self.class) && other.namespace == namespace && other.name == name
|
22
|
-
end
|
23
|
-
|
24
|
-
alias eql? ==
|
25
|
-
|
26
|
-
def hash
|
27
|
-
self.class.hash ^ namespace.hash ^ name.hash
|
28
|
-
end
|
29
|
-
|
30
|
-
def to_s
|
31
|
-
"#{namespace.to_s}#{name}"
|
32
|
-
end
|
33
|
-
|
34
|
-
def to_json(*a)
|
35
|
-
to_s.to_json(*a)
|
36
|
-
end
|
37
|
-
|
38
|
-
def to_namespace
|
39
|
-
namespace.append(self.name)
|
40
|
-
end
|
41
|
-
|
42
|
-
def class?
|
43
|
-
kind == :class
|
44
|
-
end
|
45
|
-
|
46
|
-
def alias?
|
47
|
-
kind == :alias
|
48
|
-
end
|
49
|
-
|
50
|
-
def absolute!
|
51
|
-
self.class.new(namespace: namespace.absolute!, name: name)
|
52
|
-
end
|
53
|
-
|
54
|
-
def absolute?
|
55
|
-
namespace.absolute?
|
56
|
-
end
|
57
|
-
|
58
|
-
def relative!
|
59
|
-
self.class.new(namespace: namespace.relative!, name: name)
|
60
|
-
end
|
61
|
-
|
62
|
-
def interface?
|
63
|
-
kind == :interface
|
64
|
-
end
|
65
|
-
|
66
|
-
def with_prefix(namespace)
|
67
|
-
self.class.new(namespace: namespace + self.namespace, name: name)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|