lib/tapioca/compilers/symbol_table/symbol_generator.rb in tapioca-0.2.6 vs lib/tapioca/compilers/symbol_table/symbol_generator.rb in tapioca-0.2.7

- old
+ new

@@ -72,18 +72,22 @@ return unless constant compile(symbol, constant) end - sig { params(symbol: String).returns(BasicObject) } + sig { params(symbol: String).returns(BasicObject).checked(:never) } def resolve_constant(symbol) Object.const_get(symbol, false) rescue NameError, LoadError, RuntimeError, ArgumentError, TypeError nil end - sig { params(name: T.nilable(String), constant: BasicObject).returns(T.nilable(String)) } + sig do + params(name: T.nilable(String), constant: BasicObject) + .returns(T.nilable(String)) + .checked(:never) + end def compile(name, constant) return unless constant return unless name return if name.strip.empty? return if name.start_with?('#<') @@ -94,11 +98,15 @@ mark_seen(name) compile_constant(name, constant) end - sig { params(name: String, constant: BasicObject).returns(T.nilable(String)) } + sig do + params(name: String, constant: BasicObject) + .returns(T.nilable(String)) + .checked(:never) + end def compile_constant(name, constant) case constant when Module if name_of(constant) != name compile_alias(name, constant) @@ -120,16 +128,21 @@ return if IGNORED_SYMBOLS.include?(name) indented("#{name} = #{constant_name}") end - sig { params(name: String, value: BasicObject).returns(T.nilable(String)) } + sig do + params(name: String, value: BasicObject) + .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) } + sig { params(value: BasicObject).returns(String).checked(:never) } def type_name_of(value) klass = class_of(value) public_module?(klass) && name_of(klass) || "T.untyped" end @@ -526,11 +539,11 @@ rescue NameError false end end - sig { params(constant: BasicObject).returns(Class) } + sig { params(constant: BasicObject).returns(Class).checked(:never) } def class_of(constant) Kernel.instance_method(:class).bind(constant).call end sig { params(constant: Module).returns(T::Array[Symbol]) } @@ -541,11 +554,11 @@ sig { params(constant: Module).returns(T.nilable(String)) } def raw_name_of(constant) Module.instance_method(:name).bind(constant).call end - sig { params(constant: BasicObject).returns(Class) } + sig { params(constant: BasicObject).returns(Class).checked(:never) } def singleton_class_of(constant) Object.instance_method(:singleton_class).bind(constant).call end sig { params(constant: Module).returns(T.nilable(String)) } @@ -576,19 +589,23 @@ sig { params(constant: Module).returns(T.nilable(String)) } def qualified_name_of(constant) name = name_of(constant) return if name.nil? - name.prepend("::") unless name.start_with?("::") - name + + if name.start_with?("::") + name + else + "::#{name}" + end end sig { params(constant: Class).returns(T.nilable(Class)) } def superclass_of(constant) Class.instance_method(:superclass).bind(constant).call end - sig { params(constant: Module, other: BasicObject).returns(T::Boolean) } + sig { params(constant: Module, other: BasicObject).returns(T::Boolean).checked(:never) } def are_equal?(constant, other) BasicObject.instance_method(:equal?).bind(constant).call(other) end end end