steep 0.13.0 → 0.16.2
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 +28 -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.rb +33 -1
- data/lib/steep/annotation_parser.rb +4 -4
- data/lib/steep/ast/buffer.rb +11 -7
- data/lib/steep/ast/builtin.rb +8 -0
- data/lib/steep/ast/types/factory.rb +124 -89
- data/lib/steep/cli.rb +16 -1
- data/lib/steep/drivers/annotations.rb +1 -1
- data/lib/steep/drivers/check.rb +20 -4
- data/lib/steep/drivers/init.rb +5 -5
- data/lib/steep/drivers/langserver.rb +13 -287
- data/lib/steep/drivers/utils/driver_helper.rb +1 -1
- data/lib/steep/drivers/vendor.rb +2 -2
- data/lib/steep/drivers/watch.rb +97 -85
- data/lib/steep/drivers/worker.rb +51 -0
- data/lib/steep/project.rb +9 -5
- data/lib/steep/project/completion_provider.rb +298 -0
- data/lib/steep/project/dsl.rb +14 -0
- data/lib/steep/project/file.rb +54 -47
- data/lib/steep/project/hover_content.rb +17 -8
- data/lib/steep/project/options.rb +25 -3
- data/lib/steep/project/target.rb +40 -24
- data/lib/steep/server/base_worker.rb +56 -0
- data/lib/steep/server/code_worker.rb +151 -0
- data/lib/steep/server/interaction_worker.rb +281 -0
- data/lib/steep/server/master.rb +196 -0
- data/lib/steep/server/signature_worker.rb +148 -0
- data/lib/steep/server/utils.rb +36 -0
- data/lib/steep/server/worker_process.rb +62 -0
- data/lib/steep/signature/errors.rb +1 -1
- data/lib/steep/signature/validator.rb +13 -13
- data/lib/steep/source.rb +1 -1
- data/lib/steep/type_construction.rb +1004 -727
- data/lib/steep/type_inference/constant_env.rb +3 -11
- data/lib/steep/type_inference/context.rb +8 -3
- data/lib/steep/type_inference/context_array.rb +111 -0
- data/lib/steep/type_inference/local_variable_type_env.rb +226 -0
- data/lib/steep/type_inference/logic.rb +130 -0
- data/lib/steep/type_inference/type_env.rb +5 -69
- data/lib/steep/typing.rb +91 -23
- data/lib/steep/version.rb +1 -1
- data/smoke/alias/Steepfile +1 -0
- data/smoke/alias/a.rb +1 -1
- data/smoke/and/Steepfile +1 -0
- data/smoke/array/Steepfile +1 -0
- data/smoke/array/b.rb +0 -2
- data/smoke/block/Steepfile +1 -0
- data/smoke/case/Steepfile +1 -0
- data/smoke/class/Steepfile +1 -0
- data/smoke/const/Steepfile +1 -0
- data/smoke/dstr/Steepfile +1 -0
- data/smoke/ensure/Steepfile +1 -0
- data/smoke/enumerator/Steepfile +1 -0
- data/smoke/extension/Steepfile +1 -0
- data/smoke/extension/c.rb +1 -0
- data/smoke/hash/Steepfile +1 -0
- data/smoke/hello/Steepfile +1 -0
- data/smoke/if/Steepfile +1 -0
- data/smoke/if/a.rb +1 -1
- data/smoke/implements/Steepfile +1 -0
- data/smoke/initialize/Steepfile +1 -0
- data/smoke/integer/Steepfile +1 -0
- data/smoke/interface/Steepfile +1 -0
- data/smoke/kwbegin/Steepfile +1 -0
- data/smoke/lambda/Steepfile +1 -0
- data/smoke/literal/Steepfile +1 -0
- data/smoke/map/Steepfile +1 -0
- data/smoke/method/Steepfile +1 -0
- data/smoke/module/Steepfile +1 -0
- data/smoke/regexp/Steepfile +1 -0
- data/smoke/regexp/b.rb +4 -4
- data/smoke/regression/Steepfile +1 -0
- data/smoke/rescue/Steepfile +1 -0
- data/smoke/rescue/a.rb +1 -1
- data/smoke/self/Steepfile +1 -0
- data/smoke/skip/Steepfile +1 -0
- data/smoke/stdout/Steepfile +1 -0
- data/smoke/super/Steepfile +1 -0
- data/smoke/type_case/Steepfile +1 -0
- data/smoke/yield/Steepfile +1 -0
- data/steep.gemspec +8 -8
- metadata +38 -138
- data/exe/rbs +0 -3
- data/exe/ruby-signature +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 -66
- data/vendor/ruby-signature/bin/annotate-with-rdoc +0 -156
- 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 -88
- data/vendor/ruby-signature/bin/test_runner.rb +0 -17
- 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 -3
- data/vendor/ruby-signature/exe/ruby-signature +0 -7
- data/vendor/ruby-signature/lib/ruby/signature.rb +0 -64
- data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +0 -29
- data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +0 -29
- data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +0 -391
- data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +0 -364
- data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +0 -52
- data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +0 -54
- data/vendor/ruby-signature/lib/ruby/signature/cli.rb +0 -534
- data/vendor/ruby-signature/lib/ruby/signature/constant.rb +0 -28
- data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +0 -152
- data/vendor/ruby-signature/lib/ruby/signature/definition.rb +0 -172
- data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +0 -921
- data/vendor/ruby-signature/lib/ruby/signature/environment.rb +0 -283
- data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +0 -138
- data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +0 -126
- data/vendor/ruby-signature/lib/ruby/signature/errors.rb +0 -189
- data/vendor/ruby-signature/lib/ruby/signature/location.rb +0 -104
- data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +0 -125
- data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +0 -93
- data/vendor/ruby-signature/lib/ruby/signature/parser.y +0 -1343
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +0 -441
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +0 -579
- data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +0 -383
- data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +0 -48
- data/vendor/ruby-signature/lib/ruby/signature/test.rb +0 -28
- data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +0 -63
- data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +0 -290
- data/vendor/ruby-signature/lib/ruby/signature/test/setup.rb +0 -58
- data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +0 -324
- data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +0 -185
- data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +0 -256
- data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +0 -72
- data/vendor/ruby-signature/lib/ruby/signature/types.rb +0 -932
- data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +0 -140
- data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +0 -49
- data/vendor/ruby-signature/lib/ruby/signature/version.rb +0 -5
- data/vendor/ruby-signature/lib/ruby/signature/writer.rb +0 -271
- data/vendor/ruby-signature/ruby-signature.gemspec +0 -45
- data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -3
- data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -15
- 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 -35
- 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 -419
- data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -606
- 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 -193
- 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 -476
- 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 -121
- data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
- data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -710
- data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
- data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -574
- data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -135
- data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -141
- data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -66
- data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -182
- data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -248
- 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 -426
- data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -354
- data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -93
- 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 -10
- data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +0 -131
- 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 -770
- data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -13
- data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
- data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -230
- data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1112
- data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
- data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -739
- data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -91
- data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
- data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -159
- data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
- data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -18
- data/vendor/ruby-signature/stdlib/find/find.rbs +0 -44
- data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -21
- 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 -77
- data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +0 -53
@@ -1,185 +0,0 @@
|
|
1
|
-
module Ruby
|
2
|
-
module Signature
|
3
|
-
module Test
|
4
|
-
module TypeAssertions
|
5
|
-
module ClassMethods
|
6
|
-
attr_reader :target
|
7
|
-
|
8
|
-
def library(*libs)
|
9
|
-
@libs = libs
|
10
|
-
@env = nil
|
11
|
-
@target = nil
|
12
|
-
end
|
13
|
-
|
14
|
-
def env
|
15
|
-
@env ||= begin
|
16
|
-
loader = Ruby::Signature::EnvironmentLoader.new
|
17
|
-
(@libs || []).each do |lib|
|
18
|
-
loader.add library: lib
|
19
|
-
end
|
20
|
-
|
21
|
-
Ruby::Signature::Environment.new.tap do |env|
|
22
|
-
loader.load(env: env)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def builder
|
28
|
-
@builder ||= DefinitionBuilder.new(env: env)
|
29
|
-
end
|
30
|
-
|
31
|
-
def testing(type_or_string)
|
32
|
-
type = case type_or_string
|
33
|
-
when String
|
34
|
-
Ruby::Signature::Parser.parse_type(type_or_string, variables: [])
|
35
|
-
else
|
36
|
-
type_or_string
|
37
|
-
end
|
38
|
-
|
39
|
-
definition = case type
|
40
|
-
when Types::ClassInstance
|
41
|
-
builder.build_instance(type.name)
|
42
|
-
when Types::ClassSingleton
|
43
|
-
builder.build_singleton(type.name)
|
44
|
-
else
|
45
|
-
raise "Test target should be class instance or class singleton: #{type}"
|
46
|
-
end
|
47
|
-
|
48
|
-
@target = [type, definition]
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
def self.included(base)
|
53
|
-
base.extend ClassMethods
|
54
|
-
end
|
55
|
-
|
56
|
-
def env
|
57
|
-
self.class.env
|
58
|
-
end
|
59
|
-
|
60
|
-
def builder
|
61
|
-
self.class.builder
|
62
|
-
end
|
63
|
-
|
64
|
-
def targets
|
65
|
-
@targets ||= []
|
66
|
-
end
|
67
|
-
|
68
|
-
def target
|
69
|
-
targets.last || self.class.target
|
70
|
-
end
|
71
|
-
|
72
|
-
def testing(type_or_string)
|
73
|
-
type = case type_or_string
|
74
|
-
when String
|
75
|
-
Ruby::Signature::Parser.parse_type(type_or_string, variables: [])
|
76
|
-
else
|
77
|
-
type_or_string
|
78
|
-
end
|
79
|
-
|
80
|
-
definition = case type
|
81
|
-
when Types::ClassInstance
|
82
|
-
builder.build_instance(type.name)
|
83
|
-
when Types::ClassSingleton
|
84
|
-
builder.build_singleton(type.name)
|
85
|
-
else
|
86
|
-
raise "Test target should be class instance or class singleton: #{type}"
|
87
|
-
end
|
88
|
-
|
89
|
-
targets.push [type, definition]
|
90
|
-
|
91
|
-
if block_given?
|
92
|
-
begin
|
93
|
-
yield
|
94
|
-
ensure
|
95
|
-
targets.pop
|
96
|
-
end
|
97
|
-
else
|
98
|
-
[type, definition]
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
ruby2_keywords def assert_send_type(method_type, receiver, method, *args, &block)
|
103
|
-
trace = []
|
104
|
-
spy = Spy.wrap(receiver, method)
|
105
|
-
spy.callback = -> (result) { trace << result }
|
106
|
-
|
107
|
-
exception = nil
|
108
|
-
|
109
|
-
begin
|
110
|
-
spy.wrapped_object.__send__(method, *args, &block)
|
111
|
-
rescue => exn
|
112
|
-
exception = exn
|
113
|
-
end
|
114
|
-
|
115
|
-
mt = case method_type
|
116
|
-
when String
|
117
|
-
Ruby::Signature::Parser.parse_method_type(method_type, variables: [])
|
118
|
-
when Ruby::Signature::MethodType
|
119
|
-
method_type
|
120
|
-
end
|
121
|
-
|
122
|
-
typecheck = TypeCheck.new(self_class: receiver.class, builder: builder)
|
123
|
-
errors = typecheck.method_call(method, mt, trace.last, errors: [])
|
124
|
-
|
125
|
-
assert_empty errors.map {|x| Ruby::Signature::Test::Errors.to_string(x) }, "Call trace does not match with given method type: #{trace.last.inspect}"
|
126
|
-
|
127
|
-
type, definition = target
|
128
|
-
method_types = case
|
129
|
-
when definition.instance_type?
|
130
|
-
subst = Substitution.build(definition.declaration.type_params.each.map(&:name),
|
131
|
-
type.args)
|
132
|
-
definition.methods[method].method_types.map do |method_type|
|
133
|
-
method_type.sub(subst)
|
134
|
-
end
|
135
|
-
when definition.class_type?
|
136
|
-
definition.methods[method].method_types
|
137
|
-
end
|
138
|
-
|
139
|
-
all_errors = method_types.map {|t| typecheck.method_call(method, t, trace.last, errors: []) }
|
140
|
-
assert all_errors.any? {|es| es.empty? }, "Call trace does not match one of method definitions:\n #{trace.last.inspect}\n #{method_types.join(" | ")}"
|
141
|
-
|
142
|
-
if exception
|
143
|
-
raise exception
|
144
|
-
end
|
145
|
-
end
|
146
|
-
|
147
|
-
ruby2_keywords def refute_send_type(method_type, receiver, method, *args, &block)
|
148
|
-
trace = []
|
149
|
-
spy = Spy.wrap(receiver, method)
|
150
|
-
spy.callback = -> (result) { trace << result }
|
151
|
-
|
152
|
-
exception = nil
|
153
|
-
begin
|
154
|
-
spy.wrapped_object.__send__(method, *args, &block)
|
155
|
-
rescue Exception => exn
|
156
|
-
exception = exn
|
157
|
-
end
|
158
|
-
|
159
|
-
mt = case method_type
|
160
|
-
when String
|
161
|
-
Ruby::Signature::Parser.parse_method_type(method_type, variables: [])
|
162
|
-
when Ruby::Signature::MethodType
|
163
|
-
method_type
|
164
|
-
end
|
165
|
-
|
166
|
-
mt = mt.update(block: if mt.block
|
167
|
-
MethodType::Block.new(
|
168
|
-
type: mt.block.type.with_return_type(Types::Bases::Any.new(location: nil)),
|
169
|
-
required: mt.block.required
|
170
|
-
)
|
171
|
-
end,
|
172
|
-
type: mt.type.with_return_type(Types::Bases::Any.new(location: nil)))
|
173
|
-
|
174
|
-
typecheck = TypeCheck.new(self_class: receiver.class, builder: builder)
|
175
|
-
errors = typecheck.method_call(method, mt, trace.last, errors: [])
|
176
|
-
|
177
|
-
assert_operator exception, :is_a?, ::Exception
|
178
|
-
assert_empty errors.map {|x| Ruby::Signature::Test::Errors.to_string(x) }
|
179
|
-
|
180
|
-
exception
|
181
|
-
end
|
182
|
-
end
|
183
|
-
end
|
184
|
-
end
|
185
|
-
end
|
@@ -1,256 +0,0 @@
|
|
1
|
-
module Ruby
|
2
|
-
module Signature
|
3
|
-
module Test
|
4
|
-
class TypeCheck
|
5
|
-
attr_reader :self_class
|
6
|
-
attr_reader :builder
|
7
|
-
|
8
|
-
def initialize(self_class:, builder:)
|
9
|
-
@self_class = self_class
|
10
|
-
@builder = builder
|
11
|
-
end
|
12
|
-
|
13
|
-
def method_call(method_name, method_type, call, errors:)
|
14
|
-
args(method_name, method_type, method_type.type, call.method_call, errors, type_error: Errors::ArgumentTypeError, argument_error: Errors::ArgumentError)
|
15
|
-
self.return(method_name, method_type, method_type.type, call.method_call, errors, return_error: Errors::ReturnTypeError)
|
16
|
-
|
17
|
-
if method_type.block
|
18
|
-
case
|
19
|
-
when !call.block_calls.empty?
|
20
|
-
call.block_calls.each do |block_call|
|
21
|
-
args(method_name, method_type, method_type.block.type, block_call, errors, type_error: Errors::BlockArgumentTypeError, argument_error: Errors::BlockArgumentError)
|
22
|
-
self.return(method_name, method_type, method_type.block.type, block_call, errors, return_error: Errors::BlockReturnTypeError)
|
23
|
-
end
|
24
|
-
when !call.block_given
|
25
|
-
# Block is not given
|
26
|
-
if method_type.block.required
|
27
|
-
errors << Errors::MissingBlockError.new(klass: self_class, method_name: method_name, method_type: method_type)
|
28
|
-
end
|
29
|
-
else
|
30
|
-
# Block is given, but not yielded
|
31
|
-
end
|
32
|
-
else
|
33
|
-
if call.block_given
|
34
|
-
errors << Errors::UnexpectedBlockError.new(klass: self_class, method_name: method_name, method_type: method_type)
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
errors
|
39
|
-
end
|
40
|
-
|
41
|
-
def args(method_name, method_type, fun, call, errors, type_error:, argument_error:)
|
42
|
-
test = zip_args(call.arguments, fun) do |val, param|
|
43
|
-
unless self.value(val, param.type)
|
44
|
-
errors << type_error.new(klass: self_class,
|
45
|
-
method_name: method_name,
|
46
|
-
method_type: method_type,
|
47
|
-
param: param,
|
48
|
-
value: val)
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
unless test
|
53
|
-
errors << argument_error.new(klass: self_class,
|
54
|
-
method_name: method_name,
|
55
|
-
method_type: method_type)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
def return(method_name, method_type, fun, call, errors, return_error:)
|
60
|
-
unless call.exception
|
61
|
-
unless value(call.return_value, fun.return_type)
|
62
|
-
errors << return_error.new(klass: self_class,
|
63
|
-
method_name: method_name,
|
64
|
-
method_type: method_type,
|
65
|
-
type: fun.return_type,
|
66
|
-
value: call.return_value)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def zip_keyword_args(hash, fun)
|
72
|
-
fun.required_keywords.each do |name, param|
|
73
|
-
if hash.key?(name)
|
74
|
-
yield(hash[name], param)
|
75
|
-
else
|
76
|
-
return false
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
fun.optional_keywords.each do |name, param|
|
81
|
-
if hash.key?(name)
|
82
|
-
yield(hash[name], param)
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
hash.each do |name, value|
|
87
|
-
next if fun.required_keywords.key?(name)
|
88
|
-
next if fun.optional_keywords.key?(name)
|
89
|
-
|
90
|
-
if fun.rest_keywords
|
91
|
-
yield value, fun.rest_keywords
|
92
|
-
else
|
93
|
-
return false
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
true
|
98
|
-
end
|
99
|
-
|
100
|
-
def keyword?(value)
|
101
|
-
value.is_a?(Hash) && value.keys.all? {|key| key.is_a?(Symbol) }
|
102
|
-
end
|
103
|
-
|
104
|
-
def zip_args(args, fun, &block)
|
105
|
-
case
|
106
|
-
when args.empty?
|
107
|
-
if fun.required_positionals.empty? && fun.trailing_positionals.empty? && fun.required_keywords.empty?
|
108
|
-
true
|
109
|
-
else
|
110
|
-
false
|
111
|
-
end
|
112
|
-
when !fun.required_positionals.empty?
|
113
|
-
yield_self do
|
114
|
-
param, fun_ = fun.drop_head
|
115
|
-
yield(args.first, param)
|
116
|
-
zip_args(args.drop(1), fun_, &block)
|
117
|
-
end
|
118
|
-
when fun.has_keyword?
|
119
|
-
yield_self do
|
120
|
-
hash = args.last
|
121
|
-
if keyword?(hash)
|
122
|
-
zip_keyword_args(hash, fun, &block) &&
|
123
|
-
zip_args(args.take(args.size - 1),
|
124
|
-
fun.update(required_keywords: {}, optional_keywords: {}, rest_keywords: nil),
|
125
|
-
&block)
|
126
|
-
else
|
127
|
-
fun.required_keywords.empty? &&
|
128
|
-
zip_args(args,
|
129
|
-
fun.update(required_keywords: {}, optional_keywords: {}, rest_keywords: nil),
|
130
|
-
&block)
|
131
|
-
end
|
132
|
-
end
|
133
|
-
when !fun.trailing_positionals.empty?
|
134
|
-
yield_self do
|
135
|
-
param, fun_ = fun.drop_tail
|
136
|
-
yield(args.last, param)
|
137
|
-
zip_args(args.take(args.size - 1), fun_, &block)
|
138
|
-
end
|
139
|
-
when !fun.optional_positionals.empty?
|
140
|
-
yield_self do
|
141
|
-
param, fun_ = fun.drop_head
|
142
|
-
yield(args.first, param)
|
143
|
-
zip_args(args.drop(1), fun_, &block)
|
144
|
-
end
|
145
|
-
when fun.rest_positionals
|
146
|
-
yield_self do
|
147
|
-
yield(args.first, fun.rest_positionals)
|
148
|
-
zip_args(args.drop(1), fun, &block)
|
149
|
-
end
|
150
|
-
else
|
151
|
-
false
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
def value(val, type)
|
156
|
-
case type
|
157
|
-
when Types::Bases::Any
|
158
|
-
true
|
159
|
-
when Types::Bases::Bool
|
160
|
-
true
|
161
|
-
when Types::Bases::Top
|
162
|
-
true
|
163
|
-
when Types::Bases::Bottom
|
164
|
-
false
|
165
|
-
when Types::Bases::Void
|
166
|
-
true
|
167
|
-
when Types::Bases::Self
|
168
|
-
Test.call(val, IS_AP, self_class)
|
169
|
-
when Types::Bases::Nil
|
170
|
-
Test.call(val, IS_AP, ::NilClass)
|
171
|
-
when Types::Bases::Class
|
172
|
-
Test.call(val, IS_AP, Class)
|
173
|
-
when Types::Bases::Instance
|
174
|
-
Test.call(val, IS_AP, self_class)
|
175
|
-
when Types::ClassInstance
|
176
|
-
klass = Object.const_get(type.name.to_s)
|
177
|
-
case
|
178
|
-
when klass == ::Array
|
179
|
-
Test.call(val, IS_AP, klass) && val.all? {|v| value(v, type.args[0]) }
|
180
|
-
when klass == ::Hash
|
181
|
-
Test.call(val, IS_AP, klass) && val.all? {|k, v| value(k, type.args[0]) && value(v, type.args[1]) }
|
182
|
-
when klass == ::Range
|
183
|
-
Test.call(val, IS_AP, klass) && value(val.begin, type.args[0]) && value(val.end, type.args[0])
|
184
|
-
when klass == ::Enumerator
|
185
|
-
if Test.call(val, IS_AP, klass)
|
186
|
-
case val.size
|
187
|
-
when Float::INFINITY
|
188
|
-
values = []
|
189
|
-
ret = self
|
190
|
-
val.lazy.take(10).each do |*args|
|
191
|
-
values << args
|
192
|
-
nil
|
193
|
-
end
|
194
|
-
else
|
195
|
-
values = []
|
196
|
-
ret = val.each do |*args|
|
197
|
-
values << args
|
198
|
-
nil
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
values.all? do |v|
|
203
|
-
if v.size == 1
|
204
|
-
# Only one block argument.
|
205
|
-
value(v[0], type.args[0]) || value(v, type.args[0])
|
206
|
-
else
|
207
|
-
value(v, type.args[0])
|
208
|
-
end
|
209
|
-
end &&
|
210
|
-
if ret.equal?(self)
|
211
|
-
type.args[1].is_a?(Types::Bases::Bottom)
|
212
|
-
else
|
213
|
-
value(ret, type.args[1])
|
214
|
-
end
|
215
|
-
end
|
216
|
-
else
|
217
|
-
Test.call(val, IS_AP, klass)
|
218
|
-
end
|
219
|
-
when Types::ClassSingleton
|
220
|
-
klass = Object.const_get(type.name.to_s)
|
221
|
-
val == klass
|
222
|
-
when Types::Interface
|
223
|
-
methods = Set.new(Test.call(val, METHODS))
|
224
|
-
decl = builder.env.find_class(type.name)
|
225
|
-
if (definition = builder.build_interface(type.name, decl))
|
226
|
-
definition.methods.each_key.all? do |method_name|
|
227
|
-
methods.member?(method_name)
|
228
|
-
end
|
229
|
-
end
|
230
|
-
when Types::Variable
|
231
|
-
true
|
232
|
-
when Types::Literal
|
233
|
-
val == type.literal
|
234
|
-
when Types::Union
|
235
|
-
type.types.any? {|type| value(val, type) }
|
236
|
-
when Types::Intersection
|
237
|
-
type.types.all? {|type| value(val, type) }
|
238
|
-
when Types::Optional
|
239
|
-
Test.call(val, IS_AP, ::NilClass) || value(val, type.type)
|
240
|
-
when Types::Alias
|
241
|
-
value(val, builder.expand_alias(type.name))
|
242
|
-
when Types::Tuple
|
243
|
-
Test.call(val, IS_AP, ::Array) &&
|
244
|
-
type.types.map.with_index {|ty, index| value(val[index], ty) }.all?
|
245
|
-
when Types::Record
|
246
|
-
Test::call(val, IS_AP, ::Hash)
|
247
|
-
when Types::Proc
|
248
|
-
Test::call(val, IS_AP, ::Proc)
|
249
|
-
else
|
250
|
-
false
|
251
|
-
end
|
252
|
-
end
|
253
|
-
end
|
254
|
-
end
|
255
|
-
end
|
256
|
-
end
|
@@ -1,72 +0,0 @@
|
|
1
|
-
module Ruby
|
2
|
-
module Signature
|
3
|
-
class TypeName
|
4
|
-
attr_reader :namespace
|
5
|
-
attr_reader :name
|
6
|
-
attr_reader :kind
|
7
|
-
|
8
|
-
def initialize(namespace:, name:)
|
9
|
-
@namespace = namespace
|
10
|
-
@name = name
|
11
|
-
@kind = case name.to_s[0,1]
|
12
|
-
when /[A-Z]/
|
13
|
-
:class
|
14
|
-
when /[a-z]/
|
15
|
-
:alias
|
16
|
-
when "_"
|
17
|
-
:interface
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def ==(other)
|
22
|
-
other.is_a?(self.class) && other.namespace == namespace && other.name == name
|
23
|
-
end
|
24
|
-
|
25
|
-
alias eql? ==
|
26
|
-
|
27
|
-
def hash
|
28
|
-
self.class.hash ^ namespace.hash ^ name.hash
|
29
|
-
end
|
30
|
-
|
31
|
-
def to_s
|
32
|
-
"#{namespace.to_s}#{name}"
|
33
|
-
end
|
34
|
-
|
35
|
-
def to_json(*a)
|
36
|
-
to_s.to_json(*a)
|
37
|
-
end
|
38
|
-
|
39
|
-
def to_namespace
|
40
|
-
namespace.append(self.name)
|
41
|
-
end
|
42
|
-
|
43
|
-
def class?
|
44
|
-
kind == :class
|
45
|
-
end
|
46
|
-
|
47
|
-
def alias?
|
48
|
-
kind == :alias
|
49
|
-
end
|
50
|
-
|
51
|
-
def absolute!
|
52
|
-
self.class.new(namespace: namespace.absolute!, name: name)
|
53
|
-
end
|
54
|
-
|
55
|
-
def absolute?
|
56
|
-
namespace.absolute?
|
57
|
-
end
|
58
|
-
|
59
|
-
def relative!
|
60
|
-
self.class.new(namespace: namespace.relative!, name: name)
|
61
|
-
end
|
62
|
-
|
63
|
-
def interface?
|
64
|
-
kind == :interface
|
65
|
-
end
|
66
|
-
|
67
|
-
def with_prefix(namespace)
|
68
|
-
self.class.new(namespace: namespace + self.namespace, name: name)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|