raap 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/raap/cli.rb +55 -28
- data/lib/raap/function_type.rb +6 -6
- data/lib/raap/method_property.rb +25 -24
- data/lib/raap/method_type.rb +6 -6
- data/lib/raap/minitest.rb +2 -2
- data/lib/raap/type.rb +44 -29
- data/lib/raap/type_substitution.rb +3 -3
- data/lib/raap/value/interface.rb +5 -5
- data/lib/raap/value/intersection.rb +2 -2
- data/lib/raap/value/module.rb +1 -1
- data/lib/raap/version.rb +1 -1
- data/lib/shims.rb +2 -2
- metadata +3 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 508a0205dd03919d714a256f88193ab5755dd4d97c1cde9a5b0cb1720eae6b78
|
4
|
+
data.tar.gz: 8b220e18757b06c77816d27fd49b2e6db958b55c3d804890bc8691c23f2e74f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 69cf2e9fa5b033a71c7ce3efd01c04be95d7ac9baf8a9d05f4c6e4e63ffbb8ff06f3cc857cce786bbc5adb7059e19eeaa05ae7026990afd22b7481b20cdcc09b
|
7
|
+
data.tar.gz: fe81a27af6cb732096635b12301a726b13d0ea8e1f0ea8301ec29a2978b17a41f4fced40a5d8821caa3129ed56c79e6084ed74bafe8d5e84e6f1dd6d34be4e97
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
## [Unreleased]
|
2
2
|
|
3
|
+
## [1.1.0] - 2025-01-13
|
4
|
+
|
5
|
+
* Bundle update by @ksss in https://github.com/ksss/raap/pull/31
|
6
|
+
* Fix typing by @ksss in https://github.com/ksss/raap/pull/44
|
7
|
+
* Support RBS v3.8 by @ksss in https://github.com/ksss/raap/pull/45
|
8
|
+
* Use ruby34 by @ksss in https://github.com/ksss/raap/pull/46
|
9
|
+
|
3
10
|
## [1.0.0] - 2024-08-23
|
4
11
|
|
5
12
|
* Do not modify array for RBS::Types::ClassInstance#args by @pocke in https://github.com/ksss/raap/pull/25
|
data/lib/raap/cli.rb
CHANGED
@@ -13,6 +13,7 @@ module RaaP
|
|
13
13
|
:size_by,
|
14
14
|
:allow_private,
|
15
15
|
:coverage,
|
16
|
+
:numeric_positive,
|
16
17
|
keyword_init: true
|
17
18
|
)
|
18
19
|
|
@@ -44,6 +45,7 @@ module RaaP
|
|
44
45
|
size_by: 1,
|
45
46
|
coverage: true,
|
46
47
|
allow_private: false,
|
48
|
+
numeric_positive: false,
|
47
49
|
)
|
48
50
|
@argv = argv
|
49
51
|
@skip = DEFAULT_SKIP.dup
|
@@ -87,6 +89,9 @@ module RaaP
|
|
87
89
|
o.on('--[no-]coverage', "Show coverage for RBS (default: #{@option.coverage})") do |arg|
|
88
90
|
@option.coverage = arg
|
89
91
|
end
|
92
|
+
o.on('--numeric-positive', "Generate positive numeric only (default: #{@option.numeric_positive})") do |arg|
|
93
|
+
@option.numeric_positive = arg
|
94
|
+
end
|
90
95
|
end.parse!(@argv)
|
91
96
|
|
92
97
|
self
|
@@ -110,18 +115,20 @@ module RaaP
|
|
110
115
|
end
|
111
116
|
@skip.freeze
|
112
117
|
|
118
|
+
Type::Arithmetic.numeric_positive = @option.numeric_positive
|
119
|
+
|
113
120
|
@argv.each do |tag|
|
114
121
|
next if tag.start_with?('!')
|
115
122
|
|
116
123
|
case
|
117
124
|
when tag.include?('#')
|
118
|
-
run_by(kind: :instance, tag:
|
125
|
+
run_by(kind: :instance, tag:)
|
119
126
|
when tag.include?('.')
|
120
|
-
run_by(kind: :singleton, tag:
|
127
|
+
run_by(kind: :singleton, tag:)
|
121
128
|
when tag.end_with?('*')
|
122
|
-
run_by_type_name_with_search(tag:
|
129
|
+
run_by_type_name_with_search(tag:)
|
123
130
|
else
|
124
|
-
run_by_type_name(tag:
|
131
|
+
run_by_type_name(tag:)
|
125
132
|
end
|
126
133
|
end
|
127
134
|
|
@@ -195,10 +202,15 @@ module RaaP
|
|
195
202
|
|
196
203
|
RaaP.logger.info("# #{type}")
|
197
204
|
@results << {
|
198
|
-
method
|
199
|
-
properties: method.
|
200
|
-
property(
|
201
|
-
|
205
|
+
method:,
|
206
|
+
properties: method.defs.map do |type_def|
|
207
|
+
property(
|
208
|
+
receiver_type:,
|
209
|
+
type_params_decl:,
|
210
|
+
type_args:,
|
211
|
+
type_def:,
|
212
|
+
method_name:
|
213
|
+
)
|
202
214
|
end
|
203
215
|
}
|
204
216
|
end
|
@@ -236,10 +248,15 @@ module RaaP
|
|
236
248
|
|
237
249
|
RaaP.logger.info("# #{type_name}.#{method_name}")
|
238
250
|
@results << {
|
239
|
-
method
|
240
|
-
properties: method.
|
241
|
-
property(
|
242
|
-
|
251
|
+
method:,
|
252
|
+
properties: method.defs.map do |type_def|
|
253
|
+
property(
|
254
|
+
receiver_type: Type.new("singleton(#{type.name})"),
|
255
|
+
type_params_decl:,
|
256
|
+
type_args:,
|
257
|
+
type_def:,
|
258
|
+
method_name:
|
259
|
+
)
|
243
260
|
end
|
244
261
|
}
|
245
262
|
end
|
@@ -256,16 +273,21 @@ module RaaP
|
|
256
273
|
|
257
274
|
RaaP.logger.info("# #{type_name}##{method_name}")
|
258
275
|
@results << {
|
259
|
-
method
|
260
|
-
properties: method.
|
261
|
-
property(
|
262
|
-
|
276
|
+
method:,
|
277
|
+
properties: method.defs.map do |type_def|
|
278
|
+
property(
|
279
|
+
receiver_type: Type.new(type.name),
|
280
|
+
type_params_decl:,
|
281
|
+
type_args:,
|
282
|
+
type_def:,
|
283
|
+
method_name:
|
284
|
+
)
|
263
285
|
end
|
264
286
|
}
|
265
287
|
end
|
266
288
|
end
|
267
289
|
|
268
|
-
def property(receiver_type:, type_params_decl:, type_args:,
|
290
|
+
def property(receiver_type:, type_params_decl:, type_args:, type_def:, method_name:)
|
269
291
|
rtype = __skip__ = receiver_type.type
|
270
292
|
if receiver_type.type.instance_of?(::RBS::Types::ClassSingleton)
|
271
293
|
prefix = 'self.'
|
@@ -278,19 +300,19 @@ module RaaP
|
|
278
300
|
args = type_params_decl.map.with_index do |param, i|
|
279
301
|
type_args[i] || param.upper_bound || ::RBS::Types::Bases::Any.new(location: nil)
|
280
302
|
end
|
281
|
-
rtype = ::RBS::Types::ClassInstance.new(name: rtype.name, args
|
303
|
+
rtype = ::RBS::Types::ClassInstance.new(name: rtype.name, args:, location: rtype.location)
|
282
304
|
receiver_type = Type.new(rtype)
|
283
305
|
end
|
284
|
-
RaaP.logger.info("## def #{prefix}#{method_name}: #{
|
306
|
+
RaaP.logger.info("## def #{prefix}#{method_name}: #{type_def.type}")
|
285
307
|
status = 0
|
286
308
|
reason = nil
|
287
309
|
prop = MethodProperty.new(
|
288
|
-
receiver_type
|
289
|
-
method_name
|
310
|
+
receiver_type:,
|
311
|
+
method_name:,
|
290
312
|
method_type: MethodType.new(
|
291
|
-
|
292
|
-
type_params_decl
|
293
|
-
type_args
|
313
|
+
type_def.type,
|
314
|
+
type_params_decl:,
|
315
|
+
type_args:,
|
294
316
|
self_type: rtype,
|
295
317
|
instance_type: ::RBS::Types::ClassInstance.new(name: rtype.name, args: type_args, location: nil),
|
296
318
|
class_type: ::RBS::Types::ClassSingleton.new(name: rtype.name, location: nil),
|
@@ -298,8 +320,9 @@ module RaaP
|
|
298
320
|
size_step: @option.size_from.step(to: @option.size_to, by: @option.size_by),
|
299
321
|
timeout: @option.timeout,
|
300
322
|
allow_private: @option.allow_private,
|
323
|
+
annotations: type_def.annotations
|
301
324
|
)
|
302
|
-
RaaP::Coverage.start(
|
325
|
+
RaaP::Coverage.start(type_def.type) if @option.coverage
|
303
326
|
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
304
327
|
stats = prop.run do |called|
|
305
328
|
case called
|
@@ -314,8 +337,12 @@ module RaaP
|
|
314
337
|
end
|
315
338
|
RaaP.logger.debug { PP.pp(f.symbolic_call, ''.dup) }
|
316
339
|
reason = StringIO.new
|
317
|
-
|
318
|
-
|
340
|
+
begin
|
341
|
+
reason.puts "Failed in case of `#{f.called_str}`"
|
342
|
+
reason.puts
|
343
|
+
rescue => e
|
344
|
+
RaaP.logger.debug { "Raised `#{e}` in Result::Failure" }
|
345
|
+
end
|
319
346
|
reason.puts "### Repro"
|
320
347
|
reason.puts
|
321
348
|
reason.puts "```rb"
|
@@ -351,7 +378,7 @@ module RaaP
|
|
351
378
|
reason.puts "Never succeeded => #{stats_log}"
|
352
379
|
end
|
353
380
|
|
354
|
-
[status, method_name,
|
381
|
+
[status, method_name, type_def.type, reason]
|
355
382
|
end
|
356
383
|
end
|
357
384
|
end
|
data/lib/raap/function_type.rb
CHANGED
@@ -8,12 +8,12 @@ module RaaP
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def pick_arguments(size: 10)
|
11
|
-
SymbolicCaller.new(arguments_to_symbolic_call(size:
|
11
|
+
SymbolicCaller.new(arguments_to_symbolic_call(size:)).eval
|
12
12
|
end
|
13
13
|
|
14
14
|
def arguments_to_symbolic_call(size: 10)
|
15
|
-
a = to_symbolic_call_recursive(build_args_type, size:
|
16
|
-
k = to_symbolic_call_recursive(build_kwargs_type, size:
|
15
|
+
a = to_symbolic_call_recursive(build_args_type, size:)
|
16
|
+
k = to_symbolic_call_recursive(build_kwargs_type, size:)
|
17
17
|
|
18
18
|
[a, k]
|
19
19
|
end
|
@@ -25,11 +25,11 @@ module RaaP
|
|
25
25
|
when type.nil?
|
26
26
|
nil
|
27
27
|
when type.respond_to?(:each_pair)
|
28
|
-
type.each_pair.to_h { |k, v| [k, to_symbolic_call_recursive(v, size:
|
28
|
+
type.each_pair.to_h { |k, v| [k, to_symbolic_call_recursive(v, size:)] }
|
29
29
|
when type.respond_to?(:each)
|
30
|
-
type.map { |v| to_symbolic_call_recursive(v, size:
|
30
|
+
type.map { |v| to_symbolic_call_recursive(v, size:) }
|
31
31
|
else
|
32
|
-
type.to_symbolic_call(size:
|
32
|
+
type.to_symbolic_call(size:)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
data/lib/raap/method_property.rb
CHANGED
@@ -8,13 +8,14 @@ module RaaP
|
|
8
8
|
end
|
9
9
|
end
|
10
10
|
|
11
|
-
def initialize(receiver_type:, method_name:, method_type:, size_step:, timeout:, allow_private: false)
|
11
|
+
def initialize(receiver_type:, method_name:, method_type:, size_step:, timeout:, allow_private: false, annotations: [])
|
12
12
|
@receiver_type = receiver_type
|
13
13
|
@method_name = method_name
|
14
14
|
@method_type = method_type
|
15
15
|
@size_step = size_step
|
16
16
|
@timeout = timeout
|
17
17
|
@allow_private = allow_private
|
18
|
+
@annotations = annotations
|
18
19
|
end
|
19
20
|
|
20
21
|
def run
|
@@ -23,7 +24,7 @@ module RaaP
|
|
23
24
|
Timeout.timeout(@timeout) do
|
24
25
|
catch(:break) do
|
25
26
|
@size_step.each do |size|
|
26
|
-
call(size
|
27
|
+
call(size:, stats:).tap do |ret|
|
27
28
|
case ret
|
28
29
|
when Result::Success
|
29
30
|
stats.success += 1
|
@@ -55,8 +56,8 @@ module RaaP
|
|
55
56
|
stats.break = true
|
56
57
|
throw :break
|
57
58
|
end
|
58
|
-
receiver_value = @receiver_type.to_symbolic_call(size:
|
59
|
-
args, kwargs, block = @method_type.arguments_to_symbolic_call(size:
|
59
|
+
receiver_value = @receiver_type.to_symbolic_call(size:)
|
60
|
+
args, kwargs, block = @method_type.arguments_to_symbolic_call(size:)
|
60
61
|
# @type var symbolic_call: symbolic_call
|
61
62
|
symbolic_call = [:call, receiver_value, @method_name, args, kwargs, block]
|
62
63
|
symbolic_caller = SymbolicCaller.new(symbolic_call, allow_private: @allow_private)
|
@@ -78,23 +79,23 @@ module RaaP
|
|
78
79
|
end
|
79
80
|
else
|
80
81
|
return_value = symbolic_caller.eval
|
81
|
-
check = check_return(receiver_value
|
82
|
+
check = check_return(receiver_value:, return_value:)
|
82
83
|
end
|
83
84
|
case check
|
84
85
|
in [:success]
|
85
|
-
Result::Success.new(symbolic_call
|
86
|
+
Result::Success.new(symbolic_call:, return_value:)
|
86
87
|
in [:failure]
|
87
|
-
Result::Failure.new(symbolic_call
|
88
|
+
Result::Failure.new(symbolic_call:, return_value:)
|
88
89
|
in [:exception, exception]
|
89
|
-
Result::Exception.new(symbolic_call
|
90
|
+
Result::Exception.new(symbolic_call:, exception:)
|
90
91
|
end
|
91
92
|
rescue TypeError => exception
|
92
|
-
Result::Failure.new(symbolic_call
|
93
|
+
Result::Failure.new(symbolic_call:, return_value:, exception:)
|
93
94
|
end
|
94
95
|
|
95
96
|
# not ensure symbolic_call
|
96
97
|
rescue NoMethodError, NotImplementedError => exception
|
97
|
-
Result::Skip.new(symbolic_call
|
98
|
+
Result::Skip.new(symbolic_call:, exception:)
|
98
99
|
rescue NameError => e
|
99
100
|
RaaP.logger.warn("[#{e.class}] #{e.detailed_message}")
|
100
101
|
msg = e.name.nil? ? '' : "for `#{BindCall.to_s(e.receiver)}::#{e.name}`"
|
@@ -104,23 +105,17 @@ module RaaP
|
|
104
105
|
throw :break
|
105
106
|
rescue SystemStackError => exception
|
106
107
|
RaaP.logger.info "Found recursive type definition."
|
107
|
-
Result::Skip.new(symbolic_call
|
108
|
+
Result::Skip.new(symbolic_call:, exception:)
|
108
109
|
rescue => exception
|
109
|
-
Result::Exception.new(symbolic_call
|
110
|
+
Result::Exception.new(symbolic_call:, exception:)
|
110
111
|
end
|
111
112
|
|
112
113
|
def check_return(receiver_value:, return_value:)
|
113
|
-
if BindCall.is_a?(
|
114
|
-
|
115
|
-
|
116
|
-
if receiver_value == return_value
|
117
|
-
coverage("return", return_value, return_type)
|
118
|
-
[:success]
|
119
|
-
else
|
120
|
-
[:failure]
|
121
|
-
end
|
122
|
-
end
|
114
|
+
if implicitly_returns_nil? && BindCall.is_a?(return_value, NilClass)
|
115
|
+
return [:success]
|
116
|
+
end
|
123
117
|
|
118
|
+
if BindCall.is_a?(receiver_value, Module)
|
124
119
|
self_class = receiver_value
|
125
120
|
instance_class = receiver_value
|
126
121
|
else
|
@@ -128,8 +123,8 @@ module RaaP
|
|
128
123
|
instance_class = BindCall.class(receiver_value)
|
129
124
|
end
|
130
125
|
type_check = ::RBS::Test::TypeCheck.new(
|
131
|
-
self_class
|
132
|
-
instance_class
|
126
|
+
self_class:,
|
127
|
+
instance_class:,
|
133
128
|
class_class: Module,
|
134
129
|
builder: RBS.builder,
|
135
130
|
sample_size: 100,
|
@@ -148,6 +143,12 @@ module RaaP
|
|
148
143
|
end
|
149
144
|
end
|
150
145
|
|
146
|
+
def implicitly_returns_nil?
|
147
|
+
@annotations.any? do |a|
|
148
|
+
a.string == "implicitly-returns-nil"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
151
152
|
def return_type
|
152
153
|
@method_type.rbs.type.return_type
|
153
154
|
end
|
data/lib/raap/method_type.rb
CHANGED
@@ -19,7 +19,7 @@ module RaaP
|
|
19
19
|
|
20
20
|
params = (type_params_decl + rbs.type_params).uniq
|
21
21
|
ts = TypeSubstitution.new(params, type_args)
|
22
|
-
@rbs = ts.method_type_sub(rbs, self_type
|
22
|
+
@rbs = ts.method_type_sub(rbs, self_type:, instance_type:, class_type:)
|
23
23
|
function_or_untypedfunction = __skip__ = @rbs.type
|
24
24
|
@fun_type = FunctionType.new(function_or_untypedfunction)
|
25
25
|
@type_check = ::RBS::Test::TypeCheck.new(
|
@@ -33,12 +33,12 @@ module RaaP
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def pick_arguments(size: 10)
|
36
|
-
SymbolicCaller.new(arguments_to_symbolic_call(size:
|
36
|
+
SymbolicCaller.new(arguments_to_symbolic_call(size:)).eval
|
37
37
|
end
|
38
38
|
|
39
39
|
def arguments_to_symbolic_call(size: 10)
|
40
|
-
args, kwargs = @fun_type.arguments_to_symbolic_call(size:
|
41
|
-
block = pick_block(size:
|
40
|
+
args, kwargs = @fun_type.arguments_to_symbolic_call(size:)
|
41
|
+
block = pick_block(size:)
|
42
42
|
|
43
43
|
[args, kwargs, block]
|
44
44
|
end
|
@@ -62,7 +62,7 @@ module RaaP
|
|
62
62
|
end
|
63
63
|
fun.optional_positionals.each do |param|
|
64
64
|
resource.shift.tap do |name|
|
65
|
-
default = Type.new(param.type).pick(size:
|
65
|
+
default = Type.new(param.type).pick(size:)
|
66
66
|
args_name << name
|
67
67
|
# FIXME: Support any object
|
68
68
|
args_source << "#{name} = #{default.inspect}"
|
@@ -82,7 +82,7 @@ module RaaP
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
# Hack: Use local variable in eval
|
85
|
-
fixed_return_value = Type.new(block.type.return_type).pick(size:
|
85
|
+
fixed_return_value = Type.new(block.type.return_type).pick(size:)
|
86
86
|
_ = fixed_return_value
|
87
87
|
type_check = @type_check
|
88
88
|
_ = type_check
|
data/lib/raap/minitest.rb
CHANGED
@@ -13,7 +13,7 @@ module RaaP
|
|
13
13
|
method_type = RaaP::MethodType.new(type)
|
14
14
|
size_step.each do |size|
|
15
15
|
# TODO assert_send_type
|
16
|
-
args, kwargs, _block = method_type.pick_arguments(size:
|
16
|
+
args, kwargs, _block = method_type.pick_arguments(size:)
|
17
17
|
return_value = yield(*args, **kwargs)
|
18
18
|
i = BindCall.inspect(return_value)
|
19
19
|
c = BindCall.class(return_value)
|
@@ -30,7 +30,7 @@ module RaaP
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
size_step.each do |size|
|
33
|
-
values = types.map { |t| t.pick(size:
|
33
|
+
values = types.map { |t| t.pick(size:) }
|
34
34
|
assert yield(*values)
|
35
35
|
end
|
36
36
|
end
|
data/lib/raap/type.rb
CHANGED
@@ -7,8 +7,18 @@ module RaaP
|
|
7
7
|
# Type.new("Array[Integer]") { sized { |size| Array.new(size + 1) { integer.pick(size: size) } } }
|
8
8
|
class Type
|
9
9
|
module Arithmetic
|
10
|
+
def self.numeric_positive=(bool)
|
11
|
+
@numeric_positive = bool
|
12
|
+
end
|
13
|
+
|
10
14
|
def self.float
|
11
|
-
positive_float.then
|
15
|
+
positive_float.then do |x|
|
16
|
+
if @numeric_positive
|
17
|
+
x
|
18
|
+
else
|
19
|
+
[x, -x].sample or raise
|
20
|
+
end
|
21
|
+
end
|
12
22
|
end
|
13
23
|
|
14
24
|
def self.positive_float
|
@@ -50,24 +60,29 @@ module RaaP
|
|
50
60
|
type_params = definition.type_params_decl.dup.concat(rbs_method_type.type_params.drop(definition.type_params_decl.length))
|
51
61
|
ts = TypeSubstitution.new(type_params, type.args)
|
52
62
|
maped_rbs_method_type = ts.method_type_sub(rbs_method_type)
|
53
|
-
method_type = MethodType.new(
|
63
|
+
method_type = MethodType.new(
|
64
|
+
maped_rbs_method_type,
|
65
|
+
class_type: ::RBS::Types::ClassSingleton.new(name: type.name, location: nil),
|
66
|
+
instance_type: type,
|
67
|
+
self_type: type
|
68
|
+
)
|
54
69
|
|
55
70
|
begin
|
56
|
-
args, kwargs, block = method_type.arguments_to_symbolic_call(size:
|
71
|
+
args, kwargs, block = method_type.arguments_to_symbolic_call(size:)
|
57
72
|
[:call, base, :new, args, kwargs, block]
|
58
73
|
rescue
|
59
74
|
$stderr.puts "Fail with `#{rbs_method_type}`"
|
60
75
|
raise
|
61
76
|
end
|
62
77
|
else
|
63
|
-
[:call, Value::Module, :new, [type.to_s], { size:
|
78
|
+
[:call, Value::Module, :new, [type.to_s], { size: }, nil]
|
64
79
|
end
|
65
80
|
end
|
66
81
|
|
67
82
|
# Special class case
|
68
83
|
register("::Array") do
|
69
84
|
instance = __skip__ = type
|
70
|
-
t = instance.args[0] ? Type.new(instance.args[0], range:
|
85
|
+
t = instance.args[0] ? Type.new(instance.args[0], range:) : Type.random
|
71
86
|
array(t)
|
72
87
|
end
|
73
88
|
register("::Binding") { binding }
|
@@ -104,7 +119,7 @@ module RaaP
|
|
104
119
|
register("::NilClass") { nil }
|
105
120
|
register("::Proc") { Proc.new {} }
|
106
121
|
register("::Rational") { rational }
|
107
|
-
register("::Regexp") { sized { |size| Regexp.new(string.pick(size:
|
122
|
+
register("::Regexp") { sized { |size| Regexp.new(string.pick(size:)) } }
|
108
123
|
register("::String") { string }
|
109
124
|
register("::Struct") { Struct.new(:foo, :bar).new }
|
110
125
|
register("::Symbol") { symbol }
|
@@ -140,11 +155,11 @@ module RaaP
|
|
140
155
|
end
|
141
156
|
|
142
157
|
def pick(size: 10)
|
143
|
-
to_symbolic_caller(size:
|
158
|
+
to_symbolic_caller(size:).eval
|
144
159
|
end
|
145
160
|
|
146
161
|
def to_symbolic_caller(size: 10)
|
147
|
-
SymbolicCaller.new(to_symbolic_call(size:
|
162
|
+
SymbolicCaller.new(to_symbolic_call(size:))
|
148
163
|
end
|
149
164
|
|
150
165
|
def to_symbolic_call(size: 10)
|
@@ -153,20 +168,20 @@ module RaaP
|
|
153
168
|
|
154
169
|
case type
|
155
170
|
when ::RBS::Types::Tuple
|
156
|
-
type.types.map { |t| Type.new(t).to_symbolic_call(size:
|
171
|
+
type.types.map { |t| Type.new(t).to_symbolic_call(size:) }
|
157
172
|
when ::RBS::Types::Union
|
158
|
-
type.types.sample&.then { |t| Type.new(t).to_symbolic_call(size:
|
173
|
+
type.types.sample&.then { |t| Type.new(t).to_symbolic_call(size:) }
|
159
174
|
when ::RBS::Types::Intersection
|
160
175
|
if type.free_variables.empty?
|
161
|
-
[:call, Value::Intersection, :new, [type.to_s], { size:
|
176
|
+
[:call, Value::Intersection, :new, [type.to_s], { size: }, nil]
|
162
177
|
else
|
163
|
-
[:call, Value::Intersection, :new, [type], { size:
|
178
|
+
[:call, Value::Intersection, :new, [type], { size: }, nil]
|
164
179
|
end
|
165
180
|
when ::RBS::Types::Interface
|
166
181
|
if type.free_variables.empty?
|
167
|
-
[:call, Value::Interface, :new, [type.to_s], { size:
|
182
|
+
[:call, Value::Interface, :new, [type.to_s], { size: }, nil]
|
168
183
|
else
|
169
|
-
[:call, Value::Interface, :new, [type], { size:
|
184
|
+
[:call, Value::Interface, :new, [type], { size: }, nil]
|
170
185
|
end
|
171
186
|
when ::RBS::Types::Variable
|
172
187
|
[:call, Value::Variable, :new, [type.to_s], {}, nil]
|
@@ -184,7 +199,7 @@ module RaaP
|
|
184
199
|
when ::RBS::Types::Alias
|
185
200
|
case gen = GENERATORS[type.name.absolute!.to_s]
|
186
201
|
in Proc then instance_exec(&gen)
|
187
|
-
in nil then Type.new(RBS.builder.expand_alias2(type.name, type.args)).to_symbolic_call(size:
|
202
|
+
in nil then Type.new(RBS.builder.expand_alias2(type.name, type.args)).to_symbolic_call(size:)
|
188
203
|
end
|
189
204
|
when ::RBS::Types::Bases::Class
|
190
205
|
RaaP.logger.warn("Unresolved `class` type, use Object instead.")
|
@@ -198,19 +213,19 @@ module RaaP
|
|
198
213
|
Object.const_get(type.name.to_s)
|
199
214
|
when ::RBS::Types::ClassInstance
|
200
215
|
case gen = GENERATORS[type.name.absolute!.to_s]
|
201
|
-
in Proc then pick_by_generator(gen, size:
|
202
|
-
in nil then to_symbolic_call_from_initialize(type, size:
|
216
|
+
in Proc then pick_by_generator(gen, size:)
|
217
|
+
in nil then to_symbolic_call_from_initialize(type, size:)
|
203
218
|
end
|
204
219
|
when ::RBS::Types::Record
|
205
220
|
type.fields.transform_values { |t| Type.new(t).to_symbolic_call(size: size / 2) }
|
206
221
|
when ::RBS::Types::Proc
|
207
|
-
Proc.new { Type.new(type.type.return_type).to_symbolic_call(size:
|
222
|
+
Proc.new { Type.new(type.type.return_type).to_symbolic_call(size:) }
|
208
223
|
when ::RBS::Types::Literal
|
209
224
|
type.literal
|
210
225
|
when ::RBS::Types::Bases::Bool
|
211
226
|
bool
|
212
227
|
when ::RBS::Types::Bases::Any
|
213
|
-
Type.random.to_symbolic_call(size:
|
228
|
+
Type.random.to_symbolic_call(size:)
|
214
229
|
when ::RBS::Types::Bases::Nil
|
215
230
|
nil
|
216
231
|
else
|
@@ -224,7 +239,7 @@ module RaaP
|
|
224
239
|
ret = instance_exec(&gen)
|
225
240
|
case ret
|
226
241
|
when Sized
|
227
|
-
ret.pick(size:
|
242
|
+
ret.pick(size:)
|
228
243
|
else
|
229
244
|
ret
|
230
245
|
end
|
@@ -233,7 +248,7 @@ module RaaP
|
|
233
248
|
def to_symbolic_call_from_initialize(type, size:)
|
234
249
|
type_name = type.name.absolute!
|
235
250
|
const = Object.const_get(type_name.to_s)
|
236
|
-
Type.call_new_from(const, type, size:
|
251
|
+
Type.call_new_from(const, type, size:)
|
237
252
|
end
|
238
253
|
|
239
254
|
def parse(type)
|
@@ -248,7 +263,7 @@ module RaaP
|
|
248
263
|
end
|
249
264
|
|
250
265
|
def integer
|
251
|
-
sized { |size| float.pick(size:
|
266
|
+
sized { |size| float.pick(size:).round }
|
252
267
|
end
|
253
268
|
|
254
269
|
def none_zero_integer
|
@@ -272,16 +287,16 @@ module RaaP
|
|
272
287
|
|
273
288
|
def rational
|
274
289
|
sized do |size|
|
275
|
-
a = integer.pick(size:
|
276
|
-
b = none_zero_integer.pick(size:
|
290
|
+
a = integer.pick(size:)
|
291
|
+
b = none_zero_integer.pick(size:)
|
277
292
|
[:call, Kernel, :Rational, [a, b], {}, nil]
|
278
293
|
end
|
279
294
|
end
|
280
295
|
|
281
296
|
def complex
|
282
297
|
sized do |size|
|
283
|
-
a = integer.pick(size:
|
284
|
-
b = none_zero_integer.pick(size:
|
298
|
+
a = integer.pick(size:)
|
299
|
+
b = none_zero_integer.pick(size:)
|
285
300
|
[:call, Kernel, :Complex, [a, b], {}, nil]
|
286
301
|
end
|
287
302
|
end
|
@@ -306,13 +321,13 @@ module RaaP
|
|
306
321
|
|
307
322
|
def symbol
|
308
323
|
sized do |size|
|
309
|
-
string.pick(size:
|
324
|
+
string.pick(size:).to_sym
|
310
325
|
end
|
311
326
|
end
|
312
327
|
|
313
328
|
def array(type)
|
314
329
|
sized do |size|
|
315
|
-
Array.new(integer.pick(size:
|
330
|
+
Array.new(integer.pick(size:).abs) do
|
316
331
|
type.to_symbolic_call(size: size / 2)
|
317
332
|
end
|
318
333
|
end
|
@@ -323,7 +338,7 @@ module RaaP
|
|
323
338
|
def dict(key_type, value_type)
|
324
339
|
sized do |size|
|
325
340
|
csize = size / 2
|
326
|
-
Array.new(integer.pick(size:
|
341
|
+
Array.new(integer.pick(size:).abs).to_h do
|
327
342
|
[
|
328
343
|
key_type.to_symbolic_call(size: csize),
|
329
344
|
value_type.to_symbolic_call(size: csize)
|
@@ -31,8 +31,8 @@ module RaaP
|
|
31
31
|
|
32
32
|
::RBS::MethodType.new(
|
33
33
|
type_params: [],
|
34
|
-
type: method_type.type.sub(sub).then { |ty| sub(ty, self_type
|
35
|
-
block: method_type.block&.sub(sub)&.then { |bl| sub(bl, self_type
|
34
|
+
type: method_type.type.sub(sub).then { |ty| sub(ty, self_type:, instance_type:, class_type:) },
|
35
|
+
block: method_type.block&.sub(sub)&.then { |bl| sub(bl, self_type:, instance_type:, class_type:) },
|
36
36
|
location: method_type.location
|
37
37
|
)
|
38
38
|
end
|
@@ -53,7 +53,7 @@ module RaaP
|
|
53
53
|
when ::RBS::Types::Bases::Class
|
54
54
|
class_type || ty
|
55
55
|
else
|
56
|
-
sub(ty, self_type
|
56
|
+
sub(ty, self_type:, instance_type:, class_type:)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
data/lib/raap/value/interface.rb
CHANGED
@@ -20,21 +20,21 @@ module RaaP
|
|
20
20
|
method_type = method.method_types.sample or ::Kernel.raise
|
21
21
|
type_params = definition.type_params_decl.concat(method_type.type_params.drop(definition.type_params_decl.length))
|
22
22
|
ts = TypeSubstitution.new(type_params, type.args)
|
23
|
-
subed_method_type = ts.method_type_sub(method_type, self_type
|
23
|
+
subed_method_type = ts.method_type_sub(method_type, self_type:, instance_type:, class_type:)
|
24
24
|
|
25
25
|
BindCall.define_method(base_mod, name) do |*_, &b|
|
26
26
|
@fixed_return_value ||= {} #: Hash[Symbol, Interface | Type]
|
27
27
|
@fixed_return_value[name] ||= if self_type == subed_method_type.type.return_type
|
28
28
|
self
|
29
29
|
else
|
30
|
-
Type.new(subed_method_type.type.return_type).pick(size:
|
30
|
+
Type.new(subed_method_type.type.return_type).pick(size:)
|
31
31
|
end
|
32
32
|
# @type var b: Proc?
|
33
33
|
if b && subed_method_type.block && subed_method_type.block.type.is_a?(::RBS::Types::Function)
|
34
34
|
@fixed_block_arguments ||= {} #: Hash[Symbol, Array[FunctionType]]
|
35
35
|
@fixed_block_arguments[name] ||= size.times.map do
|
36
36
|
FunctionType.new(subed_method_type.block.type, coverage: false)
|
37
|
-
.pick_arguments(size:
|
37
|
+
.pick_arguments(size:)
|
38
38
|
end
|
39
39
|
|
40
40
|
@fixed_block_arguments[name].each do |a, kw|
|
@@ -48,10 +48,10 @@ module RaaP
|
|
48
48
|
|
49
49
|
def new(type, size: 3)
|
50
50
|
temp_class = ::Class.new(Interface) do |c|
|
51
|
-
define_method_from_interface(c, type, size:
|
51
|
+
define_method_from_interface(c, type, size:)
|
52
52
|
end
|
53
53
|
instance = temp_class.allocate
|
54
|
-
instance.__send__(:initialize, type, size:
|
54
|
+
instance.__send__(:initialize, type, size:)
|
55
55
|
instance
|
56
56
|
end
|
57
57
|
end
|
@@ -27,12 +27,12 @@ module RaaP
|
|
27
27
|
type.types.each do |t|
|
28
28
|
case t
|
29
29
|
when ::RBS::Types::Interface
|
30
|
-
Interface.define_method_from_interface(self, t, size:
|
30
|
+
Interface.define_method_from_interface(self, t, size:)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
end
|
34
34
|
type = ::RBS::Types::ClassInstance.new(name: ::RBS::TypeName.parse(base.name), args: [], location: nil)
|
35
|
-
SymbolicCaller.new(Type.call_new_from(c, type, size:
|
35
|
+
SymbolicCaller.new(Type.call_new_from(c, type, size:)).eval
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
data/lib/raap/value/module.rb
CHANGED
@@ -35,7 +35,7 @@ module RaaP
|
|
35
35
|
if !ts.include?('::BasicObject') || ts.any? { |t| t.split('::').last&.start_with?('_') }
|
36
36
|
ts.unshift('Object')
|
37
37
|
end
|
38
|
-
Type.new(ts.uniq.join(' & ')).pick(size:
|
38
|
+
Type.new(ts.uniq.join(' & ')).pick(size:)
|
39
39
|
end
|
40
40
|
end
|
41
41
|
const = ::Object.const_get(@type.name.absolute!.to_s)
|
data/lib/raap/version.rb
CHANGED
data/lib/shims.rb
CHANGED
@@ -48,8 +48,8 @@ unless RBS::TypeName.singleton_class.method_defined?(:parse)
|
|
48
48
|
raise unless name
|
49
49
|
|
50
50
|
TypeName.new(
|
51
|
-
name
|
52
|
-
namespace: RBS::Namespace.new(path
|
51
|
+
name:,
|
52
|
+
namespace: RBS::Namespace.new(path:, absolute:)
|
53
53
|
)
|
54
54
|
end
|
55
55
|
end
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: raap
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ksss
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date: 2025-01-
|
10
|
+
date: 2025-01-29 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: rbs
|
@@ -80,7 +79,6 @@ licenses:
|
|
80
79
|
- MIT
|
81
80
|
metadata:
|
82
81
|
rubygems_mfa_required: 'true'
|
83
|
-
post_install_message:
|
84
82
|
rdoc_options: []
|
85
83
|
require_paths:
|
86
84
|
- lib
|
@@ -95,8 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
93
|
- !ruby/object:Gem::Version
|
96
94
|
version: '0'
|
97
95
|
requirements: []
|
98
|
-
rubygems_version: 3.
|
99
|
-
signing_key:
|
96
|
+
rubygems_version: 3.6.2
|
100
97
|
specification_version: 4
|
101
98
|
summary: RBS as a Property
|
102
99
|
test_files: []
|