rbs 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +34 -0
  3. data/Rakefile +2 -0
  4. data/core/array.rbs +1 -1
  5. data/core/enumerable.rbs +1 -1
  6. data/core/hash.rbs +13 -5
  7. data/core/io.rbs +3 -3
  8. data/core/module.rbs +1 -1
  9. data/core/numeric.rbs +10 -0
  10. data/core/proc.rbs +1 -1
  11. data/core/random.rbs +4 -2
  12. data/core/range.rbs +2 -2
  13. data/core/struct.rbs +3 -2
  14. data/core/thread.rbs +1 -1
  15. data/docs/CONTRIBUTING.md +5 -3
  16. data/docs/sigs.md +18 -1
  17. data/docs/syntax.md +11 -11
  18. data/lib/rbs.rb +1 -0
  19. data/lib/rbs/ast/annotation.rb +2 -2
  20. data/lib/rbs/ast/comment.rb +2 -2
  21. data/lib/rbs/ast/declarations.rb +37 -22
  22. data/lib/rbs/ast/members.rb +26 -26
  23. data/lib/rbs/cli.rb +3 -0
  24. data/lib/rbs/constant_table.rb +4 -1
  25. data/lib/rbs/definition.rb +1 -1
  26. data/lib/rbs/definition_builder.rb +14 -0
  27. data/lib/rbs/definition_builder/ancestor_builder.rb +1 -0
  28. data/lib/rbs/definition_builder/method_builder.rb +4 -2
  29. data/lib/rbs/location.rb +106 -2
  30. data/lib/rbs/locator.rb +205 -0
  31. data/lib/rbs/method_type.rb +2 -2
  32. data/lib/rbs/parser.rb +1050 -713
  33. data/lib/rbs/parser.y +403 -71
  34. data/lib/rbs/test/hook.rb +8 -2
  35. data/lib/rbs/type_name.rb +2 -3
  36. data/lib/rbs/type_name_resolver.rb +1 -1
  37. data/lib/rbs/types.rb +36 -34
  38. data/lib/rbs/version.rb +1 -1
  39. data/lib/rbs/writer.rb +4 -2
  40. data/sig/annotation.rbs +1 -1
  41. data/sig/cli.rbs +31 -21
  42. data/sig/comment.rbs +1 -1
  43. data/sig/declarations.rbs +106 -21
  44. data/sig/environment.rbs +2 -2
  45. data/sig/location.rbs +84 -3
  46. data/sig/locator.rbs +44 -0
  47. data/sig/members.rbs +76 -12
  48. data/sig/method_builder.rbs +1 -1
  49. data/sig/method_types.rbs +1 -1
  50. data/sig/polyfill.rbs +13 -8
  51. data/sig/rbs.rbs +8 -4
  52. data/sig/typename.rbs +1 -1
  53. data/sig/types.rbs +60 -19
  54. data/sig/util.rbs +0 -4
  55. data/sig/writer.rbs +8 -2
  56. data/stdlib/rubygems/0/requirement.rbs +84 -2
  57. data/stdlib/rubygems/0/version.rbs +2 -1
  58. data/stdlib/shellwords/0/shellwords.rbs +252 -0
  59. data/steep/Gemfile.lock +16 -13
  60. metadata +5 -2
data/sig/environment.rbs CHANGED
@@ -5,7 +5,7 @@ module RBS
5
5
  interface _WithContext
6
6
  def outer: () -> Array[module_decl]
7
7
 
8
- def decl: () -> module_decl
8
+ def decl: () -> untyped
9
9
  end
10
10
 
11
11
  module ContextUtil : _WithContext
@@ -23,7 +23,7 @@ module RBS
23
23
  end
24
24
 
25
25
  attr_reader name: TypeName
26
- attr_reader decls: Array[D[module_decl]]
26
+ attr_reader decls: Array[untyped]
27
27
 
28
28
  def initialize: (name: TypeName) -> void
29
29
 
data/sig/location.rbs CHANGED
@@ -13,40 +13,121 @@ module RBS
13
13
 
14
14
  def initialize: (buffer: Buffer, start_pos: Integer, end_pos: Integer) -> void
15
15
 
16
- def inspect: () -> ::String
16
+ def inspect: () -> String
17
17
 
18
+ # Returns the name of the buffer.
18
19
  def name: () -> untyped
19
20
 
21
+ # Line of the `start_pos` (1 origin)
20
22
  def start_line: () -> Integer
21
23
 
24
+ # Column of the `start_pos` (0 origin)
22
25
  def start_column: () -> Integer
23
26
 
27
+ # Line of the `end_pos` (1 origin)
24
28
  def end_line: () -> Integer
25
29
 
30
+ # Column of the `end_pos` (0 origin)
26
31
  def end_column: () -> Integer
27
32
 
28
33
  def start_loc: () -> Buffer::loc
29
34
 
30
35
  def end_loc: () -> Buffer::loc
31
36
 
37
+ def range: () -> Range[Integer]
38
+
39
+ # A substring of buffer associated to the location.
32
40
  def source: () -> String
33
41
 
34
42
  def to_s: () -> String
35
43
 
44
+ # Returns a string representation suitable for terminal output.
45
+ #
46
+ # Location.to_string(loc) # => a.rb:1:0...3:4
47
+ # Location.to_string(nil) # => *:*:*..*:*
48
+ #
36
49
  def self.to_string: (Location? location, ?default: ::String default) -> String
37
50
 
38
51
  def ==: (untyped other) -> bool
39
52
 
53
+ # Returns a new location with starting positionof `self` and ending position of `other`.
54
+ #
55
+ # l1 = Location.new(buffer: buffer, start_pos: 0, end_pox: x)
56
+ # l2 = Location.new(buffer: buffer, start_pos: y, end_pos: 20)
57
+ # l1 + l2 # => Location.new(buffer: buffer, start_pos: 0, end_pos: 20)
58
+ #
40
59
  def +: (Location other) -> Location
41
60
 
61
+ # Returns true if `loc` is exact predecessor of `self`.
62
+ #
63
+ # l1 = Location.new(...) # 0..10
64
+ # l2 = Location.new(...) # 10..13
65
+ # l3 = Location.new(...) # 13..20
66
+ #
67
+ # l1.pred?(l2) # => true
68
+ # l2.pred?(l3) # => true
69
+ # l1.pred?(l3) # => false
70
+ #
42
71
  def pred?: (Location loc) -> bool
43
72
 
44
- def to_json: (*untyped args) -> untyped
73
+ include _ToJson
45
74
 
46
75
  # `<<` locations given as argument.
76
+ #
47
77
  def concat: (*Location?) -> Location
48
78
 
49
- # Append given location destructively.
79
+ # Inplace version of `+`.
80
+ #
50
81
  def <<: (Location?) -> Location
82
+
83
+ # Returns WithChildren instance with given children.
84
+ #
85
+ # location.with_children(
86
+ # required: { name: name.location },
87
+ # optional: { args: nil }
88
+ # )
89
+ #
90
+ def with_children: [R, O](?required: Hash[R, Range[Integer] | Location], ?optional: Hash[O, Range[Integer] | Location | nil]) -> WithChildren[R, O]
91
+
92
+ # Location::WithChildren contains _child_ locations.
93
+ #
94
+ # # Array[String]
95
+ # # ^^^^^ <= name
96
+ # # ^^^^^^^^ <= args
97
+ # #
98
+ # # @type var loc: Location::WithChildren[:name, :args]
99
+ # loc = Location::WithChildren.new(buffer: buffer, start_pos: 0, end_pos: 13)
100
+ # loc = loc.merge_required({ name: 1...5 })
101
+ # loc = loc.merge_optional({ args: 5...13 })
102
+ #
103
+ # loc[:name] # => Location instance for `Array`
104
+ # loc[:args] # => Location instance for `[String]`
105
+ #
106
+ class WithChildren[RequiredChildKeys, OptionalChildKeys] < Location
107
+ attr_reader required_children: Hash[RequiredChildKeys, Range[Integer]]
108
+
109
+ attr_reader optional_children: Hash[OptionalChildKeys, Range[Integer]?]
110
+
111
+ def initialize: ...
112
+
113
+ def initialize_copy: ...
114
+
115
+ # Returns `Location` instance for given _child_ name.
116
+ #
117
+ # # @type var loc: Location::WithChildren[:name, :args]
118
+ # loc[:name] # => Location
119
+ # loc[:args] # => may be nil
120
+ #
121
+ # Note that passing unknown symbol raises an error even if the child is _optional_.
122
+ # You need explicitly set `nil` for absent optional children.
123
+ #
124
+ def []: (RequiredChildKeys) -> Location
125
+ | (OptionalChildKeys) -> Location?
126
+ | (Symbol) -> Location?
127
+
128
+ def merge_required: (Hash[RequiredChildKeys, Range[Integer] | Location]) -> self
129
+
130
+ def merge_optional: (Hash[OptionalChildKeys, Range[Integer] | Location | nil]) -> self
131
+ end
51
132
  end
52
133
  end
data/sig/locator.rbs ADDED
@@ -0,0 +1,44 @@
1
+ module RBS
2
+ # Locator helps finding RBS elements based on locations in the RBS source text.
3
+ #
4
+ class Locator
5
+ type component = Symbol
6
+ | Types::t
7
+ | MethodType
8
+ | AST::Declarations::t
9
+ | AST::Members::t
10
+ | AST::Declarations::ModuleTypeParams::TypeParam
11
+ | AST::Declarations::Class::Super
12
+ | AST::Declarations::Module::Self
13
+
14
+ # Array of _top-level_ declarations.
15
+ #
16
+ attr_reader decls: Array[AST::Declarations::t]
17
+
18
+ def initialize: (decls: Array[AST::Declarations::t]) -> void
19
+
20
+ def buffer: () -> Buffer
21
+
22
+ # Returns list of components.
23
+ # Inner component comes first.
24
+ #
25
+ def find: (line: Integer, column: Integer) -> Array[component]
26
+
27
+ # Returns pair of the inner most symbol and outer components.
28
+ # It ensures the array starts with a AST/type component.
29
+ #
30
+ def find2: (line: Integer, column: Integer) -> [Symbol?, Array[component]]?
31
+
32
+ def find_in_decl: (Integer pos, decl: AST::Declarations::t, array: Array[component]) -> bool
33
+
34
+ def find_in_member: (Integer pos, member: AST::Members::t, array: Array[component]) -> bool
35
+
36
+ def find_in_method_type: (Integer pos, method_type: MethodType, array: Array[component]) -> bool
37
+
38
+ def find_in_type: (Integer pos, type: Types::t, array: Array[component]) -> bool
39
+
40
+ def find_in_loc: (Integer pos, location: Location::WithChildren[untyped, untyped] | Location | nil, array: Array[component]) -> bool
41
+
42
+ def test_loc: (Integer pos, location: Location?) -> bool
43
+ end
44
+ end
data/sig/members.rbs CHANGED
@@ -15,15 +15,27 @@ module RBS
15
15
  class MethodDefinition < Base
16
16
  type kind = :instance | :singleton | :singleton_instance
17
17
 
18
+ # def foo: () -> void
19
+ # ^^^ keyword
20
+ # ^^^ name
21
+ #
22
+ # def self.bar: () -> void | ...
23
+ # ^^^ keyword
24
+ # ^^^^^ kind
25
+ # ^^^ name
26
+ # ^^^ overload
27
+ #
28
+ type loc = Location::WithChildren[:keyword | :name, :kind | :overload]
29
+
18
30
  attr_reader name: Symbol
19
31
  attr_reader kind: kind
20
32
  attr_reader types: Array[MethodType]
21
33
  attr_reader annotations: Array[Annotation]
22
- attr_reader location: Location?
34
+ attr_reader location: loc?
23
35
  attr_reader comment: Comment?
24
36
  attr_reader overload: bool
25
37
 
26
- def initialize: (name: Symbol, kind: kind, types: Array[MethodType], annotations: Array[Annotation], location: Location?, comment: Comment?, overload: boolish) -> void
38
+ def initialize: (name: Symbol, kind: kind, types: Array[MethodType], annotations: Array[Annotation], location: loc?, comment: Comment?, overload: boolish) -> void
27
39
 
28
40
  include _HashEqual
29
41
  include _ToJson
@@ -34,16 +46,27 @@ module RBS
34
46
 
35
47
  def overload?: () -> bool
36
48
 
37
- def update: (?name: Symbol, ?kind: kind, ?types: Array[MethodType], ?annotations: Array[Annotation], ?location: Location?, ?comment: Comment?, ?overload: boolish) -> MethodDefinition
49
+ def update: (?name: Symbol, ?kind: kind, ?types: Array[MethodType], ?annotations: Array[Annotation], ?location: loc?, ?comment: Comment?, ?overload: boolish) -> MethodDefinition
38
50
  end
39
51
 
40
52
  module Var
53
+ # @foo: String
54
+ # ^^^^ name
55
+ # ^ colon
56
+ #
57
+ # self.@all: Array[String]
58
+ # ^^^^^ kind
59
+ # ^^^^ name
60
+ # ^ colon
61
+ #
62
+ type loc = Location::WithChildren[:name | :colon, :kind]
63
+
41
64
  attr_reader name: Symbol
42
65
  attr_reader type: Types::t
43
- attr_reader location: Location?
66
+ attr_reader location: loc?
44
67
  attr_reader comment: Comment?
45
68
 
46
- def initialize: (name: Symbol, type: Types::t, location: Location?, comment: Comment?) -> void
69
+ def initialize: (name: Symbol, type: Types::t, location: loc?, comment: Comment?) -> void
47
70
 
48
71
  include _HashEqual
49
72
  end
@@ -64,13 +87,25 @@ module RBS
64
87
  end
65
88
 
66
89
  module Mixin
90
+ # include Foo
91
+ # ^^^^^^^ keyword
92
+ # ^^^ name
93
+ #
94
+ # include Array[String]
95
+ # ^^^^^^^ keyword
96
+ # ^^^^^ name
97
+ # ^ arg_open
98
+ # ^ arg_close
99
+ #
100
+ type loc = Location::WithChildren[:name | :keyword, :args]
101
+
67
102
  attr_reader name: TypeName
68
103
  attr_reader args: Array[Types::t]
69
104
  attr_reader annotations: Array[Annotation]
70
- attr_reader location: Location?
105
+ attr_reader location: loc?
71
106
  attr_reader comment: Comment?
72
107
 
73
- def initialize: (name: TypeName, args: Array[Types::t], annotations: Array[Annotation], location: Location?, comment: Comment?) -> void
108
+ def initialize: (name: TypeName, args: Array[Types::t], annotations: Array[Annotation], location: loc?, comment: Comment?) -> void
74
109
 
75
110
  include _HashEqual
76
111
  end
@@ -93,19 +128,34 @@ module RBS
93
128
  module Attribute
94
129
  type kind = :instance | :singleton
95
130
 
131
+ # attr_reader name: String
132
+ # ^^^^^^^^^^^ keyword
133
+ # ^^^^ name
134
+ # ^ colon
135
+ #
136
+ # attr_accessor self.name (@foo) : String
137
+ # ^^^^^^^^^^^^^ keyword
138
+ # ^^^^^ kind
139
+ # ^^^^ name
140
+ # ^^^^^^ ivar
141
+ # ^^^^ ivar_name
142
+ # ^ colon
143
+ #
144
+ type loc = Location::WithChildren[:keyword | :name | :colon, :kind | :ivar | :ivar_name]
145
+
96
146
  attr_reader name: Symbol
97
147
  attr_reader type: Types::t
98
148
  attr_reader kind: kind
99
149
  attr_reader ivar_name: Symbol | false | nil
100
150
  attr_reader annotations: Array[Annotation]
101
- attr_reader location: Location?
151
+ attr_reader location: loc?
102
152
  attr_reader comment: Comment?
103
153
 
104
- def initialize: (name: Symbol, type: Types::t, ivar_name: Symbol | false | nil, kind: kind, annotations: Array[Annotation], location: Location?, comment: Comment?) -> void
154
+ def initialize: (name: Symbol, type: Types::t, ivar_name: Symbol | false | nil, kind: kind, annotations: Array[Annotation], location: loc?, comment: Comment?) -> void
105
155
 
106
156
  include _HashEqual
107
157
 
108
- def update: (?name: Symbol, ?type: Types::t, ?ivar_name: Symbol | false | nil, ?kind: kind, ?annotations: Array[Annotation], ?location: Location?, ?comment: Comment?) -> instance
158
+ def update: (?name: Symbol, ?type: Types::t, ?ivar_name: Symbol | false | nil, ?kind: kind, ?annotations: Array[Annotation], ?location: loc?, ?comment: Comment?) -> instance
109
159
  end
110
160
 
111
161
  class AttrReader < Base
@@ -144,14 +194,28 @@ module RBS
144
194
  class Alias < Base
145
195
  type kind = :instance | :singleton
146
196
 
197
+ # alias foo bar
198
+ # ^^^^^ keyword
199
+ # ^^^ new_name
200
+ # ^^^ old_name
201
+ #
202
+ # alias self.foo self.bar
203
+ # ^^^^^ keyword
204
+ # ^^^^^ new_kind
205
+ # ^^^ new_name
206
+ # ^^^^^ old_kind
207
+ # ^^^ old_name
208
+ #
209
+ type loc = Location::WithChildren[:keyword | :new_name | :old_name, :new_kind | :old_kind]
210
+
147
211
  attr_reader new_name: Symbol
148
212
  attr_reader old_name: Symbol
149
213
  attr_reader kind: kind
150
214
  attr_reader annotations: Array[Annotation]
151
- attr_reader location: Location?
215
+ attr_reader location: loc?
152
216
  attr_reader comment: Comment?
153
217
 
154
- def initialize: (new_name: Symbol, old_name: Symbol, kind: kind, annotations: Array[Annotation], location: Location?, comment: Comment?) -> void
218
+ def initialize: (new_name: Symbol, old_name: Symbol, kind: kind, annotations: Array[Annotation], location: loc?, comment: Comment?) -> void
155
219
 
156
220
  include _HashEqual
157
221
  include _ToJson
@@ -20,7 +20,7 @@ module RBS
20
20
 
21
21
  def accessibility: () -> accessibility
22
22
 
23
- def self.empty: (name: Symbol, type: instance_type) -> instance
23
+ def self.empty: (name: Symbol, type: instance_type) -> Definition
24
24
  end
25
25
 
26
26
  attr_reader type: instance_type
data/sig/method_types.rbs CHANGED
@@ -9,7 +9,7 @@ module RBS
9
9
 
10
10
  def ==: (untyped other) -> bool
11
11
 
12
- def to_json: (*untyped) -> String
12
+ include _ToJson
13
13
 
14
14
  def sub: (Substitution) -> MethodType
15
15
 
data/sig/polyfill.rbs CHANGED
@@ -1,5 +1,4 @@
1
1
  module Kernel
2
- def to_json: (*untyped) -> String
3
2
  end
4
3
 
5
4
  module Gem
@@ -14,18 +13,24 @@ end
14
13
 
15
14
  class OptionParser
16
15
  def initialize: () ?{ (instance) -> void } -> void
17
-
18
- def on: (*String) { (String) -> void } -> void
19
-
16
+
17
+ def on: [T] (*String) { (T) -> void } -> void
18
+
20
19
  attr_accessor version: String
21
-
20
+
22
21
  attr_accessor banner: String
23
22
 
24
23
  def order!: (Array[String]) -> void
25
-
24
+
26
25
  def parse!: (Array[String]) -> void
27
-
26
+
28
27
  def ver: () -> String
29
-
28
+
30
29
  def help: () -> String
31
30
  end
31
+
32
+ module Enumerable[unchecked out Elem]
33
+ def flat_map: [U] () { (Elem) -> Array[U] } -> Array[U]
34
+ | [U] () { (Elem) -> U } -> Array[U]
35
+ | ...
36
+ end
data/sig/rbs.rbs CHANGED
@@ -1,11 +1,15 @@
1
1
  module RBS
2
2
  def self.logger: () -> Logger
3
-
3
+
4
4
  def self.logger_level: () -> untyped
5
-
5
+
6
6
  def self.logger_level=: (untyped) -> untyped
7
-
7
+
8
8
  def self.logger_output: () -> IO
9
-
9
+
10
10
  def self.logger_output=: (IO) -> IO
11
11
  end
12
+
13
+ module Ruby
14
+ Signature: singleton(RBS)
15
+ end
data/sig/typename.rbs CHANGED
@@ -34,7 +34,7 @@ module RBS
34
34
 
35
35
  def to_s: () -> ::String
36
36
 
37
- def to_json: (*untyped a) -> untyped
37
+ include _ToJson
38
38
 
39
39
  # Returns a namespace with same components of self.
40
40
  def to_namespace: () -> Namespace
data/sig/types.rbs CHANGED
@@ -3,11 +3,6 @@ module RBS
3
3
  # _TypeBase interface represents the operations common to all of the types.
4
4
  #
5
5
  interface _TypeBase
6
- # Location for types in the RBS source code.
7
- # `nil` means there is no RBS source code for the type.
8
- #
9
- def location: () -> Location?
10
-
11
6
  # Returns names of free variables of a type.
12
7
  # You can pass a Set instance to add the free variables to the set to avoid Set object allocation.
13
8
  #
@@ -32,7 +27,7 @@ module RBS
32
27
 
33
28
  # Returns a JSON representation.
34
29
  #
35
- def to_json: (*untyped) -> String
30
+ include _ToJson
36
31
 
37
32
  # Returns a String representation.
38
33
  # `level` is used internally.
@@ -70,6 +65,8 @@ module RBS
70
65
  class Base
71
66
  include _TypeBase
72
67
 
68
+ attr_reader location: Location?
69
+
73
70
  def initialize: (location: Location?) -> void
74
71
 
75
72
  def ==: (untyped other) -> bool
@@ -119,12 +116,13 @@ module RBS
119
116
  @@count: Integer
120
117
 
121
118
  include _TypeBase
122
-
123
119
  include NoTypeName
124
120
  include EmptyEachType
125
121
 
126
122
  def initialize: (name: Symbol, location: Location?) -> void
127
123
 
124
+ attr_reader location: Location?
125
+
128
126
  def ==: (untyped other) -> bool
129
127
 
130
128
  alias eql? ==
@@ -144,21 +142,26 @@ module RBS
144
142
  end
145
143
 
146
144
  class ClassSingleton
145
+ # singleton(::Foo)
146
+ # ^^^^^ => name
147
+ type loc = Location::WithChildren[:name, bot]
148
+
149
+ def initialize: (name: TypeName, location: loc?) -> void
150
+
147
151
  attr_reader name: TypeName
148
152
 
149
- include _TypeBase
153
+ attr_reader location: loc?
150
154
 
151
- def initialize: (name: TypeName, location: Location?) -> void
155
+ include _TypeBase
156
+ include NoFreeVariables
157
+ include NoSubst
158
+ include EmptyEachType
152
159
 
153
160
  def ==: (untyped other) -> bool
154
161
 
155
162
  alias eql? ==
156
163
 
157
164
  def hash: () -> Integer
158
-
159
- include NoFreeVariables
160
- include NoSubst
161
- include EmptyEachType
162
165
  end
163
166
 
164
167
  module Application
@@ -180,11 +183,20 @@ module RBS
180
183
  end
181
184
 
182
185
  class Interface
183
- include Application
186
+ # _Foo
187
+ # ^^^^ => name
188
+ #
189
+ # _Foo[Bar, Baz]
190
+ # ^^^^ => name
191
+ # ^^^^^^^^^^ => args
192
+ type loc = Location::WithChildren[:name, :args]
184
193
 
185
- def initialize: (name: TypeName, args: Array[t], location: Location?) -> void
194
+ def initialize: (name: TypeName, args: Array[t], location: loc?) -> void
186
195
 
196
+ include Application
187
197
  include _TypeBase
198
+
199
+ attr_reader location: loc?
188
200
  end
189
201
 
190
202
  # ClassInstance represents a type of an instance of a class.
@@ -196,7 +208,17 @@ module RBS
196
208
  class ClassInstance
197
209
  include Application
198
210
 
199
- def initialize: (name: TypeName, args: Array[t], location: Location?) -> void
211
+ # Foo
212
+ # ^^^ => name
213
+ #
214
+ # Foo[Bar, Baz]
215
+ # ^^^ => name
216
+ # ^^^^^^^^^^ => args
217
+ type loc = Location::WithChildren[:name, :args]
218
+
219
+ def initialize: (name: TypeName, args: Array[t], location: loc?) -> void
220
+
221
+ attr_reader location: loc?
200
222
 
201
223
  include _TypeBase
202
224
  end
@@ -210,6 +232,8 @@ module RBS
210
232
  include NoFreeVariables
211
233
  include NoSubst
212
234
  include EmptyEachType
235
+
236
+ attr_reader location: Location?
213
237
  end
214
238
 
215
239
  class Tuple
@@ -218,6 +242,8 @@ module RBS
218
242
  def initialize: (types: Array[t], location: Location?) -> void
219
243
 
220
244
  include _TypeBase
245
+
246
+ attr_reader location: Location?
221
247
  end
222
248
 
223
249
  class Record
@@ -226,6 +252,8 @@ module RBS
226
252
  def initialize: (fields: Hash[Symbol, t], location: Location?) -> void
227
253
 
228
254
  include _TypeBase
255
+
256
+ attr_reader location: Location?
229
257
  end
230
258
 
231
259
  class Optional
@@ -234,6 +262,8 @@ module RBS
234
262
  def initialize: (type: t, location: Location?) -> void
235
263
 
236
264
  include _TypeBase
265
+
266
+ attr_reader location: Location?
237
267
  end
238
268
 
239
269
  class Union
@@ -243,6 +273,8 @@ module RBS
243
273
 
244
274
  include _TypeBase
245
275
 
276
+ attr_reader location: Location?
277
+
246
278
  def map_type: () { (t) -> t } -> Union
247
279
  | () -> Enumerator[t, Union]
248
280
  end
@@ -254,16 +286,21 @@ module RBS
254
286
 
255
287
  include _TypeBase
256
288
 
289
+ attr_reader location: Location?
290
+
257
291
  def map_type: () { (t) -> t } -> Intersection
258
292
  | () -> Enumerator[t, Intersection]
259
293
  end
260
294
 
261
295
  class Function
262
296
  class Param
297
+ type loc = Location::WithChildren[bot, :name]
298
+
263
299
  attr_reader type: t
264
300
  attr_reader name: Symbol?
301
+ attr_reader location: loc?
265
302
 
266
- def initialize: (type: t, name: Symbol?) -> void
303
+ def initialize: (type: t, name: Symbol?, ?location: loc?) -> void
267
304
 
268
305
  def map_type: { (t) -> t } -> Param
269
306
  | -> Enumerator[t, Param]
@@ -300,7 +337,7 @@ module RBS
300
337
  def each_param: () { (Param) -> void } -> void
301
338
  | -> Enumerator[Param, void]
302
339
 
303
- def to_json: (*untyped) -> String
340
+ include _ToJson
304
341
 
305
342
  def sub: (Substitution) -> Function
306
343
 
@@ -336,7 +373,7 @@ module RBS
336
373
 
337
374
  def ==: (untyped other) -> bool
338
375
 
339
- def to_json: (*untyped) -> String
376
+ include _ToJson
340
377
 
341
378
  def sub: (Substitution) -> Block
342
379
 
@@ -350,6 +387,8 @@ module RBS
350
387
  def initialize: (location: Location?, type: Function, block: Block?) -> void
351
388
 
352
389
  include _TypeBase
390
+
391
+ attr_reader location: Location?
353
392
  end
354
393
 
355
394
  class Literal
@@ -364,6 +403,8 @@ module RBS
364
403
  include NoSubst
365
404
  include EmptyEachType
366
405
  include NoTypeName
406
+
407
+ attr_reader location: Location?
367
408
  end
368
409
  end
369
410
  end