sorbet-runtime 0.5.9058 → 0.5.9084

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e15f5bb2c23ab6f1a94d99fc85188a14a1fba652d4c8994bf84a5d568d7f808d
4
- data.tar.gz: 868e7ee916c1b38dd543d83277c06b8b1649b89e7007fe1a44869f31a129202d
3
+ metadata.gz: 9afe4efe4f9ccffa0e380b802ca0e485554d603fd37ba01fb2767314023e8c2d
4
+ data.tar.gz: 5f998864d3f6db7004f6f9dfbd0121ff16b323129bb98057f08aae4403b8469f
5
5
  SHA512:
6
- metadata.gz: 4d44ba58916117adc0d516597779a7f66d92b9f3050416aa018cf313da0e1b09c1e1572a8f7f5cca6c68064a41fd0a61866e661ff25c6535e1363d45153b6704
7
- data.tar.gz: 64187d1b8daa52799600e370891594ae9f10b71fd9b163e84c6ddb4de6a7829d869e80780ca1b35dfc733f0719b3fc7590ff30dcd9e99a1465c3de72d626c50b
6
+ metadata.gz: 12403fa7f879992564ec3fa357ee00afbdf814ade9d4c439c05d98eb209edc2be9d184a4ba5a49d05f6ec4b301d1330641755bd8c0324fcdc04a4a5434dcb572
7
+ data.tar.gz: 0043022541b91db01ee052e850f9816463a335b2ff69d5d35bcb4c5e6a5c3bbed6173d5731e8ce900415d7432c1bfd3da61d9cd75d387a7851b1b8bc72379a4d
@@ -112,3 +112,6 @@ require_relative 'types/struct'
112
112
  require_relative 'types/non_forcing_constants'
113
113
 
114
114
  require_relative 'types/compatibility_patches'
115
+
116
+ # Sorbet Compiler support module
117
+ require_relative 'types/private/compiler'
@@ -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
@@ -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(:never) with .on_failure because .on_failure will have no effect.")
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(:never) because .on_failure will have no effect.")
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
- entries = @types.map do |(k, v)|
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 {#{obj.map {|(k, v)| "#{k}: #{v.class}"}.join(', ')}}"
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.9058
4
+ version: 0.5.9084
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-22 00:00:00.000000000 Z
11
+ date: 2021-08-27 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