lib/tapioca/compilers/symbol_table/symbol_generator.rb in tapioca-0.2.8 vs lib/tapioca/compilers/symbol_table/symbol_generator.rb in tapioca-0.3.0
- old
+ new
@@ -135,18 +135,15 @@
.returns(T.nilable(String))
.checked(:never)
end
def compile_object(name, value)
return if symbol_ignored?(name)
- indented("#{name} = T.let(T.unsafe(nil), #{type_name_of(value)})")
- end
-
- sig { params(value: BasicObject).returns(String).checked(:never) }
- def type_name_of(value)
klass = class_of(value)
+ return if name_of(klass)&.start_with?("T::Types::", "T::Private::")
- public_module?(klass) && name_of(klass) || "T.untyped"
+ type_name = public_module?(klass) && name_of(klass) || "T.untyped"
+ indented("#{name} = T.let(T.unsafe(nil), #{type_name})")
end
sig { params(name: String, constant: Module).returns(T.nilable(String)) }
def compile_module(name, constant)
return unless public_module?(constant)
@@ -287,28 +284,28 @@
!public_module?(mod) ||
Module != class_of(mod)
end
prepends = prepend
- .select(&method(:name_of))
+ .select { |mod| (name = name_of(mod)) && !name.start_with?("T::") }
.select(&method(:public_module?))
.map do |mod|
# TODO: Sorbet currently does not handle prepend
# properly for method resolution, so we generate an
# include statement instead
indented("include(#{qualified_name_of(mod)})")
end
includes = include
- .select(&method(:name_of))
+ .select { |mod| (name = name_of(mod)) && !name.start_with?("T::") }
.select(&method(:public_module?))
.map do |mod|
indented("include(#{qualified_name_of(mod)})")
end
extends = extend
- .select(&method(:name_of))
+ .select { |mod| (name = name_of(mod)) && !name.start_with?("T::") }
.select(&method(:public_module?))
.map do |mod|
indented("extend(#{qualified_name_of(mod)})")
end
@@ -422,15 +419,10 @@
sig { params(symbol_name: String).returns(T::Boolean) }
def symbol_ignored?(symbol_name)
SymbolLoader.ignore_symbol?(symbol_name)
end
- sig { params(path: String).returns(T::Boolean) }
- def path_in_gem?(path)
- File.realpath(path).start_with?(gem.full_gem_path)
- end
-
SPECIAL_METHOD_NAMES = %w[! ~ +@ ** -@ * / % + - << >> & | ^ < <= => > >= == === != =~ !~ <=> [] []= `]
sig { params(name: String).returns(T::Boolean) }
def valid_method_name?(name)
return true if SPECIAL_METHOD_NAMES.include?(name)
@@ -460,21 +452,21 @@
sig { params(method: UnboundMethod).returns(T::Boolean) }
def method_in_gem?(method)
source_location = method.source_location&.first
return false if source_location.nil?
- path_in_gem?(source_location)
+ gem.contains_path?(source_location)
end
sig { params(constant: Module, strict: T::Boolean).returns(T::Boolean) }
def defined_in_gem?(constant, strict: true)
files = Set.new(get_file_candidates(constant))
.merge(Tapioca::ConstantLocator.files_for(constant))
return !strict if files.empty?
files.any? do |file|
- path_in_gem?(file)
+ gem.contains_path?(file)
end
end
sig { params(constant: Module).returns(T::Array[String]) }
def get_file_candidates(constant)