diff --git a/lib/rbi/model.rb b/lib/rbi/model.rb index 1ff2f32e..5a7c80ed 100644 --- a/lib/rbi/model.rb +++ b/lib/rbi/model.rb @@ -269,13 +269,16 @@ def fully_qualified_name class Const < NodeWithComments #: String - attr_reader :name, :value + attr_reader :name - #: (String name, String value, ?loc: Loc?, ?comments: Array[Comment]) ?{ (Const node) -> void } -> void - def initialize(name, value, loc: nil, comments: [], &block) + #: (String | Type)? + attr_reader :type + + #: (String name, (String | Type)? type, ?loc: Loc?, ?comments: Array[Comment]) ?{ (Const node) -> void } -> void + def initialize(name, type: nil, loc: nil, comments: [], &block) super(loc: loc, comments: comments) @name = name - @value = value + @type = type block&.call(self) end diff --git a/lib/rbi/parser.rb b/lib/rbi/parser.rb index eba179b2..b8cade65 100644 --- a/lib/rbi/parser.rb +++ b/lib/rbi/parser.rb @@ -138,17 +138,6 @@ def node_string(node) def node_string!(node) T.must(node_string(node)) end - - #: (Prism::Node node) -> Prism::Location - def adjust_prism_location_for_heredoc(node) - visitor = HeredocLocationVisitor.new( - node.location.send(:source), - node.location.start_offset, - node.location.end_offset, - ) - visitor.visit(node) - visitor.location - end end class TreeBuilder < Visitor @@ -228,6 +217,18 @@ def visit_constant_assign(node) current_scope << if struct struct + elsif type_variable_definition?(node.value) + TypeMember.new( + case node + when Prism::ConstantWriteNode + node.name.to_s + when Prism::ConstantPathWriteNode + node_string!(node.target) + end, + node.value.slice, + loc: node_loc(node), + comments: node_comments(node), + ) elsif t_enum_value?(node) TEnumValue.new( case node @@ -240,39 +241,17 @@ def visit_constant_assign(node) comments: node_comments(node), ) else - adjusted_node_location = adjust_prism_location_for_heredoc(node) - - adjusted_value_location = Prism::Location.new( - node.value.location.send(:source), - node.value.location.start_offset, - adjusted_node_location.end_offset - node.value.location.start_offset, + Const.new( + case node + when Prism::ConstantWriteNode + node.name.to_s + when Prism::ConstantPathWriteNode + node_string!(node.target) + end, + type: parse_t_let(node.value), + loc: node_loc(node), + comments: node_comments(node), ) - - if type_variable_definition?(node.value) - TypeMember.new( - case node - when Prism::ConstantWriteNode - node.name.to_s - when Prism::ConstantPathWriteNode - node_string!(node.target) - end, - adjusted_value_location.slice, - loc: Loc.from_prism(@file, adjusted_node_location), - comments: node_comments(node), - ) - else - Const.new( - case node - when Prism::ConstantWriteNode - node.name.to_s - when Prism::ConstantPathWriteNode - node_string!(node.target) - end, - adjusted_value_location.slice, - loc: Loc.from_prism(@file, adjusted_node_location), - comments: node_comments(node), - ) - end end end @@ -772,6 +751,24 @@ def parse_struct(node) struct end + # Parse a node as a `T.let(x, X)` and extract the type + # + # Returns `nil` is the node is not a `T.let` call. + #: (Prism::Node?) -> String? + def parse_t_let(node) + return unless node + + return unless node.is_a?(Prism::CallNode) + return unless node.name == :let + return unless node.receiver&.slice =~ /^(::)?T$/ + + arguments = node.arguments&.arguments + return unless arguments + return unless arguments.size == 2 + + arguments.fetch(1, nil)&.slice + end + #: (Prism::CallNode send) -> void def parse_tstruct_field(send) args = send.arguments @@ -948,57 +945,5 @@ def visit_assoc_node(node) ) end end - - class HeredocLocationVisitor < Prism::Visitor - #: (Prism::Source source, Integer begin_offset, Integer end_offset) -> void - def initialize(source, begin_offset, end_offset) - super() - @source = source - @begin_offset = begin_offset - @end_offset = end_offset - @offset_last_newline = false #: bool - end - - #: (Prism::StringNode node) -> void - def visit_string_node(node) - return unless node.heredoc? - - closing_loc = node.closing_loc - return unless closing_loc - - handle_string_node(node) - end - - #: (Prism::InterpolatedStringNode node) -> void - def visit_interpolated_string_node(node) - return super unless node.heredoc? - - closing_loc = node.closing_loc - return super unless closing_loc - - handle_string_node(node) - end - - #: -> Prism::Location - def location - Prism::Location.new( - @source, - @begin_offset, - @end_offset - @begin_offset - (@offset_last_newline ? 1 : 0), - ) - end - - private - - #: (Prism::StringNode | Prism::InterpolatedStringNode node) -> void - def handle_string_node(node) - closing_loc = T.must(node.closing_loc) - - if closing_loc.end_offset > @end_offset - @end_offset = closing_loc.end_offset - @offset_last_newline = true if node.closing_loc&.slice&.end_with?("\n") - end - end - end end end diff --git a/lib/rbi/printer.rb b/lib/rbi/printer.rb index b2970f3e..9afb5640 100644 --- a/lib/rbi/printer.rb +++ b/lib/rbi/printer.rb @@ -233,7 +233,12 @@ def visit_const(node) print_loc(node) visit_all(node.comments) - printl("#{node.name} = #{node.value}") + type = node.type + if type + printl("#{node.name} = T.let(T.unsafe(nil), #{type})") + else + printl("#{node.name} = T.let(T.unsafe(nil), T.untyped)") + end end # @override @@ -685,13 +690,6 @@ def oneline?(node) node.comments.empty? && node.empty? when Attr node.comments.empty? && node.sigs.empty? - when Const - return false unless node.comments.empty? - - loc = node.loc - return true unless loc - - loc.begin_line == loc.end_line when Method node.comments.empty? && node.sigs.empty? && node.params.all? { |p| p.comments.empty? } when Sig diff --git a/lib/rbi/rbs_printer.rb b/lib/rbi/rbs_printer.rb index 9d028272..c98e2069 100644 --- a/lib/rbi/rbs_printer.rb +++ b/lib/rbi/rbs_printer.rb @@ -229,10 +229,9 @@ def visit_const(node) print_loc(node) visit_all(node.comments) - type = parse_t_let(node.value) + type = node.type if type - type = parse_type(type) - printl("#{node.name}: #{type.rbs_string}") + printl("#{node.name}: #{parse_type(type).rbs_string}") else printl("#{node.name}: untyped") end @@ -853,30 +852,6 @@ def parse_type(type) rescue Type::Error => e raise Error, "Failed to parse type `#{type}` (#{e.message})" end - - # Parse a string containing a `T.let(x, X)` and extract the type - # - # Returns `nil` is the string is not a `T.let`. - #: (String? code) -> String? - def parse_t_let(code) - return unless code - - res = Prism.parse(code) - return unless res.success? - - node = res.value - return unless node.is_a?(Prism::ProgramNode) - - node = node.statements.body.first - return unless node.is_a?(Prism::CallNode) - return unless node.name == :let - return unless node.receiver&.slice =~ /^(::)?T$/ - - arguments = node.arguments&.arguments - return unless arguments - - arguments.fetch(1, nil)&.slice - end end class TypePrinter diff --git a/lib/rbi/rewriters/merge_trees.rb b/lib/rbi/rewriters/merge_trees.rb index 5af32eca..3902d29b 100644 --- a/lib/rbi/rewriters/merge_trees.rb +++ b/lib/rbi/rewriters/merge_trees.rb @@ -384,7 +384,7 @@ class Const # @override #: (Node other) -> bool def compatible_with?(other) - other.is_a?(Const) && name == other.name && value == other.value + other.is_a?(Const) && name == other.name && type == other.type end end diff --git a/test/rbi/model_test.rb b/test/rbi/model_test.rb index 7b4a9792..97f754e1 100644 --- a/test/rbi/model_test.rb +++ b/test/rbi/model_test.rb @@ -42,7 +42,7 @@ def test_model_block_builders tree << SingletonClass.new do |node| node.comments << Comment.new("comment") end - tree << Const.new("C", "42") do |node| + tree << Const.new("C") do |node| node.comments << Comment.new("comment") end tree << AttrAccessor.new(:a1) do |node| @@ -135,7 +135,7 @@ class Bar; end class << self; end # comment - C = 42 + C = T.let(T.unsafe(nil), T.untyped) # comment attr_accessor :a1 @@ -270,19 +270,19 @@ def test_model_fully_qualified_names cls1 << singleton_class assert_equal("::Foo::Bar::", singleton_class.fully_qualified_name) - const = Const.new("Foo", "42") + const = Const.new("Foo") assert_equal("::Foo", const.fully_qualified_name) mod << const assert_equal("::Foo::Foo", const.fully_qualified_name) - const2 = Const.new("Foo::Bar", "42") + const2 = Const.new("Foo::Bar") assert_equal("::Foo::Bar", const2.fully_qualified_name) mod << const2 assert_equal("::Foo::Foo::Bar", const2.fully_qualified_name) - const3 = Const.new("::Foo::Bar", "42") + const3 = Const.new("::Foo::Bar") assert_equal("::Foo::Bar", const3.fully_qualified_name) mod << const3 @@ -344,13 +344,13 @@ def test_model_nodes_as_strings cls << singleton_class assert_equal("::Foo::Bar::", singleton_class.to_s) - const = Const.new("Foo", "42") + const = Const.new("Foo") assert_equal("::Foo", const.to_s) mod << const assert_equal("::Foo::Foo", const.to_s) - const2 = Const.new("Foo::Bar", "42") + const2 = Const.new("Foo::Bar") assert_equal("::Foo::Bar", const2.to_s) mod << const2 diff --git a/test/rbi/parser_test.rb b/test/rbi/parser_test.rb index aea8cfbf..0b2057b7 100644 --- a/test/rbi/parser_test.rb +++ b/test/rbi/parser_test.rb @@ -75,17 +75,26 @@ def m2; end def test_parse_constants rbi = <<~RBI Foo = 42 - Bar = "foo" + Bar = T.let("foo", String) Baz = Bar A = nil B = :s - C = T.nilable(String) - D = A::B::C + C = T.let(nil, T.nilable(String)) + D = T.let(A::B::C, T.class_of(A::B::C)) A::B::C = Foo RBI tree = parse_rbi(rbi) - assert_equal(rbi, tree.string) + assert_equal(<<~RBI, tree.string) + Foo = T.let(T.unsafe(nil), T.untyped) + Bar = T.let(T.unsafe(nil), String) + Baz = T.let(T.unsafe(nil), T.untyped) + A = T.let(T.unsafe(nil), T.untyped) + B = T.let(T.unsafe(nil), T.untyped) + C = T.let(T.unsafe(nil), T.nilable(String)) + D = T.let(T.unsafe(nil), T.class_of(A::B::C)) + A::B::C = T.let(T.unsafe(nil), T.untyped) + RBI end def test_parse_constants_with_heredoc @@ -130,7 +139,16 @@ def test_parse_constants_with_heredoc RBI tree = parse_rbi(rbi) - assert_equal(rbi, tree.string) + assert_equal(<<~RBI, tree.string) + A = T.let(T.unsafe(nil), T.untyped) + B = T.let(T.unsafe(nil), T.untyped) + C = T.let(T.unsafe(nil), T.untyped) + D = T.let(T.unsafe(nil), T.untyped) + E = T.let(T.unsafe(nil), String) + F = T.let(T.unsafe(nil), T.untyped) + G = T.let(T.unsafe(nil), T.untyped) + H = T.let(T.unsafe(nil), T.untyped) + RBI end def test_parse_constants_multiline_calls @@ -144,7 +162,9 @@ def test_parse_constants_multiline_calls RBI tree = parse_rbi(rbi) - assert_equal(rbi, tree.string) + assert_equal(<<~RBI, tree.string) + A = T.let(T.unsafe(nil), T.untyped) + RBI end def test_parse_constants_with_newlines @@ -628,13 +648,13 @@ def test_parse_constants_locations tree = parse_rbi(rbi) assert_equal(<<~RBI, tree.string(print_locs: true)) # -:1:0-1:8 - Foo = 42 + Foo = T.let(T.unsafe(nil), T.untyped) # -:2:0-2:11 - Bar = "foo" + Bar = T.let(T.unsafe(nil), T.untyped) # -:3:0-3:11 - ::Baz = Bar + ::Baz = T.let(T.unsafe(nil), T.untyped) # -:4:0-4:13 - A::B::C = Foo + A::B::C = T.let(T.unsafe(nil), T.untyped) RBI end @@ -971,7 +991,7 @@ def c(a); end attr_reader :a # E comment - E = _ + E = T.let(T.unsafe(nil), T.untyped) end end RBI diff --git a/test/rbi/printer_test.rb b/test/rbi/printer_test.rb index 6960928f..d0550b79 100644 --- a/test/rbi/printer_test.rb +++ b/test/rbi/printer_test.rb @@ -96,14 +96,14 @@ def baz_class_method; end def test_print_constants rbi = Tree.new - rbi << Const.new("Foo", "42") - rbi << Const.new("Bar", "'foo'") - rbi << Const.new("Baz", "Bar") + rbi << Const.new("Foo") + rbi << Const.new("Bar", type: nil) + rbi << Const.new("Baz", type: "String") assert_equal(<<~RBI, rbi.string) - Foo = 42 - Bar = 'foo' - Baz = Bar + Foo = T.let(T.unsafe(nil), T.untyped) + Bar = T.let(T.unsafe(nil), T.untyped) + Baz = T.let(T.unsafe(nil), String) RBI end @@ -401,7 +401,7 @@ def test_print_nodes_with_comments rbi << Module.new("Foo", comments: comments_single) rbi << Class.new("Bar", comments: comments_multi) rbi << SingletonClass.new(comments: comments_single) - rbi << Const.new("Foo", "42", comments: comments_multi) + rbi << Const.new("Foo", comments: comments_multi) rbi << Include.new("A", comments: comments_single) rbi << Extend.new("A", comments: comments_multi) @@ -442,7 +442,7 @@ class << self; end # This is a # Multiline Comment - Foo = 42 + Foo = T.let(T.unsafe(nil), T.untyped) # This is a single line comment include A @@ -1092,7 +1092,7 @@ def test_print_nodes_locations rbi << SingletonClass.new(loc: loc) rbi << TEnum.new("TE", loc: loc) rbi << TStruct.new("TS", loc: loc) - rbi << Const.new("C", "42", loc: loc) + rbi << Const.new("C", loc: loc) rbi << Extend.new("E", loc: loc) rbi << Include.new("I", loc: loc) rbi << Send.new("foo", loc: loc) @@ -1113,10 +1113,8 @@ class << self; end class TE < T::Enum; end # file.rbi:1:3-2:4 class TS < T::Struct; end - # file.rbi:1:3-2:4 - C = 42 - + C = T.let(T.unsafe(nil), T.untyped) # file.rbi:1:3-2:4 extend E # file.rbi:1:3-2:4 diff --git a/test/rbi/rewriters/flatten_singleton_methods_test.rb b/test/rbi/rewriters/flatten_singleton_methods_test.rb index 1f8ea0e6..d21f68f8 100644 --- a/test/rbi/rewriters/flatten_singleton_methods_test.rb +++ b/test/rbi/rewriters/flatten_singleton_methods_test.rb @@ -125,7 +125,7 @@ def self.m1; end def test_flatten_does_not_flatten_other_nodes rbi = <<~RBI module Foo - C1 = 42 + C1 = T.let(T.unsafe(nil), T.untyped) module M1; end abtract! end diff --git a/test/rbi/rewriters/group_nodes_test.rb b/test/rbi/rewriters/group_nodes_test.rb index 05f6f499..5105df7a 100644 --- a/test/rbi/rewriters/group_nodes_test.rb +++ b/test/rbi/rewriters/group_nodes_test.rb @@ -61,7 +61,7 @@ def self.m2; end class << self; end - C = 42 + C = T.let(T.unsafe(nil), T.untyped) module S1; end class S2; end S3 = ::Struct.new @@ -109,8 +109,8 @@ def m2; end module Scope2 class << self; end - C1 = 42 - C2 = 42 + C1 = T.let(T.unsafe(nil), T.untyped) + C2 = T.let(T.unsafe(nil), T.untyped) module M1; end Scope3 = ::Struct.new do @@ -170,7 +170,7 @@ def self.m2; end class << self; end - C = 42 + C = T.let(T.unsafe(nil), T.untyped) module S1; end class S2; end S3 = ::Struct.new @@ -295,7 +295,7 @@ def self.m2; end class << self; end - C = 42 + C = T.let(T.unsafe(nil), T.untyped) module S1; end class S2; end S3 = ::Struct.new @@ -368,8 +368,8 @@ def m2; end class << self; end - C1 = 42 - C2 = 42 + C1 = T.let(T.unsafe(nil), T.untyped) + C2 = T.let(T.unsafe(nil), T.untyped) class S1; end module S2; end S3 = ::Struct.new @@ -383,7 +383,7 @@ class TS2 < T::Struct; end def test_group_sort_nested_groups rbi = Tree.new sscope = Class.new("Scope2.1") - sscope << Const.new("C2", "42") + sscope << Const.new("C2") sscope << Module.new("S2") sscope << Method.new("m2") sscope << Include.new("I2") @@ -395,7 +395,7 @@ def test_group_sort_nested_groups sscope << TStructConst.new("SC2", "Type") sscope << TEnum.new("TE2") sscope << TStruct.new("TS2") - sscope << Const.new("C1", "42") + sscope << Const.new("C1") sscope << Class.new("S1") sscope << Method.new("m1") sscope << Include.new("I1") @@ -413,7 +413,7 @@ def test_group_sort_nested_groups scope = Class.new("Scope2") scope << sscope - scope << Const.new("C2", "42") + scope << Const.new("C2") scope << Module.new("S2") scope << Method.new("m2") scope << Include.new("I2") @@ -425,7 +425,7 @@ def test_group_sort_nested_groups scope << TStructConst.new("SC2", "Type") scope << TEnum.new("TE2") scope << TStruct.new("TS2") - scope << Const.new("C1", "42") + scope << Const.new("C1") scope << Class.new("S1") scope << Method.new("m1") scope << Include.new("I1") @@ -443,7 +443,7 @@ def test_group_sort_nested_groups rbi << scope scope = Class.new("Scope1") - scope << Const.new("C2", "42") + scope << Const.new("C2") scope << Module.new("S2") scope << Method.new("m2") scope << Include.new("I2") @@ -455,7 +455,7 @@ def test_group_sort_nested_groups scope << TStructConst.new("SC2", "Type") scope << TEnum.new("TE2") scope << TStruct.new("TS2") - scope << Const.new("C1", "42") + scope << Const.new("C1") scope << Class.new("S1") scope << Method.new("m1") scope << Include.new("I1") @@ -502,8 +502,8 @@ class Scope1 def m1; end def m2; end - C1 = 42 - C2 = 42 + C1 = T.let(T.unsafe(nil), T.untyped) + C2 = T.let(T.unsafe(nil), T.untyped) class S1; end module S2; end S3 = ::Struct.new @@ -539,8 +539,8 @@ class Scope2 def m1; end def m2; end - C1 = 42 - C2 = 42 + C1 = T.let(T.unsafe(nil), T.untyped) + C2 = T.let(T.unsafe(nil), T.untyped) class S1; end module S2; end S3 = ::Struct.new @@ -571,8 +571,8 @@ class Scope2.1 def m1; end def m2; end - C1 = 42 - C2 = 42 + C1 = T.let(T.unsafe(nil), T.untyped) + C2 = T.let(T.unsafe(nil), T.untyped) class S1; end module S2; end S3 = ::Struct.new diff --git a/test/rbi/rewriters/merge_trees_test.rb b/test/rbi/rewriters/merge_trees_test.rb index 21714ac8..5b4ce9f8 100644 --- a/test/rbi/rewriters/merge_trees_test.rb +++ b/test/rbi/rewriters/merge_trees_test.rb @@ -127,11 +127,11 @@ class A res = tree1.merge(tree2) assert_equal(<<~RBI, res.string) class A - A = 42 - B = 42 + A = T.let(T.unsafe(nil), T.untyped) + B = T.let(T.unsafe(nil), T.untyped) end - B = 42 + B = T.let(T.unsafe(nil), T.untyped) RBI end @@ -517,28 +517,28 @@ def test_merge_tree_comments_together def test_merge_create_conflict_tree_for_scopes tree1 = parse_rbi(<<~RBI) class Foo - A = 10 + A = T.let(T.unsafe(nil), T.untyped) end module Bar - B = 10 + B = T.let(T.unsafe(nil), T.untyped) class Baz < Foo - C = 10 + C = T.let(T.unsafe(nil), T.untyped) end end RBI tree2 = parse_rbi(<<~RBI) module Foo - A = 10 + A = T.let(T.unsafe(nil), T.untyped) end class Bar - B = 10 + B = T.let(T.unsafe(nil), T.untyped) class Baz < Bar - C = 10 + C = T.let(T.unsafe(nil), T.untyped) end end RBI @@ -550,7 +550,7 @@ class Foo ======= module Foo >>>>>>> right - A = 10 + A = T.let(T.unsafe(nil), T.untyped) end <<<<<<< left @@ -558,14 +558,14 @@ module Bar ======= class Bar >>>>>>> right - B = 10 + B = T.let(T.unsafe(nil), T.untyped) <<<<<<< left class Baz < Foo ======= class Baz < Bar >>>>>>> right - C = 10 + C = T.let(T.unsafe(nil), T.untyped) end end RBI @@ -627,31 +627,44 @@ def test_merge_create_conflict_tree_for_constants tree1 = parse_rbi(<<~RBI) class Foo A = 10 + B = T.let(T.unsafe(nil), Integer) + C = T.let(T.unsafe(nil), String) end - B = 10 + A = 10 + B = T.let(T.unsafe(nil), Integer) + C = T.let(T.unsafe(nil), String) RBI tree2 = parse_rbi(<<~RBI) class Foo A = 42 + B = T.let(T.unsafe(nil), String) + C = T.let(T.unsafe(nil), String) end - B = 42 + A = 42 + B = T.let(T.unsafe(nil), String) + C = T.let(T.unsafe(nil), String) RBI res = tree1.merge(tree2) assert_equal(<<~RBI, res.string) class Foo + A = T.let(T.unsafe(nil), T.untyped) <<<<<<< left - A = 10 + B = T.let(T.unsafe(nil), Integer) ======= - A = 42 + B = T.let(T.unsafe(nil), String) >>>>>>> right + C = T.let(T.unsafe(nil), String) end + + A = T.let(T.unsafe(nil), T.untyped) <<<<<<< left - B = 10 + B = T.let(T.unsafe(nil), Integer) ======= - B = 42 + B = T.let(T.unsafe(nil), String) >>>>>>> right + C = T.let(T.unsafe(nil), String) RBI end @@ -689,7 +702,7 @@ class B; end <<<<<<< left module C; end ======= - C = 42 + C = T.let(T.unsafe(nil), T.untyped) >>>>>>> right <<<<<<< left class D < A; end @@ -985,16 +998,16 @@ def m3; end def test_merge_return_the_list_of_conflicts tree1 = parse_rbi(<<~RBI) class Foo - A = 10 + A = T.let(T.unsafe(nil), T.untyped) end - B = 10 + B = T.let(T.unsafe(nil), T.untyped) RBI tree2 = parse_rbi(<<~RBI) module Foo - A = 42 + A = T.let(T.unsafe(nil), String) end - B = 42 + B = T.let(T.unsafe(nil), String) RBI merged_tree = tree1.merge(tree2) @@ -1009,7 +1022,7 @@ module Foo def test_merge_keep_left tree1 = parse_rbi(<<~RBI) module Foo - A = 10 + A = T.let(T.unsafe(nil), T.untyped) class Bar def m1; end @@ -1024,7 +1037,7 @@ def m3; end tree2 = parse_rbi(<<~RBI) module Foo - A = 42 + A = T.let(T.unsafe(nil), String) module Bar def m1(x); end @@ -1041,7 +1054,7 @@ def m4; end assert_equal(<<~RBI, res.string) module Foo - A = 10 + A = T.let(T.unsafe(nil), T.untyped) class Bar def m1; end @@ -1059,7 +1072,7 @@ def m4; end def test_merge_keep_right tree1 = parse_rbi(<<~RBI) module Foo - A = 10 + A = T.let(T.unsafe(nil), T.untyped) class Bar def m1; end @@ -1074,7 +1087,7 @@ def m3; end tree2 = parse_rbi(<<~RBI) module Foo - A = 42 + A = T.let(T.unsafe(nil), String) module Bar def m1(x); end @@ -1091,7 +1104,7 @@ def m4; end assert_equal(<<~RBI, res.string) module Foo - A = 42 + A = T.let(T.unsafe(nil), String) module Bar def m1(x); end diff --git a/test/rbi/rewriters/nest_singleton_methods_test.rb b/test/rbi/rewriters/nest_singleton_methods_test.rb index bdec4b4c..32cca0c3 100644 --- a/test/rbi/rewriters/nest_singleton_methods_test.rb +++ b/test/rbi/rewriters/nest_singleton_methods_test.rb @@ -92,7 +92,7 @@ def m1; end def test_nest_does_not_nest_other_nodes rbi = <<~RBI module Foo - C1 = 42 + C1 = T.let(T.unsafe(nil), T.untyped) module M1; end h1! end diff --git a/test/rbi/rewriters/remove_known_definitions_test.rb b/test/rbi/rewriters/remove_known_definitions_test.rb index 64f020a8..cb8212e2 100644 --- a/test/rbi/rewriters/remove_known_definitions_test.rb +++ b/test/rbi/rewriters/remove_known_definitions_test.rb @@ -19,7 +19,7 @@ module Bar def bar; end end - BAZ = 42 + BAZ = T.let(T.unsafe(nil), T.untyped) RBI original = parse_rbi(shim) @@ -97,7 +97,7 @@ def bar; end assert_equal(<<~RBI, cleaned.string) class Foo def bar; end - BAR = 42 + BAR = T.let(T.unsafe(nil), T.untyped) end RBI diff --git a/test/rbi/rewriters/sort_nodes_test.rb b/test/rbi/rewriters/sort_nodes_test.rb index 557099ac..da66a8fe 100644 --- a/test/rbi/rewriters/sort_nodes_test.rb +++ b/test/rbi/rewriters/sort_nodes_test.rb @@ -17,9 +17,9 @@ def test_sorts_constants tree.sort_nodes! assert_equal(<<~RBI, tree.string) - A = 42 - B = 42 - C = 42 + A = T.let(T.unsafe(nil), T.untyped) + B = T.let(T.unsafe(nil), T.untyped) + C = T.let(T.unsafe(nil), T.untyped) RBI end @@ -84,12 +84,12 @@ class A; end tree.sort_nodes! assert_equal(<<~RBI, tree.string) - A = 42 + A = T.let(T.unsafe(nil), T.untyped) module A; end class A; end class B; end module B; end - B = 42 + B = T.let(T.unsafe(nil), T.untyped) RBI end @@ -259,7 +259,7 @@ class E; end def m1; end def m2; end def self.m3; end - A = 42 + A = T.let(T.unsafe(nil), T.untyped) module B; end class C < T::Enum; end class D < T::Struct; end @@ -319,7 +319,7 @@ def self.m3; end class << self; end class << self; end class << self; end - A = 42 + A = T.let(T.unsafe(nil), T.untyped) module B; end class C < T::Enum; end class D < T::Struct; end