From 1ee345194e12e9635fb96262d7a3c64dad73b854 Mon Sep 17 00:00:00 2001 From: ksss Date: Tue, 8 Aug 2023 13:36:18 +0900 Subject: [PATCH] Super class should be absolute paths. to suppress RBS::RecursiveAncestorError. --- lib/rbs/prototype/runtime.rb | 2 +- test/rbs/runtime_prototype_test.rb | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/rbs/prototype/runtime.rb b/lib/rbs/prototype/runtime.rb index 60093fee6..ec17057ba 100644 --- a/lib/rbs/prototype/runtime.rb +++ b/lib/rbs/prototype/runtime.rb @@ -380,7 +380,7 @@ def generate_super_class(mod) RBS.logger.warn("Skipping anonymous superclass #{mod.superclass} of #{mod}") nil else - super_name = to_type_name(const_name(mod.superclass), full_name: true) + super_name = to_type_name(const_name(mod.superclass), full_name: true).absolute! super_args = type_args(super_name) AST::Declarations::Class::Super.new(name: super_name, args: super_args, location: nil) end diff --git a/test/rbs/runtime_prototype_test.rb b/test/rbs/runtime_prototype_test.rb index 08f22a9bd..d4815aa80 100644 --- a/test/rbs/runtime_prototype_test.rb +++ b/test/rbs/runtime_prototype_test.rb @@ -47,7 +47,7 @@ def test_1 assert_write p.decls, <<-EOF module RBS - class RuntimePrototypeTest < Test::Unit::TestCase + class RuntimePrototypeTest < ::Test::Unit::TestCase module TestTargets module Bar end @@ -58,7 +58,7 @@ module Foo extend Comparable end - class Test < String + class Test < ::String include RBS::RuntimePrototypeTest::TestTargets::Foo extend RBS::RuntimePrototypeTest::TestTargets::Bar @@ -91,7 +91,7 @@ def test_merge_types SignatureManager.new do |manager| manager.files[Pathname("foo.rbs")] = < void @@ -111,7 +111,7 @@ def bar: () -> void assert_write p.decls, <<-EOF module RBS - class RuntimePrototypeTest < Test::Unit::TestCase + class RuntimePrototypeTest < ::Test::Unit::TestCase module TestTargets module Bar end @@ -122,7 +122,7 @@ module Foo extend Comparable end - class Test < String + class Test < ::String include RBS::RuntimePrototypeTest::TestTargets::Foo extend RBS::RuntimePrototypeTest::TestTargets::Bar @@ -172,9 +172,9 @@ def test_include_owner assert_write p.decls, <<-EOF module RBS - class RuntimePrototypeTest < Test::Unit::TestCase + class RuntimePrototypeTest < ::Test::Unit::TestCase module IncludeTests - class ChildClass < RBS::RuntimePrototypeTest::IncludeTests::SuperClass + class ChildClass < ::RBS::RuntimePrototypeTest::IncludeTests::SuperClass def self.foo: () -> untyped public @@ -250,7 +250,7 @@ def test_argument_forwarding assert_write p.decls, <<-EOF module RBS - class RuntimePrototypeTest < Test::Unit::TestCase + class RuntimePrototypeTest < ::Test::Unit::TestCase class TestForArgumentForwarding public @@ -291,7 +291,7 @@ def test_for_overwritten_module_name assert_write p.decls, <<~RBS module RBS - class RuntimePrototypeTest < Test::Unit::TestCase + class RuntimePrototypeTest < ::Test::Unit::TestCase module TestForOverrideModuleName class C include RBS::RuntimePrototypeTest::TestForOverrideModuleName::M @@ -303,7 +303,7 @@ def self.to_s: () -> untyped INSTANCE: C end - class C2 < RBS::RuntimePrototypeTest::TestForOverrideModuleName::C + class C2 < ::RBS::RuntimePrototypeTest::TestForOverrideModuleName::C end module M @@ -341,9 +341,9 @@ def test_for_type_parameters assert_write p.decls, <<~RBS module RBS - class RuntimePrototypeTest < Test::Unit::TestCase + class RuntimePrototypeTest < ::Test::Unit::TestCase module TestForTypeParameters - class C < Hash[untyped, untyped] + class C < ::Hash[untyped, untyped] end class C2 @@ -372,7 +372,7 @@ def test_for_initialize_type assert_write p.decls, <<~RBS module RBS - class RuntimePrototypeTest < Test::Unit::TestCase + class RuntimePrototypeTest < ::Test::Unit::TestCase class TestForInitialize private @@ -400,7 +400,7 @@ def test_for_yield assert_write p.decls, <<~RBS module RBS - class RuntimePrototypeTest < Test::Unit::TestCase + class RuntimePrototypeTest < ::Test::Unit::TestCase class TestForYield public