File tree Expand file tree Collapse file tree 3 files changed +21
-4
lines changed
src/main/ruby/truffleruby/core Expand file tree Collapse file tree 3 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,12 @@ def initialize(*args)
13
13
end
14
14
end
15
15
16
+ class StructWithOverriddenName < Struct . new ( :a )
17
+ def self . name
18
+ "A"
19
+ end
20
+ end
21
+
16
22
class SubclassX < Struct
17
23
end
18
24
Original file line number Diff line number Diff line change @@ -25,4 +25,16 @@ class Foo < Struct.new(:a); end
25
25
26
26
m ::Foo . new ( "" ) . send ( @method ) . should == '#<struct a="">'
27
27
end
28
+
29
+ it "does not call #name method" do
30
+ struct = StructClasses ::StructWithOverriddenName . new ( "" )
31
+ struct . send ( @method ) . should == '#<struct StructClasses::StructWithOverriddenName a="">'
32
+ end
33
+
34
+ it "does not call #name method when struct is anonymous" do
35
+ struct = Struct . new ( :a )
36
+ def struct . name ; "A" ; end
37
+
38
+ struct . new ( "" ) . send ( @method ) . should == '#<struct a="">'
39
+ end
28
40
end
Original file line number Diff line number Diff line change @@ -145,12 +145,11 @@ def to_s
145
145
values << "#{ var } =#{ val . inspect } "
146
146
end
147
147
148
- name = self . class . name
149
-
150
- if Primitive . nil? ( name ) || name . empty? || name [ 0 ] == '#'
148
+ if Primitive . module_anonymous? ( self . class )
151
149
return "#<struct #{ values . join ( ', ' ) } >"
152
150
else
153
- return "#<struct #{ self . class . name } #{ values . join ( ', ' ) } >"
151
+ name = Primitive . module_name self . class
152
+ return "#<struct #{ name } #{ values . join ( ', ' ) } >"
154
153
end
155
154
end
156
155
You can’t perform that action at this time.
0 commit comments