steep-relaxed 1.9.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -0
  3. data/.gitmodules +0 -0
  4. data/CHANGELOG.md +1032 -0
  5. data/LICENSE +21 -0
  6. data/README.md +260 -0
  7. data/Rakefile +227 -0
  8. data/STDGEM_DEPENDENCIES.txt +59 -0
  9. data/Steepfile +68 -0
  10. data/bin/console +14 -0
  11. data/bin/generate-diagnostics-docs.rb +112 -0
  12. data/bin/mem_graph.rb +67 -0
  13. data/bin/mem_prof.rb +102 -0
  14. data/bin/output_rebaseline.rb +34 -0
  15. data/bin/output_test.rb +60 -0
  16. data/bin/rbs +20 -0
  17. data/bin/rbs-inline +19 -0
  18. data/bin/setup +9 -0
  19. data/bin/stackprof_test.rb +19 -0
  20. data/bin/steep +19 -0
  21. data/bin/steep-check.rb +251 -0
  22. data/bin/steep-prof +16 -0
  23. data/doc/narrowing.md +195 -0
  24. data/doc/shape.md +194 -0
  25. data/exe/steep +18 -0
  26. data/guides/README.md +5 -0
  27. data/guides/src/gem-rbs-collection/gem-rbs-collection.md +126 -0
  28. data/guides/src/getting-started/getting-started.md +163 -0
  29. data/guides/src/nil-optional/nil-optional.md +195 -0
  30. data/lib/steep/annotation_parser.rb +199 -0
  31. data/lib/steep/ast/annotation/collection.rb +172 -0
  32. data/lib/steep/ast/annotation.rb +137 -0
  33. data/lib/steep/ast/builtin.rb +104 -0
  34. data/lib/steep/ast/ignore.rb +148 -0
  35. data/lib/steep/ast/node/type_application.rb +88 -0
  36. data/lib/steep/ast/node/type_assertion.rb +81 -0
  37. data/lib/steep/ast/types/any.rb +35 -0
  38. data/lib/steep/ast/types/boolean.rb +45 -0
  39. data/lib/steep/ast/types/bot.rb +35 -0
  40. data/lib/steep/ast/types/class.rb +43 -0
  41. data/lib/steep/ast/types/factory.rb +557 -0
  42. data/lib/steep/ast/types/helper.rb +40 -0
  43. data/lib/steep/ast/types/instance.rb +42 -0
  44. data/lib/steep/ast/types/intersection.rb +93 -0
  45. data/lib/steep/ast/types/literal.rb +59 -0
  46. data/lib/steep/ast/types/logic.rb +84 -0
  47. data/lib/steep/ast/types/name.rb +128 -0
  48. data/lib/steep/ast/types/nil.rb +41 -0
  49. data/lib/steep/ast/types/proc.rb +117 -0
  50. data/lib/steep/ast/types/record.rb +79 -0
  51. data/lib/steep/ast/types/self.rb +43 -0
  52. data/lib/steep/ast/types/shared_instance.rb +11 -0
  53. data/lib/steep/ast/types/top.rb +35 -0
  54. data/lib/steep/ast/types/tuple.rb +60 -0
  55. data/lib/steep/ast/types/union.rb +97 -0
  56. data/lib/steep/ast/types/var.rb +65 -0
  57. data/lib/steep/ast/types/void.rb +35 -0
  58. data/lib/steep/cli.rb +401 -0
  59. data/lib/steep/diagnostic/deprecated/else_on_exhaustive_case.rb +20 -0
  60. data/lib/steep/diagnostic/deprecated/unknown_constant_assigned.rb +28 -0
  61. data/lib/steep/diagnostic/helper.rb +18 -0
  62. data/lib/steep/diagnostic/lsp_formatter.rb +78 -0
  63. data/lib/steep/diagnostic/result_printer2.rb +48 -0
  64. data/lib/steep/diagnostic/ruby.rb +1221 -0
  65. data/lib/steep/diagnostic/signature.rb +570 -0
  66. data/lib/steep/drivers/annotations.rb +52 -0
  67. data/lib/steep/drivers/check.rb +339 -0
  68. data/lib/steep/drivers/checkfile.rb +210 -0
  69. data/lib/steep/drivers/diagnostic_printer.rb +105 -0
  70. data/lib/steep/drivers/init.rb +66 -0
  71. data/lib/steep/drivers/langserver.rb +56 -0
  72. data/lib/steep/drivers/print_project.rb +113 -0
  73. data/lib/steep/drivers/stats.rb +203 -0
  74. data/lib/steep/drivers/utils/driver_helper.rb +143 -0
  75. data/lib/steep/drivers/utils/jobs_option.rb +26 -0
  76. data/lib/steep/drivers/vendor.rb +27 -0
  77. data/lib/steep/drivers/watch.rb +194 -0
  78. data/lib/steep/drivers/worker.rb +58 -0
  79. data/lib/steep/equatable.rb +23 -0
  80. data/lib/steep/expectations.rb +228 -0
  81. data/lib/steep/index/rbs_index.rb +350 -0
  82. data/lib/steep/index/signature_symbol_provider.rb +185 -0
  83. data/lib/steep/index/source_index.rb +167 -0
  84. data/lib/steep/interface/block.rb +103 -0
  85. data/lib/steep/interface/builder.rb +843 -0
  86. data/lib/steep/interface/function.rb +1090 -0
  87. data/lib/steep/interface/method_type.rb +330 -0
  88. data/lib/steep/interface/shape.rb +239 -0
  89. data/lib/steep/interface/substitution.rb +159 -0
  90. data/lib/steep/interface/type_param.rb +115 -0
  91. data/lib/steep/located_value.rb +20 -0
  92. data/lib/steep/method_name.rb +42 -0
  93. data/lib/steep/module_helper.rb +24 -0
  94. data/lib/steep/node_helper.rb +273 -0
  95. data/lib/steep/path_helper.rb +30 -0
  96. data/lib/steep/project/dsl.rb +268 -0
  97. data/lib/steep/project/group.rb +31 -0
  98. data/lib/steep/project/options.rb +63 -0
  99. data/lib/steep/project/pattern.rb +59 -0
  100. data/lib/steep/project/target.rb +92 -0
  101. data/lib/steep/project.rb +78 -0
  102. data/lib/steep/rake_task.rb +132 -0
  103. data/lib/steep/range_extension.rb +29 -0
  104. data/lib/steep/server/base_worker.rb +97 -0
  105. data/lib/steep/server/change_buffer.rb +73 -0
  106. data/lib/steep/server/custom_methods.rb +77 -0
  107. data/lib/steep/server/delay_queue.rb +45 -0
  108. data/lib/steep/server/interaction_worker.rb +492 -0
  109. data/lib/steep/server/lsp_formatter.rb +455 -0
  110. data/lib/steep/server/master.rb +922 -0
  111. data/lib/steep/server/target_group_files.rb +205 -0
  112. data/lib/steep/server/type_check_controller.rb +366 -0
  113. data/lib/steep/server/type_check_worker.rb +303 -0
  114. data/lib/steep/server/work_done_progress.rb +64 -0
  115. data/lib/steep/server/worker_process.rb +176 -0
  116. data/lib/steep/services/completion_provider.rb +802 -0
  117. data/lib/steep/services/content_change.rb +61 -0
  118. data/lib/steep/services/file_loader.rb +74 -0
  119. data/lib/steep/services/goto_service.rb +441 -0
  120. data/lib/steep/services/hover_provider/rbs.rb +88 -0
  121. data/lib/steep/services/hover_provider/ruby.rb +221 -0
  122. data/lib/steep/services/hover_provider/singleton_methods.rb +20 -0
  123. data/lib/steep/services/path_assignment.rb +46 -0
  124. data/lib/steep/services/signature_help_provider.rb +202 -0
  125. data/lib/steep/services/signature_service.rb +428 -0
  126. data/lib/steep/services/stats_calculator.rb +68 -0
  127. data/lib/steep/services/type_check_service.rb +394 -0
  128. data/lib/steep/services/type_name_completion.rb +236 -0
  129. data/lib/steep/signature/validator.rb +651 -0
  130. data/lib/steep/source/ignore_ranges.rb +69 -0
  131. data/lib/steep/source.rb +691 -0
  132. data/lib/steep/subtyping/cache.rb +30 -0
  133. data/lib/steep/subtyping/check.rb +1113 -0
  134. data/lib/steep/subtyping/constraints.rb +341 -0
  135. data/lib/steep/subtyping/relation.rb +101 -0
  136. data/lib/steep/subtyping/result.rb +324 -0
  137. data/lib/steep/subtyping/variable_variance.rb +89 -0
  138. data/lib/steep/test.rb +9 -0
  139. data/lib/steep/thread_waiter.rb +43 -0
  140. data/lib/steep/type_construction.rb +5183 -0
  141. data/lib/steep/type_inference/block_params.rb +416 -0
  142. data/lib/steep/type_inference/case_when.rb +303 -0
  143. data/lib/steep/type_inference/constant_env.rb +56 -0
  144. data/lib/steep/type_inference/context.rb +195 -0
  145. data/lib/steep/type_inference/logic_type_interpreter.rb +613 -0
  146. data/lib/steep/type_inference/method_call.rb +193 -0
  147. data/lib/steep/type_inference/method_params.rb +531 -0
  148. data/lib/steep/type_inference/multiple_assignment.rb +194 -0
  149. data/lib/steep/type_inference/send_args.rb +712 -0
  150. data/lib/steep/type_inference/type_env.rb +341 -0
  151. data/lib/steep/type_inference/type_env_builder.rb +138 -0
  152. data/lib/steep/typing.rb +321 -0
  153. data/lib/steep/version.rb +3 -0
  154. data/lib/steep.rb +369 -0
  155. data/manual/annotations.md +181 -0
  156. data/manual/ignore.md +20 -0
  157. data/manual/ruby-diagnostics.md +1879 -0
  158. data/sample/Steepfile +22 -0
  159. data/sample/lib/conference.rb +49 -0
  160. data/sample/lib/length.rb +35 -0
  161. data/sample/sig/conference.rbs +42 -0
  162. data/sample/sig/generics.rbs +15 -0
  163. data/sample/sig/length.rbs +34 -0
  164. data/steep-relaxed.gemspec +56 -0
  165. metadata +340 -0
@@ -0,0 +1,172 @@
1
+ module Steep
2
+ module AST
3
+ module Annotation
4
+ class Collection
5
+ attr_reader :annotations
6
+ attr_reader :factory
7
+ attr_reader :context
8
+
9
+ attr_reader :var_type_annotations
10
+ attr_reader :const_type_annotations
11
+ attr_reader :ivar_type_annotations
12
+ attr_reader :method_type_annotations
13
+ attr_reader :block_type_annotation
14
+ attr_reader :return_type_annotation
15
+ attr_reader :self_type_annotation
16
+ attr_reader :instance_type_annotation
17
+ attr_reader :module_type_annotation
18
+ attr_reader :implement_module_annotation
19
+ attr_reader :dynamic_annotations
20
+ attr_reader :break_type_annotation
21
+
22
+ def initialize(annotations:, factory:, context:)
23
+ @annotations = annotations
24
+ @factory = factory
25
+ @context = context
26
+
27
+ @var_type_annotations = {}
28
+ @method_type_annotations = {}
29
+ @const_type_annotations = {}
30
+ @ivar_type_annotations = {}
31
+ @dynamic_annotations = []
32
+
33
+ annotations.each do |annotation|
34
+ case annotation
35
+ when VarType
36
+ var_type_annotations[annotation.name] = annotation
37
+ when MethodType
38
+ method_type_annotations[annotation.name] = annotation
39
+ when BlockType
40
+ @block_type_annotation = annotation
41
+ when ReturnType
42
+ @return_type_annotation = annotation
43
+ when SelfType
44
+ @self_type_annotation = annotation
45
+ when ConstType
46
+ @const_type_annotations[annotation.name] = annotation
47
+ when InstanceType
48
+ @instance_type_annotation = annotation
49
+ when ModuleType
50
+ @module_type_annotation = annotation
51
+ when Implements
52
+ @implement_module_annotation = annotation
53
+ when IvarType
54
+ @ivar_type_annotations[annotation.name] = annotation
55
+ when Dynamic
56
+ @dynamic_annotations << annotation
57
+ when BreakType
58
+ @break_type_annotation = annotation
59
+ else
60
+ raise "Unexpected annotation: #{annotation.inspect}"
61
+ end
62
+ end
63
+ end
64
+
65
+ def absolute_type(type)
66
+ if type
67
+ factory.absolute_type(type, context: context)
68
+ end
69
+ end
70
+
71
+ def var_type(lvar: nil, ivar: nil, const: nil)
72
+ case
73
+ when lvar
74
+ absolute_type(var_type_annotations[lvar]&.type)
75
+ when ivar
76
+ absolute_type(ivar_type_annotations[ivar]&.type)
77
+ when const
78
+ absolute_type(const_type_annotations[const]&.type)
79
+ end
80
+ end
81
+
82
+ def method_type(name)
83
+ if (a = method_type_annotations[name])
84
+ a.type.map_type {|type| absolute_type(type) }
85
+ end
86
+ end
87
+
88
+ def block_type
89
+ absolute_type(block_type_annotation&.type)
90
+ end
91
+
92
+ def return_type
93
+ absolute_type(return_type_annotation&.type)
94
+ end
95
+
96
+ def self_type
97
+ absolute_type(self_type_annotation&.type)
98
+ end
99
+
100
+ def instance_type
101
+ absolute_type(instance_type_annotation&.type)
102
+ end
103
+
104
+ def module_type
105
+ absolute_type(module_type_annotation&.type)
106
+ end
107
+
108
+ def break_type
109
+ absolute_type(break_type_annotation&.type)
110
+ end
111
+
112
+ def lvar_types
113
+ var_type_annotations.each_key.with_object({}) do |name, hash| #$ Hash[Symbol, Types::t]
114
+ hash[name] = var_type(lvar: name) || raise
115
+ end
116
+ end
117
+
118
+ def ivar_types
119
+ ivar_type_annotations.each_key.with_object({}) do |name, hash| #$ Hash[Symbol, Types::t]
120
+ hash[name] = var_type(ivar: name) || raise
121
+ end
122
+ end
123
+
124
+ def const_types
125
+ const_type_annotations.each_key.with_object({}) do |name, hash| #$ Hash[RBS::TypeName, Types::t]
126
+ hash[name] = var_type(const: name) || raise
127
+ end
128
+ end
129
+
130
+ def instance_dynamics
131
+ dynamic_annotations.flat_map do |annot|
132
+ annot.names.select(&:instance_method?).map(&:name)
133
+ end
134
+ end
135
+
136
+ def module_dynamics
137
+ dynamic_annotations.flat_map do |annot|
138
+ annot.names.select(&:module_method?).map(&:name)
139
+ end
140
+ end
141
+
142
+ def merge_block_annotations(annotations)
143
+ if annotations.context != context || annotations.factory != factory
144
+ raise "Cannot merge another annotation: self=#{self}, other=#{annotations}"
145
+ end
146
+
147
+ retained_annotations = self.annotations.reject do |annotation|
148
+ annotation.is_a?(BlockType) || annotation.is_a?(BreakType)
149
+ end
150
+
151
+ self.class.new(
152
+ annotations: retained_annotations + annotations.annotations,
153
+ factory: factory,
154
+ context: context
155
+ )
156
+ end
157
+
158
+ def any?(&block)
159
+ annotations.any?(&block)
160
+ end
161
+
162
+ def size
163
+ annotations.size
164
+ end
165
+
166
+ def include?(obj)
167
+ annotations.include?(obj)
168
+ end
169
+ end
170
+ end
171
+ end
172
+ end
@@ -0,0 +1,137 @@
1
+ module Steep
2
+ module AST
3
+ module Annotation
4
+ module Located
5
+ attr_reader :location
6
+
7
+ def line
8
+ location&.start_line
9
+ end
10
+ end
11
+
12
+ class Named
13
+ include Located
14
+
15
+ attr_reader :name
16
+ attr_reader :type
17
+
18
+ def initialize(name:, type:, location: nil)
19
+ @name = name
20
+ @type = type
21
+ @location = location
22
+ end
23
+
24
+ def ==(other)
25
+ other.is_a?(self.class) &&
26
+ other.name == name &&
27
+ other.type == type
28
+ end
29
+ end
30
+
31
+ class Typed
32
+ include Located
33
+
34
+ attr_reader :type
35
+
36
+ def initialize(type:, location: nil)
37
+ @type = type
38
+ @location = location
39
+ end
40
+
41
+ def ==(other)
42
+ other.is_a?(self.class) &&
43
+ other.type == type
44
+ end
45
+ end
46
+
47
+ class ReturnType < Typed; end
48
+ class BlockType < Typed; end
49
+ class SelfType < Typed; end
50
+ class InstanceType < Typed; end
51
+ class ModuleType < Typed; end
52
+ class BreakType < Typed; end
53
+
54
+ class MethodType < Named; end
55
+ class VarType < Named; end
56
+ class ConstType < Named; end
57
+ class IvarType < Named; end
58
+
59
+ class Implements
60
+ class Module
61
+ attr_reader :name
62
+ attr_reader :args
63
+
64
+ def initialize(name:, args:)
65
+ @name = name
66
+ @args = args
67
+ end
68
+
69
+ def ==(other)
70
+ other.is_a?(Module) && other.name == name && other.args == args
71
+ end
72
+
73
+ alias eql? ==
74
+
75
+ def hash
76
+ self.class.hash ^ name.hash ^ args.hash
77
+ end
78
+ end
79
+
80
+ include Located
81
+
82
+ attr_reader :name
83
+
84
+ def initialize(name:, location: nil)
85
+ @location = location
86
+ @name = name
87
+ end
88
+
89
+ def ==(other)
90
+ other.is_a?(Implements) && other.name == name
91
+ end
92
+ end
93
+
94
+ class Dynamic
95
+ class Name
96
+ attr_reader :kind
97
+ attr_reader :name
98
+ attr_reader :location
99
+
100
+ def initialize(name:, kind:, location: nil)
101
+ @name = name
102
+ @kind = kind
103
+ @location = location
104
+ end
105
+
106
+ def instance_method?
107
+ kind == :instance || kind == :module_instance
108
+ end
109
+
110
+ def module_method?
111
+ kind == :module || kind == :module_instance
112
+ end
113
+
114
+ def ==(other)
115
+ other.is_a?(Name) &&
116
+ other.name == name &&
117
+ other.kind == kind
118
+ end
119
+ end
120
+
121
+ include Located
122
+
123
+ attr_reader :names
124
+
125
+ def initialize(names:, location: nil)
126
+ @location = location
127
+ @names = names
128
+ end
129
+
130
+ def ==(other)
131
+ other.is_a?(Dynamic) &&
132
+ other.names == names
133
+ end
134
+ end
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,104 @@
1
+ module Steep
2
+ module AST
3
+ module Builtin
4
+ class Type
5
+ attr_reader :module_name
6
+ attr_reader :arity
7
+
8
+ def initialize(module_name, arity: 0)
9
+ @module_name = RBS::TypeName.parse(module_name)
10
+ @arity = arity
11
+ end
12
+
13
+ def instance_type(*args, fill_untyped: false)
14
+ if fill_untyped
15
+ (arity - args.size).times do
16
+ args << Builtin.any_type
17
+ end
18
+ end
19
+ arity == args.size or raise "Malformed instance type: name=#{module_name}, args=#{args}"
20
+
21
+ Types::Name::Instance.new(name: module_name, args: args)
22
+ end
23
+
24
+ def module_type
25
+ Types::Name::Singleton.new(name: module_name)
26
+ end
27
+
28
+ def instance_type?(type, args: nil)
29
+ if type.is_a?(Types::Name::Instance)
30
+ if args
31
+ arity == args.size or raise "Malformed instance type: name=#{module_name}, args=#{args}"
32
+ if type.name == module_name && type.args == args
33
+ type
34
+ end
35
+ else
36
+ if type.name == module_name && type.args.size == arity
37
+ type
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ def module_type?(type)
44
+ if type.is_a?(Types::Name::Singleton)
45
+ if type.name == module_name
46
+ type
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ Object = Type.new("::Object")
53
+ BasicObject = Type.new("::BasicObject")
54
+ Array = Type.new("::Array", arity: 1)
55
+ Range = Type.new("::Range", arity: 1)
56
+ Hash = Type.new("::Hash", arity: 2)
57
+ Module = Type.new("::Module")
58
+ Class = Type.new("::Class")
59
+ Integer = Type.new("::Integer")
60
+ Float = Type.new("::Float")
61
+ String = Type.new("::String")
62
+ Symbol = Type.new("::Symbol")
63
+ TrueClass = Type.new("::TrueClass")
64
+ FalseClass = Type.new("::FalseClass")
65
+ Regexp = Type.new("::Regexp")
66
+ NilClass = Type.new("::NilClass")
67
+ Proc = Type.new("::Proc")
68
+ Kernel = Type.new("::Kernel")
69
+ Method = Type.new("::Method")
70
+
71
+ def self.nil_type
72
+ AST::Types::Nil.instance
73
+ end
74
+
75
+ def self.any_type
76
+ AST::Types::Any.instance
77
+ end
78
+
79
+ def self.bool_type
80
+ AST::Types::Boolean.instance
81
+ end
82
+
83
+ def self.bottom_type
84
+ AST::Types::Bot.instance
85
+ end
86
+
87
+ def self.top_type
88
+ AST::Types::Top.instance
89
+ end
90
+
91
+ def self.optional(type)
92
+ AST::Types::Union.build(types: [type, nil_type])
93
+ end
94
+
95
+ def self.true_type
96
+ AST::Types::Literal.new(value: true)
97
+ end
98
+
99
+ def self.false_type
100
+ AST::Types::Literal.new(value: false)
101
+ end
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,148 @@
1
+ module Steep
2
+ module AST
3
+ module Ignore
4
+ class BufferScanner
5
+ attr_reader :scanner, :location
6
+
7
+ def initialize(location)
8
+ @location = location
9
+
10
+ @scanner = StringScanner.new(location.source)
11
+ end
12
+
13
+ def offset
14
+ @location.start_pos
15
+ end
16
+
17
+ def charpos
18
+ scanner.charpos + offset
19
+ end
20
+
21
+ def scan(regexp)
22
+ if matched = scanner.scan(regexp)
23
+ end_pos = charpos()
24
+ begin_pos = end_pos - matched.size
25
+ RBS::Location.new(location.buffer, begin_pos, end_pos)
26
+ end
27
+ end
28
+
29
+ def skip(regexp)
30
+ scanner.skip(regexp)
31
+ end
32
+
33
+ def eos?
34
+ scanner.eos?
35
+ end
36
+ end
37
+
38
+ class IgnoreStart
39
+ attr_reader :comment, :location
40
+
41
+ def initialize(comment, location)
42
+ @comment = comment
43
+ @location = location
44
+ end
45
+
46
+ def line
47
+ location.start_line
48
+ end
49
+ end
50
+
51
+ class IgnoreEnd
52
+ attr_reader :comment, :location
53
+
54
+ def initialize(comment, location)
55
+ @comment = comment
56
+ @location = location
57
+ end
58
+
59
+ def line
60
+ location.start_line
61
+ end
62
+ end
63
+
64
+ class IgnoreLine
65
+ attr_reader :comment, :location, :raw_diagnostics
66
+
67
+ def initialize(comment, diagnostics, location)
68
+ @comment = comment
69
+ @raw_diagnostics = diagnostics
70
+ @location = location
71
+ end
72
+
73
+ def line
74
+ location.start_line
75
+ end
76
+
77
+ def ignored_diagnostics
78
+ if raw_diagnostics.empty?
79
+ return :all
80
+ end
81
+
82
+ if raw_diagnostics.size == 1 && raw_diagnostics.fetch(0).source == "all"
83
+ return :all
84
+ end
85
+
86
+ raw_diagnostics.map do |diagnostic|
87
+ name = diagnostic[:name].source
88
+ name.gsub(/\ARuby::/, "")
89
+ end
90
+ end
91
+ end
92
+
93
+ def self.parse(comment, buffer)
94
+ return unless comment.inline?
95
+
96
+ comment_location = RBS::Location.new(buffer, comment.loc.expression.begin_pos, comment.loc.expression.end_pos)
97
+ scanner = BufferScanner.new(comment_location)
98
+
99
+ scanner.scan(/#/)
100
+ scanner.skip(/\s*/)
101
+
102
+ begin_pos = comment.location.expression.begin_pos
103
+ end_pos = comment.location.expression.end_pos
104
+
105
+ case
106
+ when loc = scanner.scan(/steep:ignore:start\b/)
107
+ scanner.skip(/\s*/)
108
+ return unless scanner.eos?
109
+
110
+ IgnoreStart.new(comment, loc)
111
+ when loc = scanner.scan(/steep:ignore:end\b/)
112
+ scanner.skip(/\s*/)
113
+ return unless scanner.eos?
114
+
115
+ IgnoreEnd.new(comment, loc)
116
+ when keyword_loc = scanner.scan(/steep:ignore\b/)
117
+ # @type var diagnostics: IgnoreLine::diagnostics
118
+ diagnostics = []
119
+
120
+ scanner.skip(/\s*/)
121
+
122
+ while true
123
+ name = scanner.scan(/[A-Z]\w*/) or break
124
+ scanner.skip(/\s*/)
125
+ comma = scanner.scan(/,/)
126
+ scanner.skip(/\s*/)
127
+
128
+ diagnostic = RBS::Location.new(buffer, name.start_pos, comma&.end_pos || name.end_pos) #: IgnoreLine::diagnostic
129
+ diagnostic.add_required_child(:name, name.range)
130
+ diagnostic.add_optional_child(:following_comma, comma&.range)
131
+ diagnostics << diagnostic
132
+
133
+ break unless comma
134
+ end
135
+
136
+ return unless scanner.eos?
137
+
138
+ loc = RBS::Location.new(
139
+ buffer,
140
+ keyword_loc.start_pos,
141
+ diagnostics.last&.end_pos || keyword_loc.end_pos
142
+ )
143
+ IgnoreLine.new(comment, diagnostics, loc)
144
+ end
145
+ end
146
+ end
147
+ end
148
+ end
@@ -0,0 +1,88 @@
1
+ module Steep
2
+ module AST
3
+ module Node
4
+ class TypeApplication
5
+ attr_reader :location
6
+
7
+ def initialize(location)
8
+ @location = location
9
+ end
10
+
11
+ def node
12
+ @node || raise
13
+ end
14
+
15
+ def set_node(node)
16
+ @node = node
17
+ end
18
+
19
+ def line
20
+ location.start_line
21
+ end
22
+
23
+ def source
24
+ location.source
25
+ end
26
+
27
+ def types(context, subtyping, type_vars)
28
+ resolver = RBS::Resolver::TypeNameResolver.new(subtyping.factory.env)
29
+
30
+ # @type var types: Array[LocatedValue[Types::t]]
31
+ types = []
32
+
33
+ loc = type_location
34
+
35
+ while true
36
+ rbs_ty = RBS::Parser.parse_type(loc.buffer, range: loc.range, variables: type_vars) or break
37
+ rbs_loc = rbs_ty.location or raise
38
+ ty = rbs_ty.map_type_name {|name| resolver.resolve(name, context: context) || name.absolute! }
39
+
40
+ validator = Signature::Validator.new(checker: subtyping)
41
+ validator.rescue_validation_errors do
42
+ validator.validate_type(ty)
43
+ end
44
+
45
+ if validator.has_error?
46
+ return validator.each_error
47
+ end
48
+
49
+ ty = subtyping.factory.type(ty)
50
+ types << LocatedValue.new(value: ty, location: rbs_loc)
51
+
52
+ match = RBS::Location.new(loc.buffer, rbs_loc.end_pos, type_location.end_pos).source.match(/\A\s*,\s*/) or break
53
+ offset = match.length
54
+ loc = RBS::Location.new(loc.buffer, rbs_loc.end_pos + offset, type_location.end_pos)
55
+ end
56
+
57
+ types
58
+ rescue ::RBS::ParsingError => exn
59
+ exn
60
+ end
61
+
62
+ def types?(context, subtyping, type_vars)
63
+ case types = types(context, subtyping, type_vars)
64
+ when RBS::ParsingError, Enumerator
65
+ nil
66
+ else
67
+ types
68
+ end
69
+ end
70
+
71
+ def type_str
72
+ @type_str ||= source.delete_prefix("$").lstrip
73
+ end
74
+
75
+ def type_location
76
+ offset = source.size - type_str.size
77
+ RBS::Location.new(location.buffer, location.start_pos + offset, location.end_pos)
78
+ end
79
+
80
+ def self.parse(location)
81
+ if location.source =~/\A\$\s*(.+)/
82
+ TypeApplication.new(location)
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end