sorbet-runtime 0.5.9057 → 0.5.9076
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 +3 -0
- data/lib/types/configuration.rb +1 -1
- data/lib/types/private/casts.rb +0 -8
- data/lib/types/private/compiler.rb +24 -0
- data/lib/types/private/methods/decl_builder.rb +5 -5
- data/lib/types/private/methods/signature_validation.rb +1 -1
- data/lib/types/private/runtime_levels.rb +3 -0
- data/lib/types/types/fixed_hash.rb +16 -10
- data/lib/types/utils.rb +8 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 596cfe481f3fd2b6e621a3271d3ef373d8365badfb0e7a4bb7939bc593f785ed
|
4
|
+
data.tar.gz: c3506c7e55e25a5e2821f6384adc3f383a6d1aaf8762b8b7f53e0978fe0f7d0e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d52a6f2beb4ff73a6c56f31bd741e37bae512aa7ce768a4fd811662a6077bad0ae1304d42c90c060114eeea60056f6299f48ef27d22ece9956ed6566cf2e1c4
|
7
|
+
data.tar.gz: 4a8329759522aacfb35d08f77f5c106937736e7bd75244d5bdb0b99311edfdd94e53132c3b2da07b2eca7d836a4411527bce1868e5279dc858b0951ec392f566
|
data/lib/sorbet-runtime.rb
CHANGED
data/lib/types/configuration.rb
CHANGED
@@ -112,7 +112,7 @@ module T::Configuration
|
|
112
112
|
# statically, so that methods don't have to guard themselves from being
|
113
113
|
# called incorrectly by untyped code.
|
114
114
|
#
|
115
|
-
# @param [:never, :tests, :always] default_checked_level
|
115
|
+
# @param [:never, :compiled, :tests, :always] default_checked_level
|
116
116
|
def self.default_checked_level=(default_checked_level)
|
117
117
|
T::Private::RuntimeLevels.default_checked_level = default_checked_level
|
118
118
|
end
|
data/lib/types/private/casts.rb
CHANGED
@@ -2,14 +2,6 @@
|
|
2
2
|
# typed: false
|
3
3
|
|
4
4
|
module T::Private
|
5
|
-
# Dynamically confirm that `value` is recursively a valid value of
|
6
|
-
# type `type`, including recursively through collections. Note that
|
7
|
-
# in some cases this runtime check can be very expensive, especially
|
8
|
-
# with large collections of objects.
|
9
|
-
def self.check_type_recursive!(value, type)
|
10
|
-
T::Private::Casts.cast_recursive(value, type, cast_method: "T.check_type_recursive!")
|
11
|
-
end
|
12
|
-
|
13
5
|
module Casts
|
14
6
|
def self.cast(value, type, cast_method:)
|
15
7
|
begin
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
# typed: true
|
3
|
+
|
4
|
+
module T::Private
|
5
|
+
module Compiler
|
6
|
+
# If this code ever runs, the caller is running interpreted (or the
|
7
|
+
# compiler didn't see the call to `running_compiled?` statically.)
|
8
|
+
#
|
9
|
+
# The Sorbet Compiler replaces calls to this method unconditionally (no
|
10
|
+
# runtime guards) to return `true` when compiling a file.
|
11
|
+
def self.running_compiled?
|
12
|
+
false
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns `nil` because the compiler isn't running.
|
16
|
+
#
|
17
|
+
# The Sorbet Compiler replaces calls to this method unconditionally (no
|
18
|
+
# runtime guards) to return a String showing the Sorbet Compiler's version
|
19
|
+
# string.
|
20
|
+
def self.compiler_version
|
21
|
+
nil
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -88,8 +88,8 @@ module T::Private::Methods
|
|
88
88
|
if !decl.checked.equal?(ARG_NOT_PROVIDED)
|
89
89
|
raise BuilderError.new("You can't call .checked multiple times in a signature.")
|
90
90
|
end
|
91
|
-
if level == :never && !decl.on_failure.equal?(ARG_NOT_PROVIDED)
|
92
|
-
raise BuilderError.new("You can't use .checked(
|
91
|
+
if (level == :never || level == :compiled) && !decl.on_failure.equal?(ARG_NOT_PROVIDED)
|
92
|
+
raise BuilderError.new("You can't use .checked(:#{level}) with .on_failure because .on_failure will have no effect.")
|
93
93
|
end
|
94
94
|
if !T::Private::RuntimeLevels::LEVELS.include?(level)
|
95
95
|
raise BuilderError.new("Invalid `checked` level '#{level}'. Use one of: #{T::Private::RuntimeLevels::LEVELS}.")
|
@@ -106,8 +106,8 @@ module T::Private::Methods
|
|
106
106
|
if !decl.on_failure.equal?(ARG_NOT_PROVIDED)
|
107
107
|
raise BuilderError.new("You can't call .on_failure multiple times in a signature.")
|
108
108
|
end
|
109
|
-
if decl.checked == :never
|
110
|
-
raise BuilderError.new("You can't use .on_failure with .checked(
|
109
|
+
if decl.checked == :never || decl.checked == :compiled
|
110
|
+
raise BuilderError.new("You can't use .on_failure with .checked(:#{decl.checked}) because .on_failure will have no effect.")
|
111
111
|
end
|
112
112
|
|
113
113
|
decl.on_failure = args
|
@@ -209,7 +209,7 @@ module T::Private::Methods
|
|
209
209
|
end
|
210
210
|
if decl.checked.equal?(ARG_NOT_PROVIDED)
|
211
211
|
default_checked_level = T::Private::RuntimeLevels.default_checked_level
|
212
|
-
if default_checked_level == :never && !decl.on_failure.equal?(ARG_NOT_PROVIDED)
|
212
|
+
if (default_checked_level == :never || default_checked_level == :compiled) && !decl.on_failure.equal?(ARG_NOT_PROVIDED)
|
213
213
|
raise BuilderError.new("To use .on_failure you must additionally call .checked(:tests) or .checked(:always), otherwise, the .on_failure has no effect.")
|
214
214
|
end
|
215
215
|
decl.checked = default_checked_level
|
@@ -174,7 +174,7 @@ module T::Private::Methods::SignatureValidation
|
|
174
174
|
return if signature.override_allow_incompatible
|
175
175
|
return if super_signature.mode == Modes.untyped
|
176
176
|
return unless [signature, super_signature].all? do |sig|
|
177
|
-
sig.check_level == :always || (sig.check_level == :tests && T::Private::RuntimeLevels.check_tests?)
|
177
|
+
sig.check_level == :always || sig.check_level == :compiled || (sig.check_level == :tests && T::Private::RuntimeLevels.check_tests?)
|
178
178
|
end
|
179
179
|
mode_noun = super_signature.mode == Modes.abstract ? 'implementation' : 'override'
|
180
180
|
|
@@ -12,6 +12,9 @@ module T::Private::RuntimeLevels
|
|
12
12
|
# Don't even validate in tests, b/c too expensive,
|
13
13
|
# or b/c we fully trust the static typing
|
14
14
|
:never,
|
15
|
+
# Validate the sig when the file is using the Sorbet Compiler.
|
16
|
+
# Behaves like :never when interpreted.
|
17
|
+
:compiled,
|
15
18
|
].freeze
|
16
19
|
|
17
20
|
@check_tests = false
|
@@ -13,15 +13,7 @@ module T::Types
|
|
13
13
|
|
14
14
|
# @override Base
|
15
15
|
def name
|
16
|
-
|
17
|
-
if Symbol === k && ":#{k}" == k.inspect
|
18
|
-
"#{k}: #{v}"
|
19
|
-
else
|
20
|
-
"#{k.inspect} => #{v}"
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
"{#{entries.join(', ')}}"
|
16
|
+
serialize_hash(@types)
|
25
17
|
end
|
26
18
|
|
27
19
|
# @override Base
|
@@ -59,10 +51,24 @@ module T::Types
|
|
59
51
|
# @override Base
|
60
52
|
def describe_obj(obj)
|
61
53
|
if obj.is_a?(Hash)
|
62
|
-
"type
|
54
|
+
"type #{serialize_hash(obj.transform_values(&:class))}"
|
63
55
|
else
|
64
56
|
super
|
65
57
|
end
|
66
58
|
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def serialize_hash(hash)
|
63
|
+
entries = hash.map do |(k, v)|
|
64
|
+
if Symbol === k && ":#{k}" == k.inspect
|
65
|
+
"#{k}: #{v}"
|
66
|
+
else
|
67
|
+
"#{k.inspect} => #{v}"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
"{#{entries.join(', ')}}"
|
72
|
+
end
|
67
73
|
end
|
68
74
|
end
|
data/lib/types/utils.rb
CHANGED
@@ -27,6 +27,14 @@ module T::Utils
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
+
# Dynamically confirm that `value` is recursively a valid value of
|
31
|
+
# type `type`, including recursively through collections. Note that
|
32
|
+
# in some cases this runtime check can be very expensive, especially
|
33
|
+
# with large collections of objects.
|
34
|
+
def self.check_type_recursive!(value, type)
|
35
|
+
T::Private::Casts.cast_recursive(value, type, cast_method: "T.check_type_recursive!")
|
36
|
+
end
|
37
|
+
|
30
38
|
# Returns the set of all methods (public, protected, private) defined on a module or its
|
31
39
|
# ancestors, excluding Object and its ancestors. Overrides of methods from Object (and its
|
32
40
|
# ancestors) are included.
|
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.5.
|
4
|
+
version: 0.5.9076
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stripe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-08-
|
11
|
+
date: 2021-08-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -173,6 +173,7 @@ files:
|
|
173
173
|
- lib/types/private/abstract/validate.rb
|
174
174
|
- lib/types/private/casts.rb
|
175
175
|
- lib/types/private/class_utils.rb
|
176
|
+
- lib/types/private/compiler.rb
|
176
177
|
- lib/types/private/decl_state.rb
|
177
178
|
- lib/types/private/final.rb
|
178
179
|
- lib/types/private/methods/_methods.rb
|