sorbet-runtime 0.6.13300 → 0.6.13301

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: 24e2e39ecb07eff0a9d4e9efeeebe17935b16363cf0e27b070e9ac9b5e90eccf
4
- data.tar.gz: 7e4c6aca4672cfe3aa3a33779e640a343c981330fbda03a2d1471b7ac619ae20
3
+ metadata.gz: 11be14e5fdfd480b79b5c799ffc878c604f8cdd3c5776f5b7eb55eaf143d59ee
4
+ data.tar.gz: c90d13ff890616e82d414249178bbd5dfb080c7604bc5b4a5c2b706ef9fd63c7
5
5
  SHA512:
6
- metadata.gz: 86e102983a1b56070cc100e77a809cf77ffdc4cc0c3ea3d4986020e9ecf85763af195cd24517157ddf2d2d4ed25c32ba9d92a19ecb1857c61b2c9503e737ac98
7
- data.tar.gz: 63d055b3273fff38053757d9e439a8e82f945d1edc0d883b2a82a1f442feb13af73a199eb56aa5216aa67e2f9c749431c29a50b5d27d24e483f580d4beca7fb5
6
+ metadata.gz: 40aebdc992a72011d67c62214f0cd36d7cf1a6a728c1c9db44beb6b2af5d97b4a7783b2896892382bdc10cde4bb9a4a3be8aa9ea901da409902569a6e52ee9ed
7
+ data.tar.gz: efbf3fff51bae607d1e0c25e12c768c95ce5e289677ab9f22fd5fb88b7f8045c9dd0940c5d3efba7b9d1ac66c53d6da166d062311b2a4b0e812166b17ba867cf
@@ -72,8 +72,16 @@ module T::Private::Methods::CallValidation
72
72
  end
73
73
 
74
74
  def self.create_validator_method(mod, original_method, method_sig, original_visibility)
75
+ # Wrapper-shape decisions must read the parameters of the method actually being wrapped, not
76
+ # `method_sig.parameters` (captured at sig-build time). The two diverge when a sig'd method is
77
+ # re-wrapped over a different implementation: a stub redefined as `def m(*args, **kwargs, &blk)`
78
+ # then re-validated against the original fixed-arity sig would otherwise pick a fixed-arity wrapper,
79
+ # which binds args to named positionals and forwards them without the `ruby2_keywords` flag, turning
80
+ # a trailing `key: val` into a positional hash. Reading from `original_method` costs one array per
81
+ # wrap, off the hot path.
82
+ parameters = original_method.parameters
75
83
  has_fixed_arity = method_sig.kwarg_types.empty? && method_sig.rest_type.nil? && method_sig.keyrest_type.nil? &&
76
- original_method.parameters.all? { |(kind, _name)| kind == :req || kind == :block }
84
+ parameters.all? { |(kind, _name)| kind == :req || kind == :block }
77
85
 
78
86
  # nil implies block_type.nil?
79
87
  # true implies !block_type.nil? and block_type.valid?(nil)
@@ -83,6 +91,29 @@ module T::Private::Methods::CallValidation
83
91
 
84
92
  ok_for_fast_path = has_fixed_arity && can_skip_block_type && !method_sig.bind && method_sig.arg_types.length < 5 && is_allowed_to_have_fast_path
85
93
 
94
+ # Like `ok_for_fast_path`, but for the specialized wrappers below, each of
95
+ # which supports exactly one extra call shape (kwargs, a required block, or
96
+ # optional positional args) on top of what the fast/medium wrappers support.
97
+ ok_for_specialized_path = !ok_for_fast_path && !method_sig.bind && method_sig.rest_type.nil? &&
98
+ method_sig.keyrest_type.nil? && method_sig.arg_types.length < 5 && is_allowed_to_have_fast_path
99
+
100
+ # Restricted to methods with no positional args. The kwargs wrapper's `|**kwargs, &blk|` declares a
101
+ # keyword-rest, which would capture a bare `key: val` hash that a method with a positional parameter
102
+ # expects to receive positionally, starving that parameter. All-kwargs methods have no such parameter,
103
+ # so the wrapper matches a direct call. (Most kwargs-shaped sigs take only kwargs.)
104
+ kwargs_path = ok_for_specialized_path && can_skip_block_type && !method_sig.kwarg_types.empty? &&
105
+ method_sig.arg_types.empty? &&
106
+ parameters.all? { |(kind, _name)| kind == :key || kind == :keyreq || kind == :block }
107
+
108
+ required_block_path = ok_for_specialized_path && !can_skip_block_type && has_fixed_arity
109
+
110
+ # At least one param is `:opt` here (otherwise `ok_for_fast_path` would hold). The wrapper forwards
111
+ # through a `ruby2_keywords`-flagged `|*args, &blk|` splat (see below), not named optional parameters:
112
+ # named params have no `*rest` for `def_with_visibility` to flag, so a trailing `key: val` that Ruby
113
+ # packs into an optional positional would lose the keyword flag the slow path preserves.
114
+ optional_args_path = ok_for_specialized_path && can_skip_block_type && method_sig.kwarg_types.empty? &&
115
+ parameters.all? { |(kind, _name)| kind == :req || kind == :opt || kind == :block }
116
+
86
117
  all_args_are_simple = ok_for_fast_path && method_sig.arg_types.all? { |_name, type| type.is_a?(T::Types::Simple) }
87
118
 
88
119
  effective_return_type = method_sig.effective_return_type
@@ -115,6 +146,12 @@ module T::Private::Methods::CallValidation
115
146
  create_validator_method_skip_return_medium(mod, original_method, method_sig, original_visibility)
116
147
  elsif ok_for_fast_path
117
148
  create_validator_method_medium(mod, original_method, method_sig, original_visibility)
149
+ elsif kwargs_path
150
+ create_validator_method_kwargs(mod, original_method, method_sig, original_visibility)
151
+ elsif required_block_path
152
+ create_validator_method_with_block(mod, original_method, method_sig, original_visibility)
153
+ elsif optional_args_path
154
+ create_validator_method_optional_args(mod, original_method, method_sig, original_visibility)
118
155
  elsif can_skip_block_type
119
156
  # The Ruby VM already validates that any block passed to a method
120
157
  # must be either `nil` or a `Proc` object, so there's no need to also
@@ -1726,4 +1726,1030 @@ module T::Private::Methods::CallValidation
1726
1726
  end
1727
1727
  end
1728
1728
 
1729
+ def self.create_validator_method_kwargs(mod, original_method, method_sig, original_visibility)
1730
+ return_type = method_sig.effective_return_type
1731
+ return_type = nil if return_type.is_a?(T::Private::Types::Void)
1732
+ create_validator_method_kwargs0(mod, original_method, method_sig, original_visibility, return_type, method_sig.kwarg_types)
1733
+ end
1734
+
1735
+ def self.create_validator_method_kwargs0(mod, original_method, method_sig, original_visibility, return_type, kwarg_types)
1736
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |**kwargs, &blk|
1737
+ # This method is a manually sped-up version of more general code in `validate_call`
1738
+ # NOTE: like `validate_call`, we don't validate for missing or extra
1739
+ # kwargs; the `bind_call` below takes care of that.
1740
+ kwargs.each do |name, val|
1741
+ type = kwarg_types[name]
1742
+ next unless type
1743
+ next if type.valid?(val)
1744
+ CallValidation.report_error(
1745
+ method_sig,
1746
+ type.error_message_for_obj(val),
1747
+ 'Parameter',
1748
+ name,
1749
+ type,
1750
+ val,
1751
+ caller_offset: 1
1752
+ )
1753
+ end
1754
+ return_value = original_method.bind_call(self, **kwargs, &blk)
1755
+ if return_type.nil?
1756
+ T::Private::Types::Void::VOID
1757
+ else
1758
+ unless return_type.valid?(return_value)
1759
+ message = method_sig.effective_return_type.error_message_for_obj(return_value)
1760
+ if message
1761
+ CallValidation.report_error(
1762
+ method_sig,
1763
+ message,
1764
+ 'Return value',
1765
+ nil,
1766
+ method_sig.effective_return_type,
1767
+ return_value,
1768
+ caller_offset: -1
1769
+ )
1770
+ end
1771
+ end
1772
+ return_value
1773
+ end
1774
+ end
1775
+ end
1776
+
1777
+ def self.create_validator_method_with_block(mod, original_method, method_sig, original_visibility)
1778
+ return_type = method_sig.effective_return_type
1779
+ return_type = nil if return_type.is_a?(T::Private::Types::Void)
1780
+ block_type = method_sig.block_type
1781
+ # trampoline to reduce stack frame size
1782
+ arg_types = method_sig.arg_types
1783
+ case arg_types.length
1784
+ when 0
1785
+ create_validator_method_with_block0(mod, original_method, method_sig, original_visibility, return_type, block_type)
1786
+ when 1
1787
+ create_validator_method_with_block1(mod, original_method, method_sig, original_visibility, return_type, block_type,
1788
+ arg_types[0][1])
1789
+ when 2
1790
+ create_validator_method_with_block2(mod, original_method, method_sig, original_visibility, return_type, block_type,
1791
+ arg_types[0][1],
1792
+ arg_types[1][1])
1793
+ when 3
1794
+ create_validator_method_with_block3(mod, original_method, method_sig, original_visibility, return_type, block_type,
1795
+ arg_types[0][1],
1796
+ arg_types[1][1],
1797
+ arg_types[2][1])
1798
+ when 4
1799
+ create_validator_method_with_block4(mod, original_method, method_sig, original_visibility, return_type, block_type,
1800
+ arg_types[0][1],
1801
+ arg_types[1][1],
1802
+ arg_types[2][1],
1803
+ arg_types[3][1])
1804
+ else
1805
+ raise 'should not happen'
1806
+ end
1807
+ end
1808
+
1809
+ def self.create_validator_method_with_block0(mod, original_method, method_sig, original_visibility, return_type, block_type)
1810
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |&blk|
1811
+ # This method is a manually sped-up version of more general code in `validate_call`
1812
+ if blk.nil?
1813
+ CallValidation.report_error(
1814
+ method_sig,
1815
+ block_type.error_message_for_obj(blk),
1816
+ 'Block parameter',
1817
+ method_sig.block_name,
1818
+ block_type,
1819
+ blk,
1820
+ caller_offset: -1
1821
+ )
1822
+ end
1823
+ return_value = original_method.bind_call(self, &blk)
1824
+ if return_type.nil?
1825
+ T::Private::Types::Void::VOID
1826
+ else
1827
+ unless return_type.valid?(return_value)
1828
+ message = method_sig.effective_return_type.error_message_for_obj(return_value)
1829
+ if message
1830
+ CallValidation.report_error(
1831
+ method_sig,
1832
+ message,
1833
+ 'Return value',
1834
+ nil,
1835
+ method_sig.effective_return_type,
1836
+ return_value,
1837
+ caller_offset: -1
1838
+ )
1839
+ end
1840
+ end
1841
+ return_value
1842
+ end
1843
+ end
1844
+ end
1845
+
1846
+ def self.create_validator_method_with_block1(mod, original_method, method_sig, original_visibility, return_type, block_type, arg0_type)
1847
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, &blk|
1848
+ # This method is a manually sped-up version of more general code in `validate_call`
1849
+ unless arg0_type.valid?(arg0)
1850
+ CallValidation.report_error(
1851
+ method_sig,
1852
+ method_sig.arg_types[0][1].error_message_for_obj(arg0),
1853
+ 'Parameter',
1854
+ method_sig.arg_types[0][0],
1855
+ arg0_type,
1856
+ arg0,
1857
+ caller_offset: -1
1858
+ )
1859
+ end
1860
+ if blk.nil?
1861
+ CallValidation.report_error(
1862
+ method_sig,
1863
+ block_type.error_message_for_obj(blk),
1864
+ 'Block parameter',
1865
+ method_sig.block_name,
1866
+ block_type,
1867
+ blk,
1868
+ caller_offset: -1
1869
+ )
1870
+ end
1871
+ return_value = original_method.bind_call(self, arg0, &blk)
1872
+ if return_type.nil?
1873
+ T::Private::Types::Void::VOID
1874
+ else
1875
+ unless return_type.valid?(return_value)
1876
+ message = method_sig.effective_return_type.error_message_for_obj(return_value)
1877
+ if message
1878
+ CallValidation.report_error(
1879
+ method_sig,
1880
+ message,
1881
+ 'Return value',
1882
+ nil,
1883
+ method_sig.effective_return_type,
1884
+ return_value,
1885
+ caller_offset: -1
1886
+ )
1887
+ end
1888
+ end
1889
+ return_value
1890
+ end
1891
+ end
1892
+ end
1893
+
1894
+ def self.create_validator_method_with_block2(mod, original_method, method_sig, original_visibility, return_type, block_type, arg0_type, arg1_type)
1895
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, arg1, &blk|
1896
+ # This method is a manually sped-up version of more general code in `validate_call`
1897
+ unless arg0_type.valid?(arg0)
1898
+ CallValidation.report_error(
1899
+ method_sig,
1900
+ method_sig.arg_types[0][1].error_message_for_obj(arg0),
1901
+ 'Parameter',
1902
+ method_sig.arg_types[0][0],
1903
+ arg0_type,
1904
+ arg0,
1905
+ caller_offset: -1
1906
+ )
1907
+ end
1908
+ unless arg1_type.valid?(arg1)
1909
+ CallValidation.report_error(
1910
+ method_sig,
1911
+ method_sig.arg_types[1][1].error_message_for_obj(arg1),
1912
+ 'Parameter',
1913
+ method_sig.arg_types[1][0],
1914
+ arg1_type,
1915
+ arg1,
1916
+ caller_offset: -1
1917
+ )
1918
+ end
1919
+ if blk.nil?
1920
+ CallValidation.report_error(
1921
+ method_sig,
1922
+ block_type.error_message_for_obj(blk),
1923
+ 'Block parameter',
1924
+ method_sig.block_name,
1925
+ block_type,
1926
+ blk,
1927
+ caller_offset: -1
1928
+ )
1929
+ end
1930
+ return_value = original_method.bind_call(self, arg0, arg1, &blk)
1931
+ if return_type.nil?
1932
+ T::Private::Types::Void::VOID
1933
+ else
1934
+ unless return_type.valid?(return_value)
1935
+ message = method_sig.effective_return_type.error_message_for_obj(return_value)
1936
+ if message
1937
+ CallValidation.report_error(
1938
+ method_sig,
1939
+ message,
1940
+ 'Return value',
1941
+ nil,
1942
+ method_sig.effective_return_type,
1943
+ return_value,
1944
+ caller_offset: -1
1945
+ )
1946
+ end
1947
+ end
1948
+ return_value
1949
+ end
1950
+ end
1951
+ end
1952
+
1953
+ def self.create_validator_method_with_block3(mod, original_method, method_sig, original_visibility, return_type, block_type, arg0_type, arg1_type, arg2_type)
1954
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, arg1, arg2, &blk|
1955
+ # This method is a manually sped-up version of more general code in `validate_call`
1956
+ unless arg0_type.valid?(arg0)
1957
+ CallValidation.report_error(
1958
+ method_sig,
1959
+ method_sig.arg_types[0][1].error_message_for_obj(arg0),
1960
+ 'Parameter',
1961
+ method_sig.arg_types[0][0],
1962
+ arg0_type,
1963
+ arg0,
1964
+ caller_offset: -1
1965
+ )
1966
+ end
1967
+ unless arg1_type.valid?(arg1)
1968
+ CallValidation.report_error(
1969
+ method_sig,
1970
+ method_sig.arg_types[1][1].error_message_for_obj(arg1),
1971
+ 'Parameter',
1972
+ method_sig.arg_types[1][0],
1973
+ arg1_type,
1974
+ arg1,
1975
+ caller_offset: -1
1976
+ )
1977
+ end
1978
+ unless arg2_type.valid?(arg2)
1979
+ CallValidation.report_error(
1980
+ method_sig,
1981
+ method_sig.arg_types[2][1].error_message_for_obj(arg2),
1982
+ 'Parameter',
1983
+ method_sig.arg_types[2][0],
1984
+ arg2_type,
1985
+ arg2,
1986
+ caller_offset: -1
1987
+ )
1988
+ end
1989
+ if blk.nil?
1990
+ CallValidation.report_error(
1991
+ method_sig,
1992
+ block_type.error_message_for_obj(blk),
1993
+ 'Block parameter',
1994
+ method_sig.block_name,
1995
+ block_type,
1996
+ blk,
1997
+ caller_offset: -1
1998
+ )
1999
+ end
2000
+ return_value = original_method.bind_call(self, arg0, arg1, arg2, &blk)
2001
+ if return_type.nil?
2002
+ T::Private::Types::Void::VOID
2003
+ else
2004
+ unless return_type.valid?(return_value)
2005
+ message = method_sig.effective_return_type.error_message_for_obj(return_value)
2006
+ if message
2007
+ CallValidation.report_error(
2008
+ method_sig,
2009
+ message,
2010
+ 'Return value',
2011
+ nil,
2012
+ method_sig.effective_return_type,
2013
+ return_value,
2014
+ caller_offset: -1
2015
+ )
2016
+ end
2017
+ end
2018
+ return_value
2019
+ end
2020
+ end
2021
+ end
2022
+
2023
+ def self.create_validator_method_with_block4(mod, original_method, method_sig, original_visibility, return_type, block_type, arg0_type, arg1_type, arg2_type, arg3_type)
2024
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |arg0, arg1, arg2, arg3, &blk|
2025
+ # This method is a manually sped-up version of more general code in `validate_call`
2026
+ unless arg0_type.valid?(arg0)
2027
+ CallValidation.report_error(
2028
+ method_sig,
2029
+ method_sig.arg_types[0][1].error_message_for_obj(arg0),
2030
+ 'Parameter',
2031
+ method_sig.arg_types[0][0],
2032
+ arg0_type,
2033
+ arg0,
2034
+ caller_offset: -1
2035
+ )
2036
+ end
2037
+ unless arg1_type.valid?(arg1)
2038
+ CallValidation.report_error(
2039
+ method_sig,
2040
+ method_sig.arg_types[1][1].error_message_for_obj(arg1),
2041
+ 'Parameter',
2042
+ method_sig.arg_types[1][0],
2043
+ arg1_type,
2044
+ arg1,
2045
+ caller_offset: -1
2046
+ )
2047
+ end
2048
+ unless arg2_type.valid?(arg2)
2049
+ CallValidation.report_error(
2050
+ method_sig,
2051
+ method_sig.arg_types[2][1].error_message_for_obj(arg2),
2052
+ 'Parameter',
2053
+ method_sig.arg_types[2][0],
2054
+ arg2_type,
2055
+ arg2,
2056
+ caller_offset: -1
2057
+ )
2058
+ end
2059
+ unless arg3_type.valid?(arg3)
2060
+ CallValidation.report_error(
2061
+ method_sig,
2062
+ method_sig.arg_types[3][1].error_message_for_obj(arg3),
2063
+ 'Parameter',
2064
+ method_sig.arg_types[3][0],
2065
+ arg3_type,
2066
+ arg3,
2067
+ caller_offset: -1
2068
+ )
2069
+ end
2070
+ if blk.nil?
2071
+ CallValidation.report_error(
2072
+ method_sig,
2073
+ block_type.error_message_for_obj(blk),
2074
+ 'Block parameter',
2075
+ method_sig.block_name,
2076
+ block_type,
2077
+ blk,
2078
+ caller_offset: -1
2079
+ )
2080
+ end
2081
+ return_value = original_method.bind_call(self, arg0, arg1, arg2, arg3, &blk)
2082
+ if return_type.nil?
2083
+ T::Private::Types::Void::VOID
2084
+ else
2085
+ unless return_type.valid?(return_value)
2086
+ message = method_sig.effective_return_type.error_message_for_obj(return_value)
2087
+ if message
2088
+ CallValidation.report_error(
2089
+ method_sig,
2090
+ message,
2091
+ 'Return value',
2092
+ nil,
2093
+ method_sig.effective_return_type,
2094
+ return_value,
2095
+ caller_offset: -1
2096
+ )
2097
+ end
2098
+ end
2099
+ return_value
2100
+ end
2101
+ end
2102
+ end
2103
+
2104
+ def self.create_validator_method_optional_args(mod, original_method, method_sig, original_visibility)
2105
+ return_type = method_sig.effective_return_type
2106
+ return_type = nil if return_type.is_a?(T::Private::Types::Void)
2107
+ # trampoline to reduce stack frame size
2108
+ arg_types = method_sig.arg_types
2109
+ case [method_sig.req_arg_count, arg_types.length]
2110
+ when [0, 1]
2111
+ create_validator_method_optional_args0_1(mod, original_method, method_sig, original_visibility, return_type,
2112
+ arg_types[0][1])
2113
+ when [0, 2]
2114
+ create_validator_method_optional_args0_2(mod, original_method, method_sig, original_visibility, return_type,
2115
+ arg_types[0][1],
2116
+ arg_types[1][1])
2117
+ when [1, 2]
2118
+ create_validator_method_optional_args1_2(mod, original_method, method_sig, original_visibility, return_type,
2119
+ arg_types[0][1],
2120
+ arg_types[1][1])
2121
+ when [0, 3]
2122
+ create_validator_method_optional_args0_3(mod, original_method, method_sig, original_visibility, return_type,
2123
+ arg_types[0][1],
2124
+ arg_types[1][1],
2125
+ arg_types[2][1])
2126
+ when [1, 3]
2127
+ create_validator_method_optional_args1_3(mod, original_method, method_sig, original_visibility, return_type,
2128
+ arg_types[0][1],
2129
+ arg_types[1][1],
2130
+ arg_types[2][1])
2131
+ when [2, 3]
2132
+ create_validator_method_optional_args2_3(mod, original_method, method_sig, original_visibility, return_type,
2133
+ arg_types[0][1],
2134
+ arg_types[1][1],
2135
+ arg_types[2][1])
2136
+ when [0, 4]
2137
+ create_validator_method_optional_args0_4(mod, original_method, method_sig, original_visibility, return_type,
2138
+ arg_types[0][1],
2139
+ arg_types[1][1],
2140
+ arg_types[2][1],
2141
+ arg_types[3][1])
2142
+ when [1, 4]
2143
+ create_validator_method_optional_args1_4(mod, original_method, method_sig, original_visibility, return_type,
2144
+ arg_types[0][1],
2145
+ arg_types[1][1],
2146
+ arg_types[2][1],
2147
+ arg_types[3][1])
2148
+ when [2, 4]
2149
+ create_validator_method_optional_args2_4(mod, original_method, method_sig, original_visibility, return_type,
2150
+ arg_types[0][1],
2151
+ arg_types[1][1],
2152
+ arg_types[2][1],
2153
+ arg_types[3][1])
2154
+ when [3, 4]
2155
+ create_validator_method_optional_args3_4(mod, original_method, method_sig, original_visibility, return_type,
2156
+ arg_types[0][1],
2157
+ arg_types[1][1],
2158
+ arg_types[2][1],
2159
+ arg_types[3][1])
2160
+ else
2161
+ raise 'should not happen'
2162
+ end
2163
+ end
2164
+
2165
+ def self.create_validator_method_optional_args0_1(mod, original_method, method_sig, original_visibility, return_type, arg0_type)
2166
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |*args, &blk|
2167
+ # This method is a manually sped-up version of more general code in `validate_call`
2168
+ unless args.empty? || arg0_type.valid?(args[0])
2169
+ CallValidation.report_error(
2170
+ method_sig,
2171
+ method_sig.arg_types[0][1].error_message_for_obj(args[0]),
2172
+ 'Parameter',
2173
+ method_sig.arg_types[0][0],
2174
+ arg0_type,
2175
+ args[0],
2176
+ caller_offset: -1
2177
+ )
2178
+ end
2179
+ return_value = original_method.bind_call(self, *args, &blk)
2180
+ if return_type.nil?
2181
+ T::Private::Types::Void::VOID
2182
+ else
2183
+ unless return_type.valid?(return_value)
2184
+ message = method_sig.effective_return_type.error_message_for_obj(return_value)
2185
+ if message
2186
+ CallValidation.report_error(
2187
+ method_sig,
2188
+ message,
2189
+ 'Return value',
2190
+ nil,
2191
+ method_sig.effective_return_type,
2192
+ return_value,
2193
+ caller_offset: -1
2194
+ )
2195
+ end
2196
+ end
2197
+ return_value
2198
+ end
2199
+ end
2200
+ end
2201
+
2202
+ def self.create_validator_method_optional_args0_2(mod, original_method, method_sig, original_visibility, return_type, arg0_type, arg1_type)
2203
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |*args, &blk|
2204
+ # This method is a manually sped-up version of more general code in `validate_call`
2205
+ unless args.empty? || arg0_type.valid?(args[0])
2206
+ CallValidation.report_error(
2207
+ method_sig,
2208
+ method_sig.arg_types[0][1].error_message_for_obj(args[0]),
2209
+ 'Parameter',
2210
+ method_sig.arg_types[0][0],
2211
+ arg0_type,
2212
+ args[0],
2213
+ caller_offset: -1
2214
+ )
2215
+ end
2216
+ unless args.length <= 1 || arg1_type.valid?(args[1])
2217
+ CallValidation.report_error(
2218
+ method_sig,
2219
+ method_sig.arg_types[1][1].error_message_for_obj(args[1]),
2220
+ 'Parameter',
2221
+ method_sig.arg_types[1][0],
2222
+ arg1_type,
2223
+ args[1],
2224
+ caller_offset: -1
2225
+ )
2226
+ end
2227
+ return_value = original_method.bind_call(self, *args, &blk)
2228
+ if return_type.nil?
2229
+ T::Private::Types::Void::VOID
2230
+ else
2231
+ unless return_type.valid?(return_value)
2232
+ message = method_sig.effective_return_type.error_message_for_obj(return_value)
2233
+ if message
2234
+ CallValidation.report_error(
2235
+ method_sig,
2236
+ message,
2237
+ 'Return value',
2238
+ nil,
2239
+ method_sig.effective_return_type,
2240
+ return_value,
2241
+ caller_offset: -1
2242
+ )
2243
+ end
2244
+ end
2245
+ return_value
2246
+ end
2247
+ end
2248
+ end
2249
+
2250
+ def self.create_validator_method_optional_args1_2(mod, original_method, method_sig, original_visibility, return_type, arg0_type, arg1_type)
2251
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |*args, &blk|
2252
+ # This method is a manually sped-up version of more general code in `validate_call`
2253
+ unless arg0_type.valid?(args[0])
2254
+ CallValidation.report_error(
2255
+ method_sig,
2256
+ method_sig.arg_types[0][1].error_message_for_obj(args[0]),
2257
+ 'Parameter',
2258
+ method_sig.arg_types[0][0],
2259
+ arg0_type,
2260
+ args[0],
2261
+ caller_offset: -1
2262
+ )
2263
+ end
2264
+ unless args.length <= 1 || arg1_type.valid?(args[1])
2265
+ CallValidation.report_error(
2266
+ method_sig,
2267
+ method_sig.arg_types[1][1].error_message_for_obj(args[1]),
2268
+ 'Parameter',
2269
+ method_sig.arg_types[1][0],
2270
+ arg1_type,
2271
+ args[1],
2272
+ caller_offset: -1
2273
+ )
2274
+ end
2275
+ return_value = original_method.bind_call(self, *args, &blk)
2276
+ if return_type.nil?
2277
+ T::Private::Types::Void::VOID
2278
+ else
2279
+ unless return_type.valid?(return_value)
2280
+ message = method_sig.effective_return_type.error_message_for_obj(return_value)
2281
+ if message
2282
+ CallValidation.report_error(
2283
+ method_sig,
2284
+ message,
2285
+ 'Return value',
2286
+ nil,
2287
+ method_sig.effective_return_type,
2288
+ return_value,
2289
+ caller_offset: -1
2290
+ )
2291
+ end
2292
+ end
2293
+ return_value
2294
+ end
2295
+ end
2296
+ end
2297
+
2298
+ def self.create_validator_method_optional_args0_3(mod, original_method, method_sig, original_visibility, return_type, arg0_type, arg1_type, arg2_type)
2299
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |*args, &blk|
2300
+ # This method is a manually sped-up version of more general code in `validate_call`
2301
+ unless args.empty? || arg0_type.valid?(args[0])
2302
+ CallValidation.report_error(
2303
+ method_sig,
2304
+ method_sig.arg_types[0][1].error_message_for_obj(args[0]),
2305
+ 'Parameter',
2306
+ method_sig.arg_types[0][0],
2307
+ arg0_type,
2308
+ args[0],
2309
+ caller_offset: -1
2310
+ )
2311
+ end
2312
+ unless args.length <= 1 || arg1_type.valid?(args[1])
2313
+ CallValidation.report_error(
2314
+ method_sig,
2315
+ method_sig.arg_types[1][1].error_message_for_obj(args[1]),
2316
+ 'Parameter',
2317
+ method_sig.arg_types[1][0],
2318
+ arg1_type,
2319
+ args[1],
2320
+ caller_offset: -1
2321
+ )
2322
+ end
2323
+ unless args.length <= 2 || arg2_type.valid?(args[2])
2324
+ CallValidation.report_error(
2325
+ method_sig,
2326
+ method_sig.arg_types[2][1].error_message_for_obj(args[2]),
2327
+ 'Parameter',
2328
+ method_sig.arg_types[2][0],
2329
+ arg2_type,
2330
+ args[2],
2331
+ caller_offset: -1
2332
+ )
2333
+ end
2334
+ return_value = original_method.bind_call(self, *args, &blk)
2335
+ if return_type.nil?
2336
+ T::Private::Types::Void::VOID
2337
+ else
2338
+ unless return_type.valid?(return_value)
2339
+ message = method_sig.effective_return_type.error_message_for_obj(return_value)
2340
+ if message
2341
+ CallValidation.report_error(
2342
+ method_sig,
2343
+ message,
2344
+ 'Return value',
2345
+ nil,
2346
+ method_sig.effective_return_type,
2347
+ return_value,
2348
+ caller_offset: -1
2349
+ )
2350
+ end
2351
+ end
2352
+ return_value
2353
+ end
2354
+ end
2355
+ end
2356
+
2357
+ def self.create_validator_method_optional_args1_3(mod, original_method, method_sig, original_visibility, return_type, arg0_type, arg1_type, arg2_type)
2358
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |*args, &blk|
2359
+ # This method is a manually sped-up version of more general code in `validate_call`
2360
+ unless arg0_type.valid?(args[0])
2361
+ CallValidation.report_error(
2362
+ method_sig,
2363
+ method_sig.arg_types[0][1].error_message_for_obj(args[0]),
2364
+ 'Parameter',
2365
+ method_sig.arg_types[0][0],
2366
+ arg0_type,
2367
+ args[0],
2368
+ caller_offset: -1
2369
+ )
2370
+ end
2371
+ unless args.length <= 1 || arg1_type.valid?(args[1])
2372
+ CallValidation.report_error(
2373
+ method_sig,
2374
+ method_sig.arg_types[1][1].error_message_for_obj(args[1]),
2375
+ 'Parameter',
2376
+ method_sig.arg_types[1][0],
2377
+ arg1_type,
2378
+ args[1],
2379
+ caller_offset: -1
2380
+ )
2381
+ end
2382
+ unless args.length <= 2 || arg2_type.valid?(args[2])
2383
+ CallValidation.report_error(
2384
+ method_sig,
2385
+ method_sig.arg_types[2][1].error_message_for_obj(args[2]),
2386
+ 'Parameter',
2387
+ method_sig.arg_types[2][0],
2388
+ arg2_type,
2389
+ args[2],
2390
+ caller_offset: -1
2391
+ )
2392
+ end
2393
+ return_value = original_method.bind_call(self, *args, &blk)
2394
+ if return_type.nil?
2395
+ T::Private::Types::Void::VOID
2396
+ else
2397
+ unless return_type.valid?(return_value)
2398
+ message = method_sig.effective_return_type.error_message_for_obj(return_value)
2399
+ if message
2400
+ CallValidation.report_error(
2401
+ method_sig,
2402
+ message,
2403
+ 'Return value',
2404
+ nil,
2405
+ method_sig.effective_return_type,
2406
+ return_value,
2407
+ caller_offset: -1
2408
+ )
2409
+ end
2410
+ end
2411
+ return_value
2412
+ end
2413
+ end
2414
+ end
2415
+
2416
+ def self.create_validator_method_optional_args2_3(mod, original_method, method_sig, original_visibility, return_type, arg0_type, arg1_type, arg2_type)
2417
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |*args, &blk|
2418
+ # This method is a manually sped-up version of more general code in `validate_call`
2419
+ unless arg0_type.valid?(args[0])
2420
+ CallValidation.report_error(
2421
+ method_sig,
2422
+ method_sig.arg_types[0][1].error_message_for_obj(args[0]),
2423
+ 'Parameter',
2424
+ method_sig.arg_types[0][0],
2425
+ arg0_type,
2426
+ args[0],
2427
+ caller_offset: -1
2428
+ )
2429
+ end
2430
+ unless arg1_type.valid?(args[1])
2431
+ CallValidation.report_error(
2432
+ method_sig,
2433
+ method_sig.arg_types[1][1].error_message_for_obj(args[1]),
2434
+ 'Parameter',
2435
+ method_sig.arg_types[1][0],
2436
+ arg1_type,
2437
+ args[1],
2438
+ caller_offset: -1
2439
+ )
2440
+ end
2441
+ unless args.length <= 2 || arg2_type.valid?(args[2])
2442
+ CallValidation.report_error(
2443
+ method_sig,
2444
+ method_sig.arg_types[2][1].error_message_for_obj(args[2]),
2445
+ 'Parameter',
2446
+ method_sig.arg_types[2][0],
2447
+ arg2_type,
2448
+ args[2],
2449
+ caller_offset: -1
2450
+ )
2451
+ end
2452
+ return_value = original_method.bind_call(self, *args, &blk)
2453
+ if return_type.nil?
2454
+ T::Private::Types::Void::VOID
2455
+ else
2456
+ unless return_type.valid?(return_value)
2457
+ message = method_sig.effective_return_type.error_message_for_obj(return_value)
2458
+ if message
2459
+ CallValidation.report_error(
2460
+ method_sig,
2461
+ message,
2462
+ 'Return value',
2463
+ nil,
2464
+ method_sig.effective_return_type,
2465
+ return_value,
2466
+ caller_offset: -1
2467
+ )
2468
+ end
2469
+ end
2470
+ return_value
2471
+ end
2472
+ end
2473
+ end
2474
+
2475
+ def self.create_validator_method_optional_args0_4(mod, original_method, method_sig, original_visibility, return_type, arg0_type, arg1_type, arg2_type, arg3_type)
2476
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |*args, &blk|
2477
+ # This method is a manually sped-up version of more general code in `validate_call`
2478
+ unless args.empty? || arg0_type.valid?(args[0])
2479
+ CallValidation.report_error(
2480
+ method_sig,
2481
+ method_sig.arg_types[0][1].error_message_for_obj(args[0]),
2482
+ 'Parameter',
2483
+ method_sig.arg_types[0][0],
2484
+ arg0_type,
2485
+ args[0],
2486
+ caller_offset: -1
2487
+ )
2488
+ end
2489
+ unless args.length <= 1 || arg1_type.valid?(args[1])
2490
+ CallValidation.report_error(
2491
+ method_sig,
2492
+ method_sig.arg_types[1][1].error_message_for_obj(args[1]),
2493
+ 'Parameter',
2494
+ method_sig.arg_types[1][0],
2495
+ arg1_type,
2496
+ args[1],
2497
+ caller_offset: -1
2498
+ )
2499
+ end
2500
+ unless args.length <= 2 || arg2_type.valid?(args[2])
2501
+ CallValidation.report_error(
2502
+ method_sig,
2503
+ method_sig.arg_types[2][1].error_message_for_obj(args[2]),
2504
+ 'Parameter',
2505
+ method_sig.arg_types[2][0],
2506
+ arg2_type,
2507
+ args[2],
2508
+ caller_offset: -1
2509
+ )
2510
+ end
2511
+ unless args.length <= 3 || arg3_type.valid?(args[3])
2512
+ CallValidation.report_error(
2513
+ method_sig,
2514
+ method_sig.arg_types[3][1].error_message_for_obj(args[3]),
2515
+ 'Parameter',
2516
+ method_sig.arg_types[3][0],
2517
+ arg3_type,
2518
+ args[3],
2519
+ caller_offset: -1
2520
+ )
2521
+ end
2522
+ return_value = original_method.bind_call(self, *args, &blk)
2523
+ if return_type.nil?
2524
+ T::Private::Types::Void::VOID
2525
+ else
2526
+ unless return_type.valid?(return_value)
2527
+ message = method_sig.effective_return_type.error_message_for_obj(return_value)
2528
+ if message
2529
+ CallValidation.report_error(
2530
+ method_sig,
2531
+ message,
2532
+ 'Return value',
2533
+ nil,
2534
+ method_sig.effective_return_type,
2535
+ return_value,
2536
+ caller_offset: -1
2537
+ )
2538
+ end
2539
+ end
2540
+ return_value
2541
+ end
2542
+ end
2543
+ end
2544
+
2545
+ def self.create_validator_method_optional_args1_4(mod, original_method, method_sig, original_visibility, return_type, arg0_type, arg1_type, arg2_type, arg3_type)
2546
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |*args, &blk|
2547
+ # This method is a manually sped-up version of more general code in `validate_call`
2548
+ unless arg0_type.valid?(args[0])
2549
+ CallValidation.report_error(
2550
+ method_sig,
2551
+ method_sig.arg_types[0][1].error_message_for_obj(args[0]),
2552
+ 'Parameter',
2553
+ method_sig.arg_types[0][0],
2554
+ arg0_type,
2555
+ args[0],
2556
+ caller_offset: -1
2557
+ )
2558
+ end
2559
+ unless args.length <= 1 || arg1_type.valid?(args[1])
2560
+ CallValidation.report_error(
2561
+ method_sig,
2562
+ method_sig.arg_types[1][1].error_message_for_obj(args[1]),
2563
+ 'Parameter',
2564
+ method_sig.arg_types[1][0],
2565
+ arg1_type,
2566
+ args[1],
2567
+ caller_offset: -1
2568
+ )
2569
+ end
2570
+ unless args.length <= 2 || arg2_type.valid?(args[2])
2571
+ CallValidation.report_error(
2572
+ method_sig,
2573
+ method_sig.arg_types[2][1].error_message_for_obj(args[2]),
2574
+ 'Parameter',
2575
+ method_sig.arg_types[2][0],
2576
+ arg2_type,
2577
+ args[2],
2578
+ caller_offset: -1
2579
+ )
2580
+ end
2581
+ unless args.length <= 3 || arg3_type.valid?(args[3])
2582
+ CallValidation.report_error(
2583
+ method_sig,
2584
+ method_sig.arg_types[3][1].error_message_for_obj(args[3]),
2585
+ 'Parameter',
2586
+ method_sig.arg_types[3][0],
2587
+ arg3_type,
2588
+ args[3],
2589
+ caller_offset: -1
2590
+ )
2591
+ end
2592
+ return_value = original_method.bind_call(self, *args, &blk)
2593
+ if return_type.nil?
2594
+ T::Private::Types::Void::VOID
2595
+ else
2596
+ unless return_type.valid?(return_value)
2597
+ message = method_sig.effective_return_type.error_message_for_obj(return_value)
2598
+ if message
2599
+ CallValidation.report_error(
2600
+ method_sig,
2601
+ message,
2602
+ 'Return value',
2603
+ nil,
2604
+ method_sig.effective_return_type,
2605
+ return_value,
2606
+ caller_offset: -1
2607
+ )
2608
+ end
2609
+ end
2610
+ return_value
2611
+ end
2612
+ end
2613
+ end
2614
+
2615
+ def self.create_validator_method_optional_args2_4(mod, original_method, method_sig, original_visibility, return_type, arg0_type, arg1_type, arg2_type, arg3_type)
2616
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |*args, &blk|
2617
+ # This method is a manually sped-up version of more general code in `validate_call`
2618
+ unless arg0_type.valid?(args[0])
2619
+ CallValidation.report_error(
2620
+ method_sig,
2621
+ method_sig.arg_types[0][1].error_message_for_obj(args[0]),
2622
+ 'Parameter',
2623
+ method_sig.arg_types[0][0],
2624
+ arg0_type,
2625
+ args[0],
2626
+ caller_offset: -1
2627
+ )
2628
+ end
2629
+ unless arg1_type.valid?(args[1])
2630
+ CallValidation.report_error(
2631
+ method_sig,
2632
+ method_sig.arg_types[1][1].error_message_for_obj(args[1]),
2633
+ 'Parameter',
2634
+ method_sig.arg_types[1][0],
2635
+ arg1_type,
2636
+ args[1],
2637
+ caller_offset: -1
2638
+ )
2639
+ end
2640
+ unless args.length <= 2 || arg2_type.valid?(args[2])
2641
+ CallValidation.report_error(
2642
+ method_sig,
2643
+ method_sig.arg_types[2][1].error_message_for_obj(args[2]),
2644
+ 'Parameter',
2645
+ method_sig.arg_types[2][0],
2646
+ arg2_type,
2647
+ args[2],
2648
+ caller_offset: -1
2649
+ )
2650
+ end
2651
+ unless args.length <= 3 || arg3_type.valid?(args[3])
2652
+ CallValidation.report_error(
2653
+ method_sig,
2654
+ method_sig.arg_types[3][1].error_message_for_obj(args[3]),
2655
+ 'Parameter',
2656
+ method_sig.arg_types[3][0],
2657
+ arg3_type,
2658
+ args[3],
2659
+ caller_offset: -1
2660
+ )
2661
+ end
2662
+ return_value = original_method.bind_call(self, *args, &blk)
2663
+ if return_type.nil?
2664
+ T::Private::Types::Void::VOID
2665
+ else
2666
+ unless return_type.valid?(return_value)
2667
+ message = method_sig.effective_return_type.error_message_for_obj(return_value)
2668
+ if message
2669
+ CallValidation.report_error(
2670
+ method_sig,
2671
+ message,
2672
+ 'Return value',
2673
+ nil,
2674
+ method_sig.effective_return_type,
2675
+ return_value,
2676
+ caller_offset: -1
2677
+ )
2678
+ end
2679
+ end
2680
+ return_value
2681
+ end
2682
+ end
2683
+ end
2684
+
2685
+ def self.create_validator_method_optional_args3_4(mod, original_method, method_sig, original_visibility, return_type, arg0_type, arg1_type, arg2_type, arg3_type)
2686
+ T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |*args, &blk|
2687
+ # This method is a manually sped-up version of more general code in `validate_call`
2688
+ unless arg0_type.valid?(args[0])
2689
+ CallValidation.report_error(
2690
+ method_sig,
2691
+ method_sig.arg_types[0][1].error_message_for_obj(args[0]),
2692
+ 'Parameter',
2693
+ method_sig.arg_types[0][0],
2694
+ arg0_type,
2695
+ args[0],
2696
+ caller_offset: -1
2697
+ )
2698
+ end
2699
+ unless arg1_type.valid?(args[1])
2700
+ CallValidation.report_error(
2701
+ method_sig,
2702
+ method_sig.arg_types[1][1].error_message_for_obj(args[1]),
2703
+ 'Parameter',
2704
+ method_sig.arg_types[1][0],
2705
+ arg1_type,
2706
+ args[1],
2707
+ caller_offset: -1
2708
+ )
2709
+ end
2710
+ unless arg2_type.valid?(args[2])
2711
+ CallValidation.report_error(
2712
+ method_sig,
2713
+ method_sig.arg_types[2][1].error_message_for_obj(args[2]),
2714
+ 'Parameter',
2715
+ method_sig.arg_types[2][0],
2716
+ arg2_type,
2717
+ args[2],
2718
+ caller_offset: -1
2719
+ )
2720
+ end
2721
+ unless args.length <= 3 || arg3_type.valid?(args[3])
2722
+ CallValidation.report_error(
2723
+ method_sig,
2724
+ method_sig.arg_types[3][1].error_message_for_obj(args[3]),
2725
+ 'Parameter',
2726
+ method_sig.arg_types[3][0],
2727
+ arg3_type,
2728
+ args[3],
2729
+ caller_offset: -1
2730
+ )
2731
+ end
2732
+ return_value = original_method.bind_call(self, *args, &blk)
2733
+ if return_type.nil?
2734
+ T::Private::Types::Void::VOID
2735
+ else
2736
+ unless return_type.valid?(return_value)
2737
+ message = method_sig.effective_return_type.error_message_for_obj(return_value)
2738
+ if message
2739
+ CallValidation.report_error(
2740
+ method_sig,
2741
+ message,
2742
+ 'Return value',
2743
+ nil,
2744
+ method_sig.effective_return_type,
2745
+ return_value,
2746
+ caller_offset: -1
2747
+ )
2748
+ end
2749
+ end
2750
+ return_value
2751
+ end
2752
+ end
2753
+ end
2754
+
1729
2755
  end
@@ -67,7 +67,9 @@ module T::Private::Methods::SignatureValidation
67
67
  super_method = signature.method.super_method
68
68
 
69
69
  if super_method && super_method.owner != signature.method.owner
70
- Methods.maybe_run_sig_block_for_method(super_method)
70
+ # No need to run the sig block for super_method explicitly:
71
+ # signature_for_method forces it internally (via signature_for_key ->
72
+ # maybe_run_sig_block_for_key on the identical registry key).
71
73
  super_signature = Methods.signature_for_method(super_method)
72
74
 
73
75
  # If the super_method has any kwargs we can't build a
@@ -200,7 +202,10 @@ module T::Private::Methods::SignatureValidation
200
202
  "#{base_override_loc_str(signature, super_signature)}"
201
203
  end
202
204
 
203
- if signature.keyrest_type.nil?
205
+ # The kwarg_types.empty? guard is an exact implication (an empty super
206
+ # kwarg set can never yield missing kwargs) that skips two fresh
207
+ # `.keys` arrays plus the Array#- for the common kwarg-free method.
208
+ if signature.keyrest_type.nil? && !super_signature.kwarg_types.empty?
204
209
  # O(nm), but n and m are tiny here
205
210
  missing_kwargs = super_signature.kwarg_names - signature.kwarg_names
206
211
  if !missing_kwargs.empty?
@@ -216,12 +221,15 @@ module T::Private::Methods::SignatureValidation
216
221
  "#{base_override_loc_str(signature, super_signature)}"
217
222
  end
218
223
 
219
- # O(nm), but n and m are tiny here
220
- extra_req_kwargs = signature.req_kwarg_names - super_signature.req_kwarg_names
221
- if !extra_req_kwargs.empty?
222
- raise "Your definition of `#{method_name}` has extra required keyword arg(s) " \
223
- "#{extra_req_kwargs} relative to the method it #{mode_verb}, making it incompatible: " \
224
- "#{base_override_loc_str(signature, super_signature)}"
224
+ # Guard on the minuend: an empty req_kwarg_names can never yield extras.
225
+ if !signature.req_kwarg_names.empty?
226
+ # O(nm), but n and m are tiny here
227
+ extra_req_kwargs = signature.req_kwarg_names - super_signature.req_kwarg_names
228
+ if !extra_req_kwargs.empty?
229
+ raise "Your definition of `#{method_name}` has extra required keyword arg(s) " \
230
+ "#{extra_req_kwargs} relative to the method it #{mode_verb}, making it incompatible: " \
231
+ "#{base_override_loc_str(signature, super_signature)}"
232
+ end
225
233
  end
226
234
 
227
235
  if super_signature.block_name && !signature.block_name
@@ -231,16 +239,33 @@ module T::Private::Methods::SignatureValidation
231
239
  end
232
240
  end
233
241
 
242
+ # Evaluation order matters: check_tests? must only run for a :tests-checked
243
+ # sig (it side-effectfully arms the @wrapped_tests_with_validation trapdoor
244
+ # in RuntimeLevels).
245
+ private_class_method def self.check_level_active?(sig)
246
+ sig.check_level == :always || (sig.check_level == :tests && T::Private::RuntimeLevels.check_tests?)
247
+ end
248
+
234
249
  def self.validate_override_types(signature, super_signature)
235
250
  return if signature.override_allow_incompatible == true
236
251
  return if super_signature.mode == Modes.untyped
237
- return unless [signature, super_signature].all? do |sig|
238
- sig.check_level == :always || (sig.check_level == :tests && T::Private::RuntimeLevels.check_tests?)
239
- end
252
+ return unless check_level_active?(signature) && check_level_active?(super_signature)
240
253
  mode_noun = super_signature.mode == Modes.abstract ? 'implementation' : 'override'
241
254
 
242
255
  # arg types must be contravariant
243
- super_signature.arg_types.zip(signature.arg_types).each_with_index do |((_super_name, super_type), (name, type)), index|
256
+ #
257
+ # An index loop avoids allocating a pair array per positional arg.
258
+ # Iterating to super's length is deliberate: extra override positionals
259
+ # go unchecked, and when the override has a rest param and fewer named
260
+ # args than the base, the missing positions are checked as nil name/type.
261
+ super_arg_types = super_signature.arg_types
262
+ arg_types = signature.arg_types
263
+ index = 0
264
+ while index < super_arg_types.length
265
+ super_type = super_arg_types.fetch(index)[1]
266
+ pair = arg_types[index]
267
+ name = pair && pair[0]
268
+ type = pair && pair[1]
244
269
  if !super_type.subtype_of?(type)
245
270
  raise "Incompatible type for arg ##{index + 1} (`#{name}`) in signature for #{mode_noun} of method " \
246
271
  "`#{signature.method_name}`:\n" \
@@ -248,6 +273,7 @@ module T::Private::Methods::SignatureValidation
248
273
  "* #{mode_noun.capitalize}: `#{type}` (in #{signature.method_desc})\n" \
249
274
  "(The types must be contravariant.)"
250
275
  end
276
+ index += 1
251
277
  end
252
278
 
253
279
  # kwarg types must be contravariant
@@ -52,6 +52,16 @@ module T::Types
52
52
  def subtype_of?(t2)
53
53
  t1 = self
54
54
 
55
+ # Fast path over the isSubType mirror below: the dominant pair during
56
+ # override validation is two plain Simples, which match none of the
57
+ # branches in the walk. instance_of? (never
58
+ # is_a?) so that any hypothetical Simple subclass takes the full walk,
59
+ # and the raw subtype_of_single? result is returned unmodified
60
+ # (Module#<= yields nil for unrelated modules, which callers observe).
61
+ if t1.instance_of?(T::Types::Simple) && t2.instance_of?(T::Types::Simple)
62
+ return subtype_of_single?(t2)
63
+ end
64
+
55
65
  if t2.is_a?(T::Private::Types::TypeAlias)
56
66
  t2 = t2.aliased_type
57
67
  end
@@ -3,6 +3,11 @@
3
3
 
4
4
  module T::Types
5
5
  class TypedSet < TypedEnumerable
6
+ # We can reference `Set` directly without a load guard: as of Ruby 3.2 it
7
+ # ships as a default-autoloaded constant (Ruby registers `autoload :Set,
8
+ # "set"`), so the first reference here transparently loads it. Ruby 3.3 --
9
+ # the most recently supported release -- keeps this behavior, and Ruby 3.1
10
+ # and earlier (which required an explicit `require "set"`) are past EOL.
6
11
  def underlying_class
7
12
  Set
8
13
  end
@@ -14,22 +19,15 @@ module T::Types
14
19
 
15
20
  # overrides Base
16
21
  def recursively_valid?(obj)
17
- return false if Object.autoload?(:Set) # Set is meant to be autoloaded but not yet loaded, this value can't be a Set
18
- return false unless Object.const_defined?(:Set) # Set is not loaded yet
19
22
  obj.is_a?(Set) && super
20
23
  end
21
24
 
22
25
  # overrides Base
23
26
  def valid?(obj)
24
- return false if Object.autoload?(:Set) # Set is meant to be autoloaded but not yet loaded, this value can't be a Set
25
- return false unless Object.const_defined?(:Set) # Set is not loaded yet
26
27
  obj.is_a?(Set)
27
28
  end
28
29
 
29
30
  def new(...)
30
- # Fine for this to blow up, because hopefully if they're trying to make a
31
- # Set, they don't mind putting (or already have put) a `require 'set'` in
32
- # their program directly.
33
31
  Set.new(...)
34
32
  end
35
33
 
@@ -39,8 +37,6 @@ module T::Types
39
37
  end
40
38
 
41
39
  def valid?(obj)
42
- return false if Object.autoload?(:Set) # Set is meant to be autoloaded but not yet loaded, this value can't be a Set
43
- return false unless Object.const_defined?(:Set) # Set is not loaded yet
44
40
  obj.is_a?(Set)
45
41
  end
46
42
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sorbet-runtime
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.13300
4
+ version: 0.6.13301
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe