sorbet-runtime 0.4.4788 → 0.4.4901
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 -1
- data/lib/types/_types.rb +17 -6
- data/lib/types/boolean.rb +1 -1
- data/lib/types/private/methods/signature_validation.rb +1 -5
- data/lib/types/private/types/type_alias.rb +26 -0
- data/lib/types/props/decorator.rb +26 -5
- data/lib/types/props/type_validation.rb +2 -0
- data/lib/types/props/utils.rb +2 -0
- data/lib/types/types/attached_class.rb +33 -0
- data/lib/types/types/base.rb +10 -1
- data/lib/types/types/intersection.rb +1 -0
- data/lib/types/types/union.rb +1 -0
- data/lib/types/utils.rb +15 -1
- metadata +6 -4
- data/lib/types/private/error_handler.rb +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: acf4827a4df1da708da87821db5e5c62e839731de066277648d6f64e0e3aaaca
|
|
4
|
+
data.tar.gz: b8c27da475f0641fd75483b9f517118cb4506fa831d7108cea9e18f8cbe3e0b5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e35bbc99c047ac0209fc143ecfc090b24e711ed48036390ceeca031eabea63a3966066ee7d9673e5d93c0a76394c205cc636968e424d8faf4102d44e95f4a4ed
|
|
7
|
+
data.tar.gz: 62c08b4a00147ef1c55bb9cbe5c0bb28a406d34b033b445293cd623238616e5854f0a4166122d776328bd65c4fe8401b8673858ff27f518669a6ccba57e92be9
|
data/lib/sorbet-runtime.rb
CHANGED
|
@@ -24,7 +24,6 @@ require_relative 'types/_types'
|
|
|
24
24
|
require_relative 'types/private/decl_state'
|
|
25
25
|
require_relative 'types/runtime_profiled'
|
|
26
26
|
require_relative 'types/private/class_utils'
|
|
27
|
-
require_relative 'types/private/error_handler'
|
|
28
27
|
require_relative 'types/private/runtime_levels'
|
|
29
28
|
require_relative 'types/private/methods/_methods'
|
|
30
29
|
require_relative 'types/sig'
|
|
@@ -43,6 +42,7 @@ require_relative 'types/types/fixed_hash'
|
|
|
43
42
|
require_relative 'types/types/intersection'
|
|
44
43
|
require_relative 'types/types/noreturn'
|
|
45
44
|
require_relative 'types/types/proc'
|
|
45
|
+
require_relative 'types/types/attached_class'
|
|
46
46
|
require_relative 'types/types/self_type'
|
|
47
47
|
require_relative 'types/types/simple'
|
|
48
48
|
require_relative 'types/types/opus_enum'
|
|
@@ -57,6 +57,7 @@ require_relative 'types/types/untyped'
|
|
|
57
57
|
require_relative 'types/private/types/not_typed'
|
|
58
58
|
require_relative 'types/private/types/void'
|
|
59
59
|
require_relative 'types/private/types/string_holder'
|
|
60
|
+
require_relative 'types/private/types/type_alias'
|
|
60
61
|
|
|
61
62
|
require_relative 'types/types/type_variable'
|
|
62
63
|
require_relative 'types/types/type_member'
|
data/lib/types/_types.rb
CHANGED
|
@@ -65,6 +65,11 @@ module T
|
|
|
65
65
|
T::Types::SelfType.new
|
|
66
66
|
end
|
|
67
67
|
|
|
68
|
+
# Matches the instance type in a singleton-class context
|
|
69
|
+
def self.experimental_attached_class
|
|
70
|
+
T::Types::AttachedClassType.new
|
|
71
|
+
end
|
|
72
|
+
|
|
68
73
|
# Matches any class that subclasses or includes the provided class
|
|
69
74
|
# or module
|
|
70
75
|
def self.class_of(klass)
|
|
@@ -75,11 +80,11 @@ module T
|
|
|
75
80
|
## END OF THE METHODS TO PASS TO `sig`.
|
|
76
81
|
|
|
77
82
|
|
|
78
|
-
# Constructs a type alias. Used to create a short name for a larger
|
|
79
|
-
#
|
|
80
|
-
# needed for support by the static checker. Example usage:
|
|
83
|
+
# Constructs a type alias. Used to create a short name for a larger type. In Ruby this returns a
|
|
84
|
+
# wrapper that contains a proc that is evaluated to get the underlying type. This syntax however
|
|
85
|
+
# is needed for support by the static checker. Example usage:
|
|
81
86
|
#
|
|
82
|
-
# NilableString = T.type_alias
|
|
87
|
+
# NilableString = T.type_alias {T.nilable(String)}
|
|
83
88
|
#
|
|
84
89
|
# sig {params(arg: NilableString, default: String).returns(String)}
|
|
85
90
|
# def or_else(arg, default)
|
|
@@ -88,8 +93,14 @@ module T
|
|
|
88
93
|
#
|
|
89
94
|
# The name of the type alias is not preserved; Error messages will
|
|
90
95
|
# be printed with reference to the underlying type.
|
|
91
|
-
|
|
92
|
-
|
|
96
|
+
#
|
|
97
|
+
# TODO Remove `type` parameter. This was left in to make life easier while migrating.
|
|
98
|
+
def self.type_alias(type=nil, &blk)
|
|
99
|
+
if blk
|
|
100
|
+
T::Private::Types::TypeAlias.new(blk)
|
|
101
|
+
else
|
|
102
|
+
T::Utils.coerce(type)
|
|
103
|
+
end
|
|
93
104
|
end
|
|
94
105
|
|
|
95
106
|
# References a type paramater which was previously defined with
|
data/lib/types/boolean.rb
CHANGED
|
@@ -4,5 +4,5 @@
|
|
|
4
4
|
module T
|
|
5
5
|
# T::Boolean is a type alias helper for the common `T.any(TrueClass, FalseClass)`.
|
|
6
6
|
# Defined separately from _types.rb because it has a dependency on T::Types::Union.
|
|
7
|
-
Boolean = T.type_alias
|
|
7
|
+
Boolean = T.type_alias {T.any(TrueClass, FalseClass)}
|
|
8
8
|
end
|
|
@@ -58,11 +58,7 @@ module T::Private::Methods::SignatureValidation
|
|
|
58
58
|
def self.validate_override_mode(signature, super_signature)
|
|
59
59
|
case signature.mode
|
|
60
60
|
when *Modes::OVERRIDE_MODES
|
|
61
|
-
|
|
62
|
-
raise "You declared `#{signature.method_name}` as #{pretty_mode(signature)}, but the method it overrides is not declared as `overridable` or `abstract`.\n" \
|
|
63
|
-
" Parent definition: #{method_loc_str(super_signature.method)}\n" \
|
|
64
|
-
" Child definition: #{method_loc_str(signature.method)}\n"
|
|
65
|
-
end
|
|
61
|
+
# Peaceful
|
|
66
62
|
when *Modes::NON_OVERRIDE_MODES
|
|
67
63
|
if super_signature.mode == Modes.standard
|
|
68
64
|
# Peaceful
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# typed: true
|
|
3
|
+
|
|
4
|
+
module T::Private::Types
|
|
5
|
+
# Wraps a proc for a type alias to defer its evaluation.
|
|
6
|
+
class TypeAlias < T::Types::Base
|
|
7
|
+
|
|
8
|
+
def initialize(callable)
|
|
9
|
+
@callable = callable
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def aliased_type
|
|
13
|
+
@aliased_type ||= T::Utils.coerce(@callable.call)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# @override Base
|
|
17
|
+
def name
|
|
18
|
+
aliased_type.name
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# @override Base
|
|
22
|
+
def valid?(obj)
|
|
23
|
+
aliased_type.valid?(obj)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
class T::Props::Decorator
|
|
11
11
|
extend T::Sig
|
|
12
12
|
|
|
13
|
-
Rules = T.type_alias
|
|
14
|
-
DecoratedClass = T.type_alias
|
|
15
|
-
DecoratedInstance = T.type_alias
|
|
16
|
-
PropType = T.type_alias
|
|
17
|
-
PropTypeOrClass = T.type_alias
|
|
13
|
+
Rules = T.type_alias {T::Hash[Symbol, T.untyped]}
|
|
14
|
+
DecoratedClass = T.type_alias {T.untyped} # T.class_of(T::Props), but that produces circular reference errors in some circumstances
|
|
15
|
+
DecoratedInstance = T.type_alias {T.untyped} # Would be T::Props, but that produces circular reference errors in some circumstances
|
|
16
|
+
PropType = T.type_alias {T.any(T::Types::Base, T::Props::CustomType)}
|
|
17
|
+
PropTypeOrClass = T.type_alias {T.any(PropType, Module)}
|
|
18
18
|
|
|
19
19
|
class NoRulesError < StandardError; end
|
|
20
20
|
|
|
@@ -156,10 +156,27 @@ class T::Props::Decorator
|
|
|
156
156
|
else
|
|
157
157
|
type_object.valid?(val)
|
|
158
158
|
end
|
|
159
|
+
|
|
159
160
|
if !valid
|
|
160
161
|
raise T::Props::InvalidValueError.new("Can't set #{@class.name}.#{prop} to #{val.inspect} " \
|
|
161
162
|
"(instance of #{val.class}) - need a #{type_object}")
|
|
162
163
|
end
|
|
164
|
+
rescue T::Props::InvalidValueError => err
|
|
165
|
+
caller_loc = T.must(caller_locations(8, 1))[0]
|
|
166
|
+
|
|
167
|
+
pretty_message = "Parameter '#{prop}': #{err.message}\n" \
|
|
168
|
+
"Caller: #{caller_loc.path}:#{caller_loc.lineno}\n"
|
|
169
|
+
|
|
170
|
+
T::Configuration.call_validation_error_handler(
|
|
171
|
+
nil,
|
|
172
|
+
message: err.message,
|
|
173
|
+
pretty_message: pretty_message,
|
|
174
|
+
kind: 'Parameter',
|
|
175
|
+
name: prop,
|
|
176
|
+
type: type,
|
|
177
|
+
value: val,
|
|
178
|
+
location: caller_loc,
|
|
179
|
+
)
|
|
163
180
|
end
|
|
164
181
|
|
|
165
182
|
# For performance, don't use named params here.
|
|
@@ -330,6 +347,7 @@ class T::Props::Decorator
|
|
|
330
347
|
.void
|
|
331
348
|
end
|
|
332
349
|
def prop_defined(name, cls, rules={})
|
|
350
|
+
cls = T::Utils.resolve_alias(cls)
|
|
333
351
|
if rules[:optional] == true
|
|
334
352
|
T::Configuration.hard_assert_handler(
|
|
335
353
|
'Use of `optional: true` is deprecated, please use `T.nilable(...)` instead.',
|
|
@@ -556,6 +574,9 @@ class T::Props::Decorator
|
|
|
556
574
|
if defined?(Opus) && defined?(Opus::Enum)
|
|
557
575
|
TYPES_NOT_NEEDING_CLONE << Opus::Enum
|
|
558
576
|
end
|
|
577
|
+
if defined?(T::Enum)
|
|
578
|
+
TYPES_NOT_NEEDING_CLONE << T::Enum
|
|
579
|
+
end
|
|
559
580
|
|
|
560
581
|
sig {params(type: PropType).returns(T::Boolean)}
|
|
561
582
|
private def shallow_clone_ok(type)
|
|
@@ -64,6 +64,8 @@ module T::Props::TypeValidation
|
|
|
64
64
|
type.types.map {|subtype| find_invalid_subtype(subtype)}.compact.first
|
|
65
65
|
when T::Types::Enum, T::Types::ClassOf
|
|
66
66
|
nil
|
|
67
|
+
when T::Private::Types::TypeAlias
|
|
68
|
+
find_invalid_subtype(type.aliased_type)
|
|
67
69
|
when T::Types::Simple
|
|
68
70
|
# TODO Could we manage to define a whitelist, consisting of something
|
|
69
71
|
# like primitives, subdocs, DataInterfaces, and collections/enums/unions
|
data/lib/types/props/utils.rb
CHANGED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# typed: true
|
|
3
|
+
|
|
4
|
+
module T::Types
|
|
5
|
+
# Modeling AttachedClass properly at runtime would require additional
|
|
6
|
+
# tracking, so at runtime we permit all values and rely on the static checker.
|
|
7
|
+
# As AttachedClass is modeled statically as a type member on every singleton
|
|
8
|
+
# class, this is consistent with the runtime behavior for all type members.
|
|
9
|
+
class AttachedClassType < Base
|
|
10
|
+
|
|
11
|
+
def initialize(); end
|
|
12
|
+
|
|
13
|
+
# @override Base
|
|
14
|
+
def name
|
|
15
|
+
"AttachedClass"
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# @override Base
|
|
19
|
+
def valid?(obj)
|
|
20
|
+
true
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# @override Base
|
|
24
|
+
private def subtype_of_single?(other)
|
|
25
|
+
case other
|
|
26
|
+
when AttachedClassType
|
|
27
|
+
true
|
|
28
|
+
else
|
|
29
|
+
false
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
data/lib/types/types/base.rb
CHANGED
|
@@ -41,6 +41,14 @@ module T::Types
|
|
|
41
41
|
def subtype_of?(t2)
|
|
42
42
|
t1 = self
|
|
43
43
|
|
|
44
|
+
if t2.is_a?(T::Private::Types::TypeAlias)
|
|
45
|
+
t2 = t2.aliased_type
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
if t1.is_a?(T::Private::Types::TypeAlias)
|
|
49
|
+
return t1.aliased_type.subtype_of?(t2)
|
|
50
|
+
end
|
|
51
|
+
|
|
44
52
|
# pairs to cover: 1 (_, _)
|
|
45
53
|
# 2 (_, And)
|
|
46
54
|
# 3 (_, Or)
|
|
@@ -134,7 +142,8 @@ module T::Types
|
|
|
134
142
|
end
|
|
135
143
|
|
|
136
144
|
def ==(other)
|
|
137
|
-
other.class == self.class &&
|
|
145
|
+
(T::Utils.resolve_alias(other).class == T::Utils.resolve_alias(self).class) &&
|
|
146
|
+
other.name == self.name
|
|
138
147
|
end
|
|
139
148
|
|
|
140
149
|
alias_method :eql?, :==
|
data/lib/types/types/union.rb
CHANGED
data/lib/types/utils.rb
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
module T::Utils
|
|
5
5
|
# Used to convert from a type specification to a `T::Types::Base`.
|
|
6
6
|
def self.coerce(val)
|
|
7
|
-
if val.is_a?(T::Types::
|
|
7
|
+
if val.is_a?(T::Private::Types::TypeAlias)
|
|
8
|
+
val.aliased_type
|
|
9
|
+
elsif val.is_a?(T::Types::Base)
|
|
8
10
|
val
|
|
9
11
|
elsif val == ::Array
|
|
10
12
|
T::Array[T.untyped]
|
|
@@ -28,6 +30,8 @@ module T::Utils
|
|
|
28
30
|
T::Private::Methods.finalize_proc(val.decl)
|
|
29
31
|
elsif defined?(::Opus) && defined?(::Opus::Enum) && val.is_a?(::Opus::Enum)
|
|
30
32
|
T::Types::OpusEnum.new(val) # rubocop:disable PrisonGuard/UseOpusTypesShortcut
|
|
33
|
+
elsif defined?(::T::Enum) && val.is_a?(::T::Enum)
|
|
34
|
+
T::Types::OpusEnum.new(val) # rubocop:disable PrisonGuard/UseOpusTypesShortcut
|
|
31
35
|
else
|
|
32
36
|
raise "Invalid value for type constraint. Must be an #{T::Types::Base}, a " \
|
|
33
37
|
"class/module, or an array. Got a `#{val.class}`."
|
|
@@ -76,6 +80,16 @@ module T::Utils
|
|
|
76
80
|
T::Private::Methods.run_all_sig_blocks
|
|
77
81
|
end
|
|
78
82
|
|
|
83
|
+
# Return the underlying type for a type alias. Otherwise returns type.
|
|
84
|
+
def self.resolve_alias(type)
|
|
85
|
+
case type
|
|
86
|
+
when T::Private::Types::TypeAlias
|
|
87
|
+
type.aliased_type
|
|
88
|
+
else
|
|
89
|
+
type
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
79
93
|
# Give a type which is a subclass of T::Types::Base, determines if the type is a simple nilable type (union of NilClass and something else).
|
|
80
94
|
# If so, returns the T::Types::Base of the something else. Otherwise, returns nil.
|
|
81
95
|
def self.unwrap_nilable(type)
|
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.4901
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Stripe
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2019-
|
|
11
|
+
date: 2019-10-22 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: minitest
|
|
@@ -88,7 +88,6 @@ files:
|
|
|
88
88
|
- lib/types/private/casts.rb
|
|
89
89
|
- lib/types/private/class_utils.rb
|
|
90
90
|
- lib/types/private/decl_state.rb
|
|
91
|
-
- lib/types/private/error_handler.rb
|
|
92
91
|
- lib/types/private/final.rb
|
|
93
92
|
- lib/types/private/methods/_methods.rb
|
|
94
93
|
- lib/types/private/methods/call_validation.rb
|
|
@@ -101,6 +100,7 @@ files:
|
|
|
101
100
|
- lib/types/private/sealed.rb
|
|
102
101
|
- lib/types/private/types/not_typed.rb
|
|
103
102
|
- lib/types/private/types/string_holder.rb
|
|
103
|
+
- lib/types/private/types/type_alias.rb
|
|
104
104
|
- lib/types/private/types/void.rb
|
|
105
105
|
- lib/types/profile.rb
|
|
106
106
|
- lib/types/props/_props.rb
|
|
@@ -118,6 +118,7 @@ files:
|
|
|
118
118
|
- lib/types/runtime_profiled.rb
|
|
119
119
|
- lib/types/sig.rb
|
|
120
120
|
- lib/types/struct.rb
|
|
121
|
+
- lib/types/types/attached_class.rb
|
|
121
122
|
- lib/types/types/base.rb
|
|
122
123
|
- lib/types/types/class_of.rb
|
|
123
124
|
- lib/types/types/enum.rb
|
|
@@ -145,7 +146,8 @@ files:
|
|
|
145
146
|
homepage: https://sorbet.run
|
|
146
147
|
licenses:
|
|
147
148
|
- Apache-2.0
|
|
148
|
-
metadata:
|
|
149
|
+
metadata:
|
|
150
|
+
source_code_uri: https://github.com/sorbet/sorbet
|
|
149
151
|
post_install_message:
|
|
150
152
|
rdoc_options: []
|
|
151
153
|
require_paths:
|
|
File without changes
|