tapioca 0.19.0 → 0.19.1
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/tapioca/commands/abstract_dsl.rb +1 -1
- data/lib/tapioca/commands/check_shims.rb +3 -0
- data/lib/tapioca/commands/configure.rb +1 -0
- data/lib/tapioca/commands/todo.rb +8 -2
- data/lib/tapioca/dsl/compiler.rb +13 -13
- data/lib/tapioca/dsl/compilers/aasm.rb +1 -1
- data/lib/tapioca/dsl/compilers/action_controller_helpers.rb +2 -2
- data/lib/tapioca/dsl/compilers/action_mailer.rb +1 -1
- data/lib/tapioca/dsl/compilers/action_text.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_job.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_model_attributes.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_model_secure_password.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_model_validations_confirmation.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_record_associations.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_record_columns.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_record_delegated_types.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_record_enum.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_record_fixtures.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_record_relations.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_record_scope.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_record_secure_token.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_record_store.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_record_typed_store.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_resource.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_storage.rb +2 -2
- data/lib/tapioca/dsl/compilers/active_support_concern.rb +6 -6
- data/lib/tapioca/dsl/compilers/active_support_current_attributes.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_support_environment_inquirer.rb +1 -1
- data/lib/tapioca/dsl/compilers/active_support_time_ext.rb +1 -1
- data/lib/tapioca/dsl/compilers/config.rb +2 -2
- data/lib/tapioca/dsl/compilers/frozen_record.rb +1 -1
- data/lib/tapioca/dsl/compilers/graphql_input_object.rb +1 -1
- data/lib/tapioca/dsl/compilers/graphql_mutation.rb +1 -1
- data/lib/tapioca/dsl/compilers/identity_cache.rb +2 -2
- data/lib/tapioca/dsl/compilers/json_api_client_resource.rb +1 -1
- data/lib/tapioca/dsl/compilers/kredis.rb +1 -1
- data/lib/tapioca/dsl/compilers/mixed_in_class_attributes.rb +2 -2
- data/lib/tapioca/dsl/compilers/protobuf.rb +1 -1
- data/lib/tapioca/dsl/compilers/rails_generators.rb +1 -1
- data/lib/tapioca/dsl/compilers/sidekiq_worker.rb +1 -1
- data/lib/tapioca/dsl/compilers/smart_properties.rb +1 -1
- data/lib/tapioca/dsl/compilers/state_machines.rb +2 -2
- data/lib/tapioca/dsl/compilers/url_helpers.rb +7 -7
- data/lib/tapioca/dsl/helpers/graphql_type_helper.rb +1 -1
- data/lib/tapioca/dsl/pipeline.rb +10 -10
- data/lib/tapioca/gem/events.rb +7 -7
- data/lib/tapioca/gem/listeners/methods.rb +8 -8
- data/lib/tapioca/gem/listeners/mixins.rb +3 -3
- data/lib/tapioca/gem/listeners/sorbet_signatures.rb +5 -3
- data/lib/tapioca/gem/listeners/sorbet_type_variables.rb +1 -1
- data/lib/tapioca/gem/pipeline.rb +18 -18
- data/lib/tapioca/helpers/sorbet_helper.rb +19 -0
- data/lib/tapioca/helpers/test/dsl_compiler.rb +2 -9
- data/lib/tapioca/internal.rb +1 -0
- data/lib/tapioca/rbi_ext/model.rb +8 -5
- data/lib/tapioca/runtime/dynamic_mixin_compiler.rb +6 -6
- data/lib/tapioca/runtime/generic_type_registry.rb +8 -8
- data/lib/tapioca/runtime/reflection.rb +20 -20
- data/lib/tapioca/runtime/trackers/constant_definition.rb +3 -3
- data/lib/tapioca/runtime/trackers/method_definition.rb +4 -4
- data/lib/tapioca/runtime/trackers/mixin.rb +5 -5
- data/lib/tapioca/runtime/trackers/required_ancestor.rb +2 -2
- data/lib/tapioca/runtime/trackers/tracker.rb +1 -1
- data/lib/tapioca/sorbet_ext/generic_name_patch.rb +1 -1
- data/lib/tapioca/sorbet_ext/void_patch.rb +29 -0
- data/lib/tapioca/static/symbol_loader.rb +19 -1
- data/lib/tapioca/version.rb +1 -1
- metadata +5 -4
|
@@ -78,7 +78,7 @@ module Tapioca
|
|
|
78
78
|
# include GeneratedUrlHelpersModule
|
|
79
79
|
# end
|
|
80
80
|
# ~~~
|
|
81
|
-
#: [ConstantType =
|
|
81
|
+
#: [ConstantType = Module[top]]
|
|
82
82
|
class UrlHelpers < Compiler
|
|
83
83
|
# @override
|
|
84
84
|
#: -> void
|
|
@@ -96,7 +96,7 @@ module Tapioca
|
|
|
96
96
|
|
|
97
97
|
class << self
|
|
98
98
|
# @override
|
|
99
|
-
#: -> Enumerable[
|
|
99
|
+
#: -> Enumerable[Module[top]]
|
|
100
100
|
def gather_constants
|
|
101
101
|
return [] unless defined?(Rails.application) && Rails.application
|
|
102
102
|
|
|
@@ -128,7 +128,7 @@ module Tapioca
|
|
|
128
128
|
constants.concat(NON_DISCOVERABLE_INCLUDERS).push(GeneratedUrlHelpersModule, GeneratedPathHelpersModule)
|
|
129
129
|
end
|
|
130
130
|
|
|
131
|
-
#: -> Array[
|
|
131
|
+
#: -> Array[Module[top]]
|
|
132
132
|
def gather_non_discoverable_includers
|
|
133
133
|
[].tap do |includers|
|
|
134
134
|
if defined?(ActionController::TemplateAssertions) && defined?(ActionDispatch::IntegrationTest)
|
|
@@ -143,7 +143,7 @@ module Tapioca
|
|
|
143
143
|
|
|
144
144
|
# Returns `true` if `mod` "directly" includes `helper`.
|
|
145
145
|
# For classes, this method will return false if the `helper` is included only by a superclass
|
|
146
|
-
#: (
|
|
146
|
+
#: (Module[top] mod, Module[top] helper) -> bool
|
|
147
147
|
private def includes_helper?(mod, helper)
|
|
148
148
|
ancestors = ancestors_of(mod)
|
|
149
149
|
|
|
@@ -158,11 +158,11 @@ module Tapioca
|
|
|
158
158
|
end
|
|
159
159
|
end
|
|
160
160
|
|
|
161
|
-
NON_DISCOVERABLE_INCLUDERS = gather_non_discoverable_includers #: Array[
|
|
161
|
+
NON_DISCOVERABLE_INCLUDERS = gather_non_discoverable_includers #: Array[Module[top]]
|
|
162
162
|
|
|
163
163
|
private
|
|
164
164
|
|
|
165
|
-
#: (RBI::Tree root,
|
|
165
|
+
#: (RBI::Tree root, Module[top] constant) -> void
|
|
166
166
|
def generate_module_for(root, constant)
|
|
167
167
|
root.create_module(T.must(constant.name)) do |mod|
|
|
168
168
|
mod.create_include("::ActionDispatch::Routing::UrlFor")
|
|
@@ -178,7 +178,7 @@ module Tapioca
|
|
|
178
178
|
end
|
|
179
179
|
end
|
|
180
180
|
|
|
181
|
-
#: (RBI::Scope mod,
|
|
181
|
+
#: (RBI::Scope mod, Module[top] helper_module) -> void
|
|
182
182
|
def create_mixins_for(mod, helper_module)
|
|
183
183
|
include_helper = constant.ancestors.include?(helper_module) || NON_DISCOVERABLE_INCLUDERS.include?(constant)
|
|
184
184
|
extend_helper = constant.singleton_class.ancestors.include?(helper_module)
|
|
@@ -110,7 +110,7 @@ module Tapioca
|
|
|
110
110
|
|
|
111
111
|
private
|
|
112
112
|
|
|
113
|
-
#: (
|
|
113
|
+
#: (Module[top] constant) -> String
|
|
114
114
|
def type_for_constant(constant)
|
|
115
115
|
if constant.instance_methods.include?(:prepare)
|
|
116
116
|
prepare_method = constant.instance_method(:prepare)
|
data/lib/tapioca/dsl/pipeline.rb
CHANGED
|
@@ -7,13 +7,13 @@ module Tapioca
|
|
|
7
7
|
#: Enumerable[singleton(Compiler)]
|
|
8
8
|
attr_reader :active_compilers
|
|
9
9
|
|
|
10
|
-
#: Array[
|
|
10
|
+
#: Array[Module[top]]
|
|
11
11
|
attr_reader :requested_constants
|
|
12
12
|
|
|
13
13
|
#: Array[Pathname]
|
|
14
14
|
attr_reader :requested_paths
|
|
15
15
|
|
|
16
|
-
#: Array[
|
|
16
|
+
#: Array[Module[top]]
|
|
17
17
|
attr_reader :skipped_constants
|
|
18
18
|
|
|
19
19
|
#: ^(String error) -> void
|
|
@@ -23,12 +23,12 @@ module Tapioca
|
|
|
23
23
|
attr_reader :errors
|
|
24
24
|
|
|
25
25
|
#: (
|
|
26
|
-
#| requested_constants: Array[
|
|
26
|
+
#| requested_constants: Array[Module[top]],
|
|
27
27
|
#| ?requested_paths: Array[Pathname],
|
|
28
28
|
#| ?requested_compilers: Array[singleton(Compiler)],
|
|
29
29
|
#| ?excluded_compilers: Array[singleton(Compiler)],
|
|
30
30
|
#| ?error_handler: ^(String error) -> void,
|
|
31
|
-
#| ?skipped_constants: Array[
|
|
31
|
+
#| ?skipped_constants: Array[Module[top]],
|
|
32
32
|
#| ?number_of_workers: Integer?,
|
|
33
33
|
#| ?compiler_options: Hash[String, untyped],
|
|
34
34
|
#| ?lsp_addon: bool
|
|
@@ -56,7 +56,7 @@ module Tapioca
|
|
|
56
56
|
@errors = [] #: Array[String]
|
|
57
57
|
end
|
|
58
58
|
|
|
59
|
-
#: [R] { (
|
|
59
|
+
#: [R] { (Module[top] constant, RBI::File rbi) -> R } -> Array[R]
|
|
60
60
|
def run(&blk)
|
|
61
61
|
constants_to_process = gather_constants(requested_constants, requested_paths, skipped_constants)
|
|
62
62
|
.select { |c| Module === c } # Filter value constants out
|
|
@@ -128,10 +128,10 @@ module Tapioca
|
|
|
128
128
|
end
|
|
129
129
|
|
|
130
130
|
#: (
|
|
131
|
-
#| Array[
|
|
131
|
+
#| Array[Module[top]] requested_constants,
|
|
132
132
|
#| Array[Pathname] requested_paths,
|
|
133
|
-
#| Array[
|
|
134
|
-
#| ) -> Set[
|
|
133
|
+
#| Array[Module[top]] skipped_constants
|
|
134
|
+
#| ) -> Set[Module[top]]
|
|
135
135
|
def gather_constants(requested_constants, requested_paths, skipped_constants)
|
|
136
136
|
Compiler.requested_constants = requested_constants
|
|
137
137
|
constants = Set.new.compare_by_identity
|
|
@@ -153,7 +153,7 @@ module Tapioca
|
|
|
153
153
|
constants
|
|
154
154
|
end
|
|
155
155
|
|
|
156
|
-
#: (Set[
|
|
156
|
+
#: (Set[Module[top]] constants) -> Set[Module[top]]
|
|
157
157
|
def filter_anonymous_and_reloaded_constants(constants)
|
|
158
158
|
# Group constants by their names
|
|
159
159
|
constants_by_name = constants
|
|
@@ -182,7 +182,7 @@ module Tapioca
|
|
|
182
182
|
Set.new.compare_by_identity.merge(filtered_constants)
|
|
183
183
|
end
|
|
184
184
|
|
|
185
|
-
#: (
|
|
185
|
+
#: (Module[top] constant) -> RBI::File?
|
|
186
186
|
def rbi_for_constant(constant)
|
|
187
187
|
file = RBI::File.new(strictness: "true")
|
|
188
188
|
|
data/lib/tapioca/gem/events.rb
CHANGED
|
@@ -37,12 +37,12 @@ module Tapioca
|
|
|
37
37
|
|
|
38
38
|
class ForeignConstantFound < ConstantFound
|
|
39
39
|
# @override
|
|
40
|
-
#: ->
|
|
40
|
+
#: -> Module[top]
|
|
41
41
|
def constant
|
|
42
42
|
T.cast(@constant, T::Module[T.anything])
|
|
43
43
|
end
|
|
44
44
|
|
|
45
|
-
#: (String symbol,
|
|
45
|
+
#: (String symbol, Module[top] constant) -> void
|
|
46
46
|
def initialize(symbol, constant)
|
|
47
47
|
super
|
|
48
48
|
end
|
|
@@ -53,10 +53,10 @@ module Tapioca
|
|
|
53
53
|
#: String
|
|
54
54
|
attr_reader :symbol
|
|
55
55
|
|
|
56
|
-
#:
|
|
56
|
+
#: Module[top]
|
|
57
57
|
attr_reader :constant
|
|
58
58
|
|
|
59
|
-
#: (String symbol,
|
|
59
|
+
#: (String symbol, Module[top] constant) -> void
|
|
60
60
|
def initialize(symbol, constant)
|
|
61
61
|
super()
|
|
62
62
|
@symbol = symbol
|
|
@@ -68,7 +68,7 @@ module Tapioca
|
|
|
68
68
|
#: RBI::Const
|
|
69
69
|
attr_reader :node
|
|
70
70
|
|
|
71
|
-
#: (String symbol,
|
|
71
|
+
#: (String symbol, Module[top] constant, RBI::Const node) -> void
|
|
72
72
|
def initialize(symbol, constant, node)
|
|
73
73
|
super(symbol, constant)
|
|
74
74
|
@node = node
|
|
@@ -79,7 +79,7 @@ module Tapioca
|
|
|
79
79
|
#: RBI::Scope
|
|
80
80
|
attr_reader :node
|
|
81
81
|
|
|
82
|
-
#: (String symbol,
|
|
82
|
+
#: (String symbol, Module[top] constant, RBI::Scope node) -> void
|
|
83
83
|
def initialize(symbol, constant, node)
|
|
84
84
|
super(symbol, constant)
|
|
85
85
|
@node = node
|
|
@@ -103,7 +103,7 @@ module Tapioca
|
|
|
103
103
|
|
|
104
104
|
#: (
|
|
105
105
|
#| String symbol,
|
|
106
|
-
#|
|
|
106
|
+
#| Module[top] constant,
|
|
107
107
|
#| UnboundMethod method,
|
|
108
108
|
#| RBI::Method node,
|
|
109
109
|
#| untyped signature,
|
|
@@ -25,9 +25,9 @@ module Tapioca
|
|
|
25
25
|
#: (
|
|
26
26
|
#| RBI::Tree tree,
|
|
27
27
|
#| String module_name,
|
|
28
|
-
#|
|
|
28
|
+
#| Module[top] mod,
|
|
29
29
|
#| ?Array[Symbol] for_visibility,
|
|
30
|
-
#| ?attached_class:
|
|
30
|
+
#| ?attached_class: Module[top]?
|
|
31
31
|
#| ) -> void
|
|
32
32
|
def compile_directly_owned_methods(
|
|
33
33
|
tree,
|
|
@@ -59,7 +59,7 @@ module Tapioca
|
|
|
59
59
|
#: (
|
|
60
60
|
#| RBI::Tree tree,
|
|
61
61
|
#| String symbol_name,
|
|
62
|
-
#|
|
|
62
|
+
#| Module[top] constant,
|
|
63
63
|
#| UnboundMethod? method,
|
|
64
64
|
#| ?RBI::Visibility visibility
|
|
65
65
|
#| ) -> void
|
|
@@ -169,7 +169,7 @@ module Tapioca
|
|
|
169
169
|
# This method implements a better way of checking whether a constant defines a method.
|
|
170
170
|
# It walks up the ancestor tree via the `super_method` method; if any of the super
|
|
171
171
|
# methods are owned by the constant, it means that the constant declares the method.
|
|
172
|
-
#: (UnboundMethod method,
|
|
172
|
+
#: (UnboundMethod method, Module[top] constant) -> bool
|
|
173
173
|
def method_owned_by_constant?(method, constant)
|
|
174
174
|
# Widen the type of `method` to be nilable
|
|
175
175
|
method = method #: UnboundMethod?
|
|
@@ -183,7 +183,7 @@ module Tapioca
|
|
|
183
183
|
false
|
|
184
184
|
end
|
|
185
185
|
|
|
186
|
-
#: (
|
|
186
|
+
#: (Module[top] mod) -> Hash[Symbol, Array[Symbol]]
|
|
187
187
|
def method_names_by_visibility(mod)
|
|
188
188
|
{
|
|
189
189
|
public: public_instance_methods_of(mod),
|
|
@@ -192,7 +192,7 @@ module Tapioca
|
|
|
192
192
|
}
|
|
193
193
|
end
|
|
194
194
|
|
|
195
|
-
#: (
|
|
195
|
+
#: (Module[top] constant, String method_name) -> bool
|
|
196
196
|
def struct_method?(constant, method_name)
|
|
197
197
|
return false unless T::Props::ClassMethods === constant
|
|
198
198
|
|
|
@@ -202,7 +202,7 @@ module Tapioca
|
|
|
202
202
|
.include?(method_name.gsub(/=$/, "").to_sym)
|
|
203
203
|
end
|
|
204
204
|
|
|
205
|
-
#: (
|
|
205
|
+
#: (Module[top]? attached_class, Symbol method_name) -> bool?
|
|
206
206
|
def method_new_in_abstract_class?(attached_class, method_name)
|
|
207
207
|
attached_class &&
|
|
208
208
|
method_name == :new &&
|
|
@@ -210,7 +210,7 @@ module Tapioca
|
|
|
210
210
|
Class === attached_class.singleton_class
|
|
211
211
|
end
|
|
212
212
|
|
|
213
|
-
#: (
|
|
213
|
+
#: (Module[top] constant) -> UnboundMethod?
|
|
214
214
|
def initialize_method_for(constant)
|
|
215
215
|
constant.instance_method(:initialize)
|
|
216
216
|
rescue
|
|
@@ -30,7 +30,7 @@ module Tapioca
|
|
|
30
30
|
add_mixins(node, constant, extends.reverse, Runtime::Trackers::Mixin::Type::Extend)
|
|
31
31
|
end
|
|
32
32
|
|
|
33
|
-
#: (RBI::Tree tree,
|
|
33
|
+
#: (RBI::Tree tree, Module[top] constant, Array[Module[top]] mods, Runtime::Trackers::Mixin::Type mixin_type) -> void
|
|
34
34
|
def add_mixins(tree, constant, mods, mixin_type)
|
|
35
35
|
mods
|
|
36
36
|
.select do |mod|
|
|
@@ -57,7 +57,7 @@ module Tapioca
|
|
|
57
57
|
end
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
-
#: (
|
|
60
|
+
#: (Module[top] constant, Module[top] mixin, Runtime::Trackers::Mixin::Type mixin_type) -> bool
|
|
61
61
|
def mixed_in_by_gem?(constant, mixin, mixin_type)
|
|
62
62
|
mixin_location = Runtime::Trackers::Mixin.mixin_location(mixin, mixin_type, constant)
|
|
63
63
|
|
|
@@ -73,7 +73,7 @@ module Tapioca
|
|
|
73
73
|
mixin_name.start_with?("T::") && !mixin_name.start_with?("T::Props")
|
|
74
74
|
end
|
|
75
75
|
|
|
76
|
-
#: (
|
|
76
|
+
#: (Module[top] constant) -> Array[Module[top]]
|
|
77
77
|
def interesting_ancestors_of(constant)
|
|
78
78
|
inherited_ancestors = Set.new.compare_by_identity.merge(inherited_ancestors_of(constant))
|
|
79
79
|
|
|
@@ -23,8 +23,10 @@ module Tapioca
|
|
|
23
23
|
def compile_signature(signature, parameters)
|
|
24
24
|
parameter_types = signature.arg_types.to_h #: Hash[Symbol, T::Types::Base]
|
|
25
25
|
parameter_types.merge!(signature.kwarg_types)
|
|
26
|
-
|
|
27
|
-
parameter_types[signature.
|
|
26
|
+
rest_type = signature.rest_type
|
|
27
|
+
parameter_types[signature.rest_name] = rest_type if rest_type
|
|
28
|
+
keyrest_type = signature.keyrest_type
|
|
29
|
+
parameter_types[signature.keyrest_name] = keyrest_type if keyrest_type
|
|
28
30
|
parameter_types[signature.block_name] = signature.block_type if signature.block_name
|
|
29
31
|
|
|
30
32
|
sig = RBI::Sig.new
|
|
@@ -40,7 +42,7 @@ module Tapioca
|
|
|
40
42
|
sig.return_type = return_type
|
|
41
43
|
@pipeline.push_symbol(return_type)
|
|
42
44
|
|
|
43
|
-
sig.type_params.concat(extract_type_parameters(parameter_types.values.map(&:to_s).
|
|
45
|
+
sig.type_params.concat(extract_type_parameters(parameter_types.values.map(&:to_s).append(return_type)))
|
|
44
46
|
|
|
45
47
|
case signature.mode
|
|
46
48
|
when "abstract"
|
|
@@ -22,7 +22,7 @@ module Tapioca
|
|
|
22
22
|
node << sclass if sclass.nodes.length > 1
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
-
#: (RBI::Tree tree,
|
|
25
|
+
#: (RBI::Tree tree, Module[top] constant) -> void
|
|
26
26
|
def compile_type_variable_declarations(tree, constant)
|
|
27
27
|
# Try to find the type variables defined on this constant, bail if we can't
|
|
28
28
|
type_variables = Runtime::GenericTypeRegistry.lookup_type_variables(constant)
|
data/lib/tapioca/gem/pipeline.rb
CHANGED
|
@@ -72,29 +72,29 @@ module Tapioca
|
|
|
72
72
|
@events << Gem::ConstantFound.new(symbol, constant)
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
-
#: (String symbol,
|
|
75
|
+
#: (String symbol, Module[top] constant) -> void
|
|
76
76
|
def push_foreign_constant(symbol, constant)
|
|
77
77
|
@events << Gem::ForeignConstantFound.new(symbol, constant)
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
-
#: (String symbol,
|
|
80
|
+
#: (String symbol, Module[top] constant, RBI::Const node) -> void
|
|
81
81
|
def push_const(symbol, constant, node)
|
|
82
82
|
@events << Gem::ConstNodeAdded.new(symbol, constant, node)
|
|
83
83
|
end
|
|
84
84
|
|
|
85
|
-
#: (String symbol,
|
|
85
|
+
#: (String symbol, Module[top] constant, RBI::Scope node) -> void
|
|
86
86
|
def push_scope(symbol, constant, node)
|
|
87
87
|
@events << Gem::ScopeNodeAdded.new(symbol, constant, node)
|
|
88
88
|
end
|
|
89
89
|
|
|
90
|
-
#: (String symbol,
|
|
90
|
+
#: (String symbol, Module[top] constant, RBI::Scope node) -> void
|
|
91
91
|
def push_foreign_scope(symbol, constant, node)
|
|
92
92
|
@events << Gem::ForeignScopeNodeAdded.new(symbol, constant, node)
|
|
93
93
|
end
|
|
94
94
|
|
|
95
95
|
#: (
|
|
96
96
|
#| String symbol,
|
|
97
|
-
#|
|
|
97
|
+
#| Module[top] constant,
|
|
98
98
|
#| UnboundMethod method,
|
|
99
99
|
#| RBI::Method node,
|
|
100
100
|
#| untyped signature,
|
|
@@ -150,7 +150,7 @@ module Tapioca
|
|
|
150
150
|
end
|
|
151
151
|
end
|
|
152
152
|
|
|
153
|
-
#: (Symbol method_name,
|
|
153
|
+
#: (Symbol method_name, Module[top] owner) -> MethodDefinitionLookupResult
|
|
154
154
|
def method_definition_in_gem(method_name, owner)
|
|
155
155
|
definitions = Tapioca::Runtime::Trackers::MethodDefinition.method_definitions_for(method_name, owner)
|
|
156
156
|
|
|
@@ -176,7 +176,7 @@ module Tapioca
|
|
|
176
176
|
|
|
177
177
|
# Helpers
|
|
178
178
|
|
|
179
|
-
#: (
|
|
179
|
+
#: (Module[top] constant) -> String?
|
|
180
180
|
def name_of(constant)
|
|
181
181
|
name = name_of_proxy_target(constant, super(class_of(constant)))
|
|
182
182
|
return name if name
|
|
@@ -248,7 +248,7 @@ module Tapioca
|
|
|
248
248
|
|
|
249
249
|
# Compiling
|
|
250
250
|
|
|
251
|
-
#: (String symbol,
|
|
251
|
+
#: (String symbol, Module[top] constant) -> void
|
|
252
252
|
def compile_foreign_constant(symbol, constant)
|
|
253
253
|
return if skip_foreign_constant?(symbol, constant)
|
|
254
254
|
return if seen?(symbol)
|
|
@@ -274,7 +274,7 @@ module Tapioca
|
|
|
274
274
|
end
|
|
275
275
|
end
|
|
276
276
|
|
|
277
|
-
#: (String name,
|
|
277
|
+
#: (String name, Module[top] constant) -> void
|
|
278
278
|
def compile_alias(name, constant)
|
|
279
279
|
return if seen?(name)
|
|
280
280
|
|
|
@@ -329,7 +329,7 @@ module Tapioca
|
|
|
329
329
|
@root << node
|
|
330
330
|
end
|
|
331
331
|
|
|
332
|
-
#: (String name,
|
|
332
|
+
#: (String name, Module[top] constant) -> void
|
|
333
333
|
def compile_module(name, constant)
|
|
334
334
|
return if skip_module?(name, constant)
|
|
335
335
|
return if seen?(name)
|
|
@@ -340,7 +340,7 @@ module Tapioca
|
|
|
340
340
|
push_scope(name, constant, scope)
|
|
341
341
|
end
|
|
342
342
|
|
|
343
|
-
#: (String name,
|
|
343
|
+
#: (String name, Module[top] constant) -> RBI::Scope
|
|
344
344
|
def compile_scope(name, constant)
|
|
345
345
|
scope = if constant.is_a?(Class)
|
|
346
346
|
superclass = compile_superclass(constant)
|
|
@@ -423,7 +423,7 @@ module Tapioca
|
|
|
423
423
|
false
|
|
424
424
|
end
|
|
425
425
|
|
|
426
|
-
#: (String name,
|
|
426
|
+
#: (String name, Module[top] constant) -> bool
|
|
427
427
|
def skip_alias?(name, constant)
|
|
428
428
|
return true if symbol_in_payload?(name)
|
|
429
429
|
return true unless constant_in_gem?(name)
|
|
@@ -441,12 +441,12 @@ module Tapioca
|
|
|
441
441
|
false
|
|
442
442
|
end
|
|
443
443
|
|
|
444
|
-
#: (String name,
|
|
444
|
+
#: (String name, Module[top] constant) -> bool
|
|
445
445
|
def skip_foreign_constant?(name, constant)
|
|
446
446
|
Tapioca::TypeVariableModule === constant
|
|
447
447
|
end
|
|
448
448
|
|
|
449
|
-
#: (String name,
|
|
449
|
+
#: (String name, Module[top] constant) -> bool
|
|
450
450
|
def skip_module?(name, constant)
|
|
451
451
|
return true unless defined_in_gem?(constant, strict: false)
|
|
452
452
|
return true if Tapioca::TypeVariableModule === constant
|
|
@@ -454,7 +454,7 @@ module Tapioca
|
|
|
454
454
|
false
|
|
455
455
|
end
|
|
456
456
|
|
|
457
|
-
#: (
|
|
457
|
+
#: (Module[top] constant, ?strict: bool) -> bool
|
|
458
458
|
def defined_in_gem?(constant, strict: true)
|
|
459
459
|
files = get_file_candidates(constant)
|
|
460
460
|
.merge(Runtime::Trackers::ConstantDefinition.files_for(constant))
|
|
@@ -466,7 +466,7 @@ module Tapioca
|
|
|
466
466
|
end
|
|
467
467
|
end
|
|
468
468
|
|
|
469
|
-
#: (
|
|
469
|
+
#: (Module[top] constant) -> Set[String]
|
|
470
470
|
def get_file_candidates(constant)
|
|
471
471
|
file_candidates_for(constant)
|
|
472
472
|
rescue ArgumentError, NameError
|
|
@@ -497,7 +497,7 @@ module Tapioca
|
|
|
497
497
|
|
|
498
498
|
# Helpers
|
|
499
499
|
|
|
500
|
-
#: ((
|
|
500
|
+
#: ((Module[top] & T::Generic) constant) -> String
|
|
501
501
|
def generic_name_of(constant)
|
|
502
502
|
type_name = T.must(constant.name)
|
|
503
503
|
return type_name if type_name =~ /\[.*\]$/
|
|
@@ -513,7 +513,7 @@ module Tapioca
|
|
|
513
513
|
"#{type_name}[#{type_variable_names}]"
|
|
514
514
|
end
|
|
515
515
|
|
|
516
|
-
#: (
|
|
516
|
+
#: (Module[top] constant, String? class_name) -> String?
|
|
517
517
|
def name_of_proxy_target(constant, class_name)
|
|
518
518
|
return unless class_name == "ActiveSupport::Deprecation::DeprecatedConstantProxy"
|
|
519
519
|
|
|
@@ -22,6 +22,25 @@ module Tapioca
|
|
|
22
22
|
SPOOM_CONTEXT.srb(sorbet_args.join(" "), sorbet_bin: sorbet_path)
|
|
23
23
|
end
|
|
24
24
|
|
|
25
|
+
#: (String, rbi_mode: bool) { (String stderr) -> void } -> void
|
|
26
|
+
def sorbet_syntax_check!(source, rbi_mode:, &on_failure)
|
|
27
|
+
quoted_source = "\"#{source}\""
|
|
28
|
+
|
|
29
|
+
result = if rbi_mode
|
|
30
|
+
# --e-rbi cannot be used on its own, so we pass a dummy value like `-e ""`
|
|
31
|
+
sorbet("--no-config", "--stop-after=parser", "-e", '""', "--e-rbi", quoted_source)
|
|
32
|
+
else
|
|
33
|
+
sorbet("--no-config", "--stop-after=parser", "-e", quoted_source)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
unless result.status
|
|
37
|
+
stderr = result.err #: as !nil
|
|
38
|
+
on_failure.call(stderr)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
nil
|
|
42
|
+
end
|
|
43
|
+
|
|
25
44
|
#: -> String
|
|
26
45
|
def sorbet_path
|
|
27
46
|
sorbet_path = ENV.fetch(SORBET_EXE_PATH_ENV_VAR, SORBET_BIN)
|
|
@@ -94,21 +94,14 @@ module Tapioca
|
|
|
94
94
|
compiler.decorate
|
|
95
95
|
|
|
96
96
|
rbi = Tapioca::DEFAULT_RBI_FORMATTER.print_file(file)
|
|
97
|
-
result = sorbet(
|
|
98
|
-
"--no-config",
|
|
99
|
-
"--stop-after",
|
|
100
|
-
"parser",
|
|
101
|
-
"-e",
|
|
102
|
-
"\"#{rbi}\"",
|
|
103
|
-
)
|
|
104
97
|
|
|
105
|
-
|
|
98
|
+
sorbet_syntax_check!(rbi, rbi_mode: true) do |stderr|
|
|
106
99
|
raise(SyntaxError, <<~MSG)
|
|
107
100
|
Expected generated RBI file for `#{constant_name}` to not have any parsing errors.
|
|
108
101
|
|
|
109
102
|
Got these parsing errors:
|
|
110
103
|
|
|
111
|
-
#{
|
|
104
|
+
#{stderr}
|
|
112
105
|
MSG
|
|
113
106
|
end
|
|
114
107
|
|
data/lib/tapioca/internal.rb
CHANGED
|
@@ -13,6 +13,7 @@ require "tapioca/sorbet_ext/backcompat_patches"
|
|
|
13
13
|
require "tapioca/sorbet_ext/name_patch"
|
|
14
14
|
require "tapioca/sorbet_ext/generic_name_patch"
|
|
15
15
|
require "tapioca/sorbet_ext/proc_bind_patch"
|
|
16
|
+
require "tapioca/sorbet_ext/void_patch"
|
|
16
17
|
require "tapioca/runtime/generic_type_registry"
|
|
17
18
|
|
|
18
19
|
# The rewriter needs to be loaded very early so RBS comments within Tapioca itself are rewritten
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
module RBI
|
|
5
5
|
class Tree
|
|
6
|
-
#: (
|
|
6
|
+
#: (Module[top] constant) ?{ (Scope scope) -> void } -> Scope
|
|
7
7
|
def create_path(constant, &block)
|
|
8
8
|
constant_name = Tapioca::Runtime::Reflection.name_of(constant)
|
|
9
9
|
raise "given constant does not have a name" unless constant_name
|
|
@@ -65,11 +65,10 @@ module RBI
|
|
|
65
65
|
#| ?return_type: String?,
|
|
66
66
|
#| ?class_method: bool,
|
|
67
67
|
#| ?visibility: RBI::Visibility,
|
|
68
|
-
#| ?comments: Array[RBI::Comment]
|
|
69
|
-
#| ?type_params: Array[String]
|
|
68
|
+
#| ?comments: Array[RBI::Comment]
|
|
70
69
|
#| ) ?{ (RBI::Method node) -> void } -> void
|
|
71
70
|
def create_method(name, parameters: [], return_type: nil, class_method: false, visibility: RBI::Public.new,
|
|
72
|
-
comments: [],
|
|
71
|
+
comments: [], &block)
|
|
73
72
|
return unless Tapioca::RBIHelper.valid_method_name?(name)
|
|
74
73
|
|
|
75
74
|
sigs = []
|
|
@@ -78,7 +77,11 @@ module RBI
|
|
|
78
77
|
# If there is no block, and the params and return type have not been supplied, then
|
|
79
78
|
# we create a single signature with the given parameters and return type
|
|
80
79
|
params = parameters.map { |param| RBI::SigParam.new(param.param.name.to_s, param.type) }
|
|
81
|
-
|
|
80
|
+
return_type ||= "T.untyped"
|
|
81
|
+
type_params = Tapioca::RBIHelper.extract_type_parameters(parameters.map(&:type).append(return_type))
|
|
82
|
+
|
|
83
|
+
sig = RBI::Sig.new(params: params, return_type: return_type, type_params: type_params)
|
|
84
|
+
sigs << sig
|
|
82
85
|
end
|
|
83
86
|
|
|
84
87
|
method = RBI::Method.new(
|
|
@@ -6,7 +6,7 @@ module Tapioca
|
|
|
6
6
|
class DynamicMixinCompiler
|
|
7
7
|
include Runtime::Reflection
|
|
8
8
|
|
|
9
|
-
#: Array[
|
|
9
|
+
#: Array[Module[top]]
|
|
10
10
|
attr_reader :dynamic_extends, :dynamic_includes
|
|
11
11
|
|
|
12
12
|
#: Array[Symbol]
|
|
@@ -15,7 +15,7 @@ module Tapioca
|
|
|
15
15
|
#: Array[Symbol]
|
|
16
16
|
attr_reader :instance_attribute_readers, :instance_attribute_writers, :instance_attribute_predicates
|
|
17
17
|
|
|
18
|
-
#: (
|
|
18
|
+
#: (Module[top] constant) -> void
|
|
19
19
|
def initialize(constant)
|
|
20
20
|
@constant = constant
|
|
21
21
|
mixins_from_modules = {}.compare_by_identity
|
|
@@ -109,12 +109,12 @@ module Tapioca
|
|
|
109
109
|
# is the list of all dynamically extended modules because of that
|
|
110
110
|
# constant. We grab that value by deleting the key for the original
|
|
111
111
|
# constant.
|
|
112
|
-
@dynamic_extends = mixins_from_modules.delete(constant) || [] #: Array[
|
|
112
|
+
@dynamic_extends = mixins_from_modules.delete(constant) || [] #: Array[Module[top]]
|
|
113
113
|
|
|
114
114
|
# Since we deleted the original constant from the list of keys, all
|
|
115
115
|
# the keys that remain are the ones that are dynamically included modules
|
|
116
116
|
# during the include of the original constant.
|
|
117
|
-
@dynamic_includes = mixins_from_modules.keys #: Array[
|
|
117
|
+
@dynamic_includes = mixins_from_modules.keys #: Array[Module[top]]
|
|
118
118
|
|
|
119
119
|
@class_attribute_readers = class_attribute_readers #: Array[Symbol]
|
|
120
120
|
@class_attribute_writers = class_attribute_writers #: Array[Symbol]
|
|
@@ -173,7 +173,7 @@ module Tapioca
|
|
|
173
173
|
tree << RBI::Include.new("GeneratedInstanceMethods")
|
|
174
174
|
end
|
|
175
175
|
|
|
176
|
-
#: (RBI::Tree tree) -> [Array[
|
|
176
|
+
#: (RBI::Tree tree) -> [Array[Module[top]], Array[Module[top]]]
|
|
177
177
|
def compile_mixes_in_class_methods(tree)
|
|
178
178
|
includes = dynamic_includes.filter_map do |mod|
|
|
179
179
|
qname = qualified_name_of(mod)
|
|
@@ -208,7 +208,7 @@ module Tapioca
|
|
|
208
208
|
[[], []] # silence errors
|
|
209
209
|
end
|
|
210
210
|
|
|
211
|
-
#: (
|
|
211
|
+
#: (Module[top] mod, Array[Module[top]] dynamic_extends) -> bool
|
|
212
212
|
def module_included_by_another_dynamic_extend?(mod, dynamic_extends)
|
|
213
213
|
dynamic_extends.any? do |dynamic_extend|
|
|
214
214
|
mod != dynamic_extend && ancestors_of(dynamic_extend).include?(mod)
|
|
@@ -21,16 +21,16 @@ module Tapioca
|
|
|
21
21
|
# variable to type variable serializers. This allows us to associate type variables
|
|
22
22
|
# to the constant names that represent them, easily.
|
|
23
23
|
module GenericTypeRegistry
|
|
24
|
-
@generic_instances = {} #: Hash[String,
|
|
24
|
+
@generic_instances = {} #: Hash[String, Module[top]]
|
|
25
25
|
|
|
26
|
-
@type_variables = {}.compare_by_identity #: Hash[
|
|
26
|
+
@type_variables = {}.compare_by_identity #: Hash[Module[top], Array[TypeVariableModule]]
|
|
27
27
|
|
|
28
28
|
class GenericType < T::Types::Simple
|
|
29
|
-
#: (
|
|
29
|
+
#: (Module[top] raw_type, Module[top] underlying_type) -> void
|
|
30
30
|
def initialize(raw_type, underlying_type)
|
|
31
31
|
super(raw_type)
|
|
32
32
|
|
|
33
|
-
@underlying_type = underlying_type #:
|
|
33
|
+
@underlying_type = underlying_type #: Module[top]
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
# @override
|
|
@@ -52,7 +52,7 @@ module Tapioca
|
|
|
52
52
|
# 2 hash lookups (for the other two `Foo[Integer]`s).
|
|
53
53
|
#
|
|
54
54
|
# This method returns the created or cached clone of the constant.
|
|
55
|
-
#: (untyped constant, untyped types) ->
|
|
55
|
+
#: (untyped constant, untyped types) -> Module[top]
|
|
56
56
|
def register_type(constant, types)
|
|
57
57
|
# Build the name of the instantiated generic type,
|
|
58
58
|
# something like `"Foo[X, Y, Z]"`
|
|
@@ -72,7 +72,7 @@ module Tapioca
|
|
|
72
72
|
@generic_instances.values.any? { |generic_type| generic_type === instance }
|
|
73
73
|
end
|
|
74
74
|
|
|
75
|
-
#: (
|
|
75
|
+
#: (Module[top] constant) -> Array[TypeVariableModule]?
|
|
76
76
|
def lookup_type_variables(constant)
|
|
77
77
|
@type_variables[constant]
|
|
78
78
|
end
|
|
@@ -95,7 +95,7 @@ module Tapioca
|
|
|
95
95
|
|
|
96
96
|
private
|
|
97
97
|
|
|
98
|
-
#: (
|
|
98
|
+
#: (Module[top] constant, String name) -> Module[top]
|
|
99
99
|
def create_generic_type(constant, name)
|
|
100
100
|
generic_type = case constant
|
|
101
101
|
when Class
|
|
@@ -164,7 +164,7 @@ module Tapioca
|
|
|
164
164
|
end
|
|
165
165
|
end
|
|
166
166
|
|
|
167
|
-
#: (
|
|
167
|
+
#: (Module[top] constant) -> Array[TypeVariableModule]
|
|
168
168
|
def lookup_or_initialize_type_variables(constant)
|
|
169
169
|
@type_variables[constant] ||= []
|
|
170
170
|
end
|