Skip to content

Commit

Permalink
Merge pull request #1618 from ksss/escape-args
Browse files Browse the repository at this point in the history
Should escape if param name include not simple-word
  • Loading branch information
soutaro authored Nov 21, 2023
2 parents bd79c0b + 88c248c commit 391ea57
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
6 changes: 5 additions & 1 deletion lib/rbs/types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,11 @@ def to_json(state = _ = nil)

def to_s
if name
"#{type} #{name}"
if name.match?(/\A[a-zA-Z0-9_]+\z/)
"#{type} #{name}"
else
"#{type} `#{name}`"
end
else
"#{type}"
end
Expand Down
46 changes: 26 additions & 20 deletions test/rbs/runtime_prototype_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ def public_todo: () -> untyped
end
end

class StructInheritWithNil < Struct.new(:foo, :bar, keyword_init: nil)
class StructInheritWithNil < Struct.new(:foo, :bar, :baz?, keyword_init: nil)
end
StructKeywordInitTrue = Struct.new(:foo, :bar, keyword_init: true)
StructKeywordInitFalse = Struct.new(:foo, :bar, keyword_init: false)
Expand All @@ -712,21 +712,23 @@ def test_struct
module RBS
class RuntimePrototypeTest < ::Test::Unit::TestCase
class StructInheritWithNil < ::Struct[untyped]
def self.new: (?untyped foo, ?untyped bar) -> instance
| (?foo: untyped, ?bar: untyped) -> instance
def self.new: (?untyped foo, ?untyped bar, ?untyped `baz?`) -> instance
| (?foo: untyped, ?bar: untyped, ?baz?: untyped) -> instance
def self.[]: (?untyped foo, ?untyped bar) -> instance
| (?foo: untyped, ?bar: untyped) -> instance
def self.[]: (?untyped foo, ?untyped bar, ?untyped `baz?`) -> instance
| (?foo: untyped, ?bar: untyped, ?baz?: untyped) -> instance
def self.keyword_init?: () -> nil
def self.members: () -> [ :foo, :bar ]
def self.members: () -> [ :foo, :bar, :baz? ]
def members: () -> [ :foo, :bar ]
def members: () -> [ :foo, :bar, :baz? ]
attr_accessor foo: untyped
attr_accessor bar: untyped
attr_accessor baz?: untyped
end
end
end
Expand All @@ -736,19 +738,21 @@ def members: () -> [ :foo, :bar ]
module RBS
class RuntimePrototypeTest < ::Test::Unit::TestCase
class StructInheritWithNil < ::Struct[untyped]
def self.new: (?untyped foo, ?untyped bar) -> instance
| (?foo: untyped, ?bar: untyped) -> instance
def self.new: (?untyped foo, ?untyped bar, ?untyped `baz?`) -> instance
| (?foo: untyped, ?bar: untyped, ?baz?: untyped) -> instance
def self.[]: (?untyped foo, ?untyped bar) -> instance
| (?foo: untyped, ?bar: untyped) -> instance
def self.[]: (?untyped foo, ?untyped bar, ?untyped `baz?`) -> instance
| (?foo: untyped, ?bar: untyped, ?baz?: untyped) -> instance
def self.members: () -> [ :foo, :bar ]
def self.members: () -> [ :foo, :bar, :baz? ]
def members: () -> [ :foo, :bar ]
def members: () -> [ :foo, :bar, :baz? ]
attr_accessor foo: untyped
attr_accessor bar: untyped
attr_accessor baz?: untyped
end
end
end
Expand Down Expand Up @@ -863,7 +867,7 @@ class StructDirectInherited < ::Struct[untyped]
end

if RUBY_VERSION >= '3.2'
class DataInherit < Data.define(:foo, :bar)
class DataInherit < Data.define(:foo, :bar, :baz?)
end
DataConst = Data.define(:foo, :bar)
class DataDirectInherit < Data
Expand All @@ -877,19 +881,21 @@ def test_data
module RBS
class RuntimePrototypeTest < ::Test::Unit::TestCase
class DataInherit < ::Data
def self.new: (untyped foo, untyped bar) -> instance
| (foo: untyped, bar: untyped) -> instance
def self.new: (untyped foo, untyped bar, untyped `baz?`) -> instance
| (foo: untyped, bar: untyped, baz?: untyped) -> instance
def self.[]: (untyped foo, untyped bar) -> instance
| (foo: untyped, bar: untyped) -> instance
def self.[]: (untyped foo, untyped bar, untyped `baz?`) -> instance
| (foo: untyped, bar: untyped, baz?: untyped) -> instance
def self.members: () -> [ :foo, :bar ]
def self.members: () -> [ :foo, :bar, :baz? ]
def members: () -> [ :foo, :bar ]
def members: () -> [ :foo, :bar, :baz? ]
attr_reader foo: untyped
attr_reader bar: untyped
attr_reader baz?: untyped
end
end
end
Expand Down
2 changes: 2 additions & 0 deletions test/rbs/writer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ def __id__: () -> Integer
def def: () -> Symbol
def foo: (untyped `include?`) -> void
def self: () -> void
def self?: () -> void
Expand Down

0 comments on commit 391ea57

Please sign in to comment.