sorbet-runtime 0.4.4602 → 0.4.4651
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/sorbet-runtime.rb +2 -0
- data/lib/types/helpers.rb +1 -1
- data/lib/types/private/class_utils.rb +3 -3
- data/lib/types/private/decl_state.rb +11 -0
- data/lib/types/private/final.rb +3 -0
- data/lib/types/private/methods/call_validation.rb +12 -12
- data/lib/types/private/sealed.rb +60 -0
- data/lib/types/types/opus_enum.rb +33 -0
- data/lib/types/utils.rb +2 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb29fced50e91266ad73cc771434de432387bd12
|
4
|
+
data.tar.gz: 9278be4e1ef30d46845e89a7647ad57a7d701966
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4bb1fc554bbce84f6c4989eef5d2c546c1ec77546663b19381d62ed74cae7be800c26630f9efbad29b0dd9055d036afcc333a0dab18861b8372271fd4009b545
|
7
|
+
data.tar.gz: 94817c53e7bd2649434f1477a7ab8107ccf1331f3757d2882fb1827a44af712cf70c9007b5634052363e00aeba1b4080cf462702a2689e88e864f7a7899aa403
|
data/lib/sorbet-runtime.rb
CHANGED
@@ -30,6 +30,7 @@ require_relative 'types/private/methods/_methods'
|
|
30
30
|
require_relative 'types/sig'
|
31
31
|
require_relative 'types/helpers'
|
32
32
|
require_relative 'types/private/final'
|
33
|
+
require_relative 'types/private/sealed'
|
33
34
|
|
34
35
|
# The types themselves. First base classes
|
35
36
|
require_relative 'types/types/base'
|
@@ -44,6 +45,7 @@ require_relative 'types/types/noreturn'
|
|
44
45
|
require_relative 'types/types/proc'
|
45
46
|
require_relative 'types/types/self_type'
|
46
47
|
require_relative 'types/types/simple'
|
48
|
+
require_relative 'types/types/opus_enum'
|
47
49
|
require_relative 'types/types/type_parameter'
|
48
50
|
require_relative 'types/types/typed_array'
|
49
51
|
require_relative 'types/types/typed_enumerator'
|
data/lib/types/helpers.rb
CHANGED
@@ -21,7 +21,7 @@ module T::Helpers
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def sealed!
|
24
|
-
Kernel.
|
24
|
+
Private::Sealed.declare(self, Kernel.caller(1..1)&.first&.split(':')&.first)
|
25
25
|
end
|
26
26
|
|
27
27
|
# Causes a mixin to also mix in class methods from the named module.
|
@@ -96,9 +96,9 @@ module T::Private::ClassUtils
|
|
96
96
|
|
97
97
|
overwritten = original_owner == mod
|
98
98
|
T::Configuration.without_ruby_warnings do
|
99
|
-
T::Private::DeclState.current.
|
100
|
-
|
101
|
-
|
99
|
+
T::Private::DeclState.current.without_on_method_added do
|
100
|
+
mod.send(:define_method, name, &blk) # rubocop:disable PrisonGuard/UsePublicSend
|
101
|
+
end
|
102
102
|
end
|
103
103
|
mod.send(original_visibility, name) # rubocop:disable PrisonGuard/UsePublicSend
|
104
104
|
new_method = mod.instance_method(name)
|
@@ -16,4 +16,15 @@ class T::Private::DeclState
|
|
16
16
|
def reset!
|
17
17
|
self.active_declaration = nil
|
18
18
|
end
|
19
|
+
|
20
|
+
def without_on_method_added
|
21
|
+
begin
|
22
|
+
# explicit 'self' is needed here
|
23
|
+
old_value = self.skip_on_method_added
|
24
|
+
self.skip_on_method_added = true
|
25
|
+
yield
|
26
|
+
ensure
|
27
|
+
self.skip_on_method_added = old_value
|
28
|
+
end
|
29
|
+
end
|
19
30
|
end
|
data/lib/types/private/final.rb
CHANGED
@@ -31,6 +31,9 @@ module T::Private::Final
|
|
31
31
|
if T::AbstractUtils.abstract_module?(mod)
|
32
32
|
raise "#{mod} was already declared as abstract and cannot be declared as final"
|
33
33
|
end
|
34
|
+
if T::Private::Sealed.sealed_module?(mod)
|
35
|
+
raise "#{mod} was already declared as sealed and cannot be declared as final"
|
36
|
+
end
|
34
37
|
mod.extend(mod.is_a?(Class) ? NoInherit : NoIncludeExtend)
|
35
38
|
mark_as_final_module(mod)
|
36
39
|
mark_as_final_module(mod.singleton_class)
|
@@ -37,9 +37,9 @@ module T::Private::Methods::CallValidation
|
|
37
37
|
else
|
38
38
|
T::Configuration.without_ruby_warnings do
|
39
39
|
# get all the shims out of the way and put back the original method
|
40
|
-
T::Private::DeclState.current.
|
41
|
-
|
42
|
-
|
40
|
+
T::Private::DeclState.current.without_on_method_added do
|
41
|
+
mod.send(:define_method, method_sig.method_name, original_method)
|
42
|
+
end
|
43
43
|
mod.send(original_visibility, method_sig.method_name)
|
44
44
|
end
|
45
45
|
end
|
@@ -172,15 +172,15 @@ module T::Private::Methods::CallValidation
|
|
172
172
|
has_simple_procedure_types = all_args_are_simple && method_sig.return_type.is_a?(T::Private::Types::Void)
|
173
173
|
|
174
174
|
T::Configuration.without_ruby_warnings do
|
175
|
-
T::Private::DeclState.current.
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
175
|
+
T::Private::DeclState.current.without_on_method_added do
|
176
|
+
if has_fixed_arity && has_simple_method_types && method_sig.arg_types.length < 5 && is_allowed_to_have_fast_path
|
177
|
+
create_validator_method_fast(mod, original_method, method_sig)
|
178
|
+
elsif has_fixed_arity && has_simple_procedure_types && method_sig.arg_types.length < 5 && is_allowed_to_have_fast_path
|
179
|
+
create_validator_procedure_fast(mod, original_method, method_sig)
|
180
|
+
else
|
181
|
+
create_validator_slow(mod, original_method, method_sig)
|
182
|
+
end
|
183
|
+
end
|
184
184
|
end
|
185
185
|
mod.send(original_visibility, method_sig.method_name)
|
186
186
|
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# typed: false
|
3
|
+
|
4
|
+
module T::Private::Sealed
|
5
|
+
module NoInherit
|
6
|
+
def inherited(other)
|
7
|
+
super
|
8
|
+
this_line = Kernel.caller.find {|line| !line.match(/in `inherited'$/)}
|
9
|
+
T::Private::Sealed.validate_inheritance(this_line, self, 'inherited')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module NoIncludeExtend
|
14
|
+
def included(other)
|
15
|
+
super
|
16
|
+
this_line = Kernel.caller.find {|line| !line.match(/in `included'$/)}
|
17
|
+
T::Private::Sealed.validate_inheritance(this_line, self, 'included')
|
18
|
+
end
|
19
|
+
|
20
|
+
def extended(other)
|
21
|
+
super
|
22
|
+
this_line = Kernel.caller.find {|line| !line.match(/in `extended'$/)}
|
23
|
+
T::Private::Sealed.validate_inheritance(this_line, self, 'extended')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.declare(mod, decl_file)
|
28
|
+
if !mod.is_a?(Module)
|
29
|
+
raise "#{mod} is not a class or module and cannot be declared `sealed!`"
|
30
|
+
end
|
31
|
+
if sealed_module?(mod)
|
32
|
+
raise "#{mod} was already declared `sealed!` and cannot be re-declared `sealed!`"
|
33
|
+
end
|
34
|
+
if T::Private::Final.final_module?(mod)
|
35
|
+
raise "#{mod} was already declared `final!` and cannot be declared `sealed!`"
|
36
|
+
end
|
37
|
+
mod.extend(mod.is_a?(Class) ? NoInherit : NoIncludeExtend)
|
38
|
+
if !decl_file
|
39
|
+
raise "Couldn't determine declaration file for sealed class."
|
40
|
+
end
|
41
|
+
mod.instance_variable_set(:@sorbet_sealed_module_decl_file, decl_file)
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.sealed_module?(mod)
|
45
|
+
mod.instance_variable_defined?(:@sorbet_sealed_module_decl_file)
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.validate_inheritance(this_line, parent, verb)
|
49
|
+
this_file = this_line&.split(':').first
|
50
|
+
decl_file = parent.instance_variable_get(:@sorbet_sealed_module_decl_file)
|
51
|
+
|
52
|
+
if !this_file || !decl_file
|
53
|
+
raise "Couldn't determine enough file information for checking sealed modules"
|
54
|
+
end
|
55
|
+
|
56
|
+
if !this_file.start_with?(decl_file)
|
57
|
+
raise "#{parent} was declared sealed and can only be #{verb} in #{decl_file}, not #{this_file}"
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# typed: true
|
3
|
+
|
4
|
+
module T::Types
|
5
|
+
# Validates that an object is equal to another Opus::Enum singleton value.
|
6
|
+
class OpusEnum < Base
|
7
|
+
attr_reader :val
|
8
|
+
|
9
|
+
def initialize(val)
|
10
|
+
@val = val
|
11
|
+
end
|
12
|
+
|
13
|
+
# @override Base
|
14
|
+
def name
|
15
|
+
@val.inspect
|
16
|
+
end
|
17
|
+
|
18
|
+
# @override Base
|
19
|
+
def valid?(obj)
|
20
|
+
@val == obj
|
21
|
+
end
|
22
|
+
|
23
|
+
# @override Base
|
24
|
+
private def subtype_of_single?(other)
|
25
|
+
case other
|
26
|
+
when OpusEnum
|
27
|
+
@val == other.val
|
28
|
+
else
|
29
|
+
false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/types/utils.rb
CHANGED
@@ -26,6 +26,8 @@ module T::Utils
|
|
26
26
|
T::Types::FixedHash.new(val) # rubocop:disable PrisonGuard/UseOpusTypesShortcut
|
27
27
|
elsif val.is_a?(T::Private::Methods::DeclBuilder)
|
28
28
|
T::Private::Methods.finalize_proc(val.decl)
|
29
|
+
elsif defined?(::Opus) && defined?(::Opus::Enum) && val.is_a?(::Opus::Enum)
|
30
|
+
T::Types::OpusEnum.new(val) # rubocop:disable PrisonGuard/UseOpusTypesShortcut
|
29
31
|
else
|
30
32
|
raise "Invalid value for type constraint. Must be an #{T::Types::Base}, a " \
|
31
33
|
"class/module, or an array. Got a `#{val.class}`."
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sorbet-runtime
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4651
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stripe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -98,6 +98,7 @@ files:
|
|
98
98
|
- lib/types/private/methods/signature_validation.rb
|
99
99
|
- lib/types/private/mixins/mixins.rb
|
100
100
|
- lib/types/private/runtime_levels.rb
|
101
|
+
- lib/types/private/sealed.rb
|
101
102
|
- lib/types/private/types/not_typed.rb
|
102
103
|
- lib/types/private/types/string_holder.rb
|
103
104
|
- lib/types/private/types/void.rb
|
@@ -124,6 +125,7 @@ files:
|
|
124
125
|
- lib/types/types/fixed_hash.rb
|
125
126
|
- lib/types/types/intersection.rb
|
126
127
|
- lib/types/types/noreturn.rb
|
128
|
+
- lib/types/types/opus_enum.rb
|
127
129
|
- lib/types/types/proc.rb
|
128
130
|
- lib/types/types/self_type.rb
|
129
131
|
- lib/types/types/simple.rb
|