sorbet-runtime 0.4.4894 → 0.4.4901

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: 20a95cf20db9071b34cf1c9ff5cb897c9bbbcd7ac745ed68e1b6093582d99430
4
- data.tar.gz: c2ac4239305dc764f39863294f8d82fcc0966e6039d7f7870db56dd968e438ad
3
+ metadata.gz: acf4827a4df1da708da87821db5e5c62e839731de066277648d6f64e0e3aaaca
4
+ data.tar.gz: b8c27da475f0641fd75483b9f517118cb4506fa831d7108cea9e18f8cbe3e0b5
5
5
  SHA512:
6
- metadata.gz: b7b2fa196ea8514860ce94d52a1be90f739b55aac5eb7c1ab98f5d94b2ec232f8709d7f1dd573501d1c37aeecf2ab5c1471737b7f1edfb1a746855f3cc9b94b5
7
- data.tar.gz: 59b7bdb36f6369bd55b8da5b136aa38312b709ac91a409890c6628f22cc00effc43ad4087d4b60a4ad97f0cf2e352f2458a4e560d87b3743349b40db9c364086
6
+ metadata.gz: e35bbc99c047ac0209fc143ecfc090b24e711ed48036390ceeca031eabea63a3966066ee7d9673e5d93c0a76394c205cc636968e424d8faf4102d44e95f4a4ed
7
+ data.tar.gz: 62c08b4a00147ef1c55bb9cbe5c0bb28a406d34b033b445293cd623238616e5854f0a4166122d776328bd65c4fe8401b8673858ff27f518669a6ccba57e92be9
@@ -80,11 +80,11 @@ module T
80
80
  ## END OF THE METHODS TO PASS TO `sig`.
81
81
 
82
82
 
83
- # Constructs a type alias. Used to create a short name for a larger
84
- # type. In Ruby this is just equivalent to assignment, but this is
85
- # 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:
86
86
  #
87
- # NilableString = T.type_alias(T.nilable(String))
87
+ # NilableString = T.type_alias {T.nilable(String)}
88
88
  #
89
89
  # sig {params(arg: NilableString, default: String).returns(String)}
90
90
  # def or_else(arg, default)
@@ -93,8 +93,14 @@ module T
93
93
  #
94
94
  # The name of the type alias is not preserved; Error messages will
95
95
  # be printed with reference to the underlying type.
96
- def self.type_alias(type)
97
- T::Utils.coerce(type)
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
98
104
  end
99
105
 
100
106
  # References a type paramater which was previously defined with
@@ -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(T.any(TrueClass, FalseClass))
7
+ Boolean = T.type_alias {T.any(TrueClass, FalseClass)}
8
8
  end
@@ -9,6 +9,10 @@ module T::Private::Types
9
9
  @callable = callable
10
10
  end
11
11
 
12
+ def aliased_type
13
+ @aliased_type ||= T::Utils.coerce(@callable.call)
14
+ end
15
+
12
16
  # @override Base
13
17
  def name
14
18
  aliased_type.name
@@ -18,9 +22,5 @@ module T::Private::Types
18
22
  def valid?(obj)
19
23
  aliased_type.valid?(obj)
20
24
  end
21
-
22
- def aliased_type
23
- @aliased_type ||= T::Utils.coerce(@callable.call)
24
- end
25
25
  end
26
26
  end
@@ -10,11 +10,11 @@
10
10
  class T::Props::Decorator
11
11
  extend T::Sig
12
12
 
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))
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.',
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.4894
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-10-21 00:00:00.000000000 Z
11
+ date: 2019-10-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest