sorbet-runtime 0.4.4869 → 0.4.4878

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5dbdfcf412572c9ea831245b35e705b4fee67a51b030569fd5b7e601c579e4f3
4
- data.tar.gz: f082863d2331e67ed34c724bc29feae087eeb63af5db6efca6e1c6af89502e9f
3
+ metadata.gz: 24dc6e9c709ddaa06a39910776ad04d297c87258be1522766bc9debea9e76f7e
4
+ data.tar.gz: 4b9054f4d6713ff99f90414c036eccc042ba6c02746525fd4e637dda62981825
5
5
  SHA512:
6
- metadata.gz: 894d0e5fd2fcc17b915dbf16cb8a7c0207d2a7e7f1c8c18d17f35c3f1fb099b06abddbeccb53e0725987a362bca3a90d68d4c734b150e2c45322d22a245ff751
7
- data.tar.gz: 6d75e695d9be234474da26b5782382efb10b880cc2c30ec3c32dca6fa3ad0067d249eed35f2398702fe003a27d76588b1309b4daeefd408fc916bc1bf4f701a1
6
+ metadata.gz: bf094800059eb3a52309de25073025dad8e33253a7318219c6d6c3459c17f5e846ce4b721605a665baf80b6237390d7ca8f83bfd285a0e477af34ff16c8c738f
7
+ data.tar.gz: 32e44a51c069b5ffee943f289c82523a26b1c13ba14edaada2e750b70989e21d5ac7e8373b61b0dbc31685dc7498a7d2dca25c05e0e7a3f2f5cc1f08280e917a
@@ -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'
@@ -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
+ # @override Base
13
+ def name
14
+ aliased_type.name
15
+ end
16
+
17
+ # @override Base
18
+ def valid?(obj)
19
+ aliased_type.valid?(obj)
20
+ end
21
+
22
+ def aliased_type
23
+ @aliased_type ||= T::Utils.coerce(@callable.call)
24
+ end
25
+ end
26
+ end
@@ -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
@@ -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 && other.name == self.name
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?, :==
@@ -8,6 +8,7 @@ module T::Types
8
8
 
9
9
  def initialize(types)
10
10
  @types = types.flat_map do |type|
11
+ type = T::Utils.resolve_alias(type)
11
12
  if type.is_a?(Intersection)
12
13
  # Simplify nested intersections (mostly so `name` returns a nicer value)
13
14
  type.types
@@ -8,6 +8,7 @@ module T::Types
8
8
 
9
9
  def initialize(types)
10
10
  @types = types.flat_map do |type|
11
+ type = T::Utils.resolve_alias(type)
11
12
  if type.is_a?(Union)
12
13
  # Simplify nested unions (mostly so `name` returns a nicer value)
13
14
  type.types
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::Base)
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]
@@ -76,6 +78,16 @@ module T::Utils
76
78
  T::Private::Methods.run_all_sig_blocks
77
79
  end
78
80
 
81
+ # Return the underlying type for a type alias. Otherwise returns type.
82
+ def self.resolve_alias(type)
83
+ case type
84
+ when T::Private::Types::TypeAlias
85
+ type.aliased_type
86
+ else
87
+ type
88
+ end
89
+ end
90
+
79
91
  # 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
92
  # If so, returns the T::Types::Base of the something else. Otherwise, returns nil.
81
93
  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.4869
4
+ version: 0.4.4878
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-15 00:00:00.000000000 Z
11
+ date: 2019-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -100,6 +100,7 @@ files:
100
100
  - lib/types/private/sealed.rb
101
101
  - lib/types/private/types/not_typed.rb
102
102
  - lib/types/private/types/string_holder.rb
103
+ - lib/types/private/types/type_alias.rb
103
104
  - lib/types/private/types/void.rb
104
105
  - lib/types/profile.rb
105
106
  - lib/types/props/_props.rb