Skip to content

Commit 8efd601

Browse files
committed
Use relative class/module names in RBS output
format_declared_const_path was already used for constant declarations but not for class/module declarations, causing fully qualified names like `class Optcarrot::ROM` inside `module Optcarrot` instead of the simpler `class ROM`.
1 parent ae9dccc commit 8efd601

15 files changed

Lines changed: 34 additions & 34 deletions

lib/typeprof/core/service.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ def dump_declarations(path)
437437
when AST::ModuleNode
438438
if node.static_cpath
439439
if event == :enter
440-
out << " " * stack.size + "module #{ node.static_cpath.join("::") }"
440+
out << " " * stack.size + "module #{ format_declared_const_path(node.static_cpath, stack) }"
441441
if stack == [:toplevel]
442442
out << "end"
443443
stack.pop
@@ -453,7 +453,7 @@ def dump_declarations(path)
453453
next if stack.any? { node.is_a?(AST::SingletonClassNode) && (_1.is_a?(AST::ClassNode) || _1.is_a?(AST::ModuleNode)) && node.static_cpath == _1.static_cpath }
454454

455455
if event == :enter
456-
s = "class #{ node.static_cpath.join("::") }"
456+
s = "class #{ format_declared_const_path(node.static_cpath, stack) }"
457457
mod = @genv.resolve_cpath(node.static_cpath)
458458
superclass = mod.superclass
459459
if superclass == nil

scenario/class/basic2.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def foo(n)
1111

1212
## assert
1313
class C
14-
class C::D
14+
class D
1515
def foo: (String) -> singleton(C)
1616
end
1717
end

scenario/class/circular_mutual.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ class Foo < Baz
1313
class Foo
1414
end
1515
class Bar
16-
class Bar::Baz < Bar::Foo
16+
class Baz < Bar::Foo
1717
end
18-
class Bar::Foo # failed to identify its superclass
18+
class Foo # failed to identify its superclass
1919
end
2020
end
2121

scenario/class/include-hack.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module Baz
1111

1212
## assert
1313
module Foo
14-
module Foo::Bar
14+
module Bar
1515
end
1616
end
1717
module Baz

scenario/class/self-in-cbase.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class self::Bar::Baz
66

77
## assert
88
class Foo
9-
class Foo::Bar::Baz
9+
class Bar::Baz
1010
end
1111
end
1212

scenario/class/unknown-cbase.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def check = foo
1414

1515
## assert: test.rb
1616
class Foo::Bar
17-
class Foo::Bar::C
17+
class C
1818
def foo: -> Integer
1919
end
2020
end
@@ -28,7 +28,7 @@ module Foo
2828

2929
## assert: test.rb
3030
class Foo::Bar
31-
class Foo::Bar::C
31+
class C
3232
def foo: -> Integer
3333
end
3434
end

scenario/const/superclass1.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class E < C
1111
class C
1212
end
1313
class D
14-
class D::E < C
14+
class E < C
1515
end
1616
end
1717

@@ -25,7 +25,7 @@ class C # Defining D::C changes the superclass of D::E from ::C to D::C
2525
class C
2626
end
2727
class D
28-
class D::E < D::C
28+
class E < D::C
2929
end
3030
end
3131

@@ -38,7 +38,7 @@ class D
3838
class C
3939
end
4040
class D
41-
class D::E < C
41+
class E < C
4242
end
4343
end
4444

scenario/const/superclass2.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ class C < A::B
1111

1212
## assert: test0.rb
1313
class A
14-
class A::B
14+
class B
1515
end
1616
end
1717
class X
18-
class X::C < A::B
18+
class C < A::B
1919
end
2020
end
2121

@@ -28,11 +28,11 @@ class A
2828

2929
## assert: test0.rb
3030
class A
31-
class A::B
31+
class B
3232
end
3333
end
3434
class X
35-
class X::C # failed to identify its superclass
35+
class C # failed to identify its superclass
3636
end
3737
end
3838

@@ -47,10 +47,10 @@ class B
4747

4848
## assert: test0.rb
4949
class A
50-
class A::B
50+
class B
5151
end
5252
end
5353
class X
54-
class X::C < X::A::B
54+
class C < X::A::B
5555
end
5656
end

scenario/const/superclass3.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ class D < B
1313

1414
## assert: test0.rb
1515
class A
16-
class A::B
16+
class B
1717
end
1818
end
1919
class X
20-
class X::C < A
21-
class X::C::D < A::B
20+
class C < A
21+
class D < A::B
2222
end
2323
end
2424
end
@@ -33,12 +33,12 @@ class B
3333

3434
## assert: test0.rb
3535
class A
36-
class A::B
36+
class B
3737
end
3838
end
3939
class X
40-
class X::C < X::A
41-
class X::C::D < X::A::B
40+
class C < X::A
41+
class D < X::A::B
4242
end
4343
end
4444
end

scenario/flow/is_a.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def foo(n)
3333

3434
## assert
3535
class C
36-
class C::D
36+
class D
3737
end
3838
def foo: (C::D | Integer) -> (C::D | String)
3939
end

0 commit comments

Comments
 (0)