steep 0.39.0 → 0.40.0
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.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +1 -1
- data/CHANGELOG.md +6 -0
- data/Rakefile +5 -2
- data/bin/output_rebaseline.rb +49 -0
- data/bin/output_test.rb +93 -0
- data/lib/steep.rb +8 -3
- data/lib/steep/cli.rb +1 -1
- data/lib/steep/diagnostic/helper.rb +17 -0
- data/lib/steep/diagnostic/lsp_formatter.rb +16 -0
- data/lib/steep/diagnostic/ruby.rb +623 -0
- data/lib/steep/diagnostic/signature.rb +224 -0
- data/lib/steep/drivers/annotations.rb +13 -6
- data/lib/steep/drivers/check.rb +83 -60
- data/lib/steep/drivers/diagnostic_printer.rb +94 -0
- data/lib/steep/drivers/stats.rb +125 -29
- data/lib/steep/drivers/trace_printer.rb +5 -1
- data/lib/steep/drivers/validate.rb +13 -6
- data/lib/steep/drivers/watch.rb +26 -9
- data/lib/steep/drivers/worker.rb +5 -0
- data/lib/steep/project/options.rb +4 -4
- data/lib/steep/project/signature_file.rb +8 -2
- data/lib/steep/project/stats_calculator.rb +80 -0
- data/lib/steep/project/target.rb +64 -53
- data/lib/steep/range_extension.rb +29 -0
- data/lib/steep/server/base_worker.rb +42 -4
- data/lib/steep/server/code_worker.rb +37 -24
- data/lib/steep/server/interaction_worker.rb +1 -0
- data/lib/steep/server/master.rb +268 -82
- data/lib/steep/server/signature_worker.rb +7 -59
- data/lib/steep/server/worker_process.rb +9 -9
- data/lib/steep/signature/validator.rb +33 -9
- data/lib/steep/type_construction.rb +276 -194
- data/lib/steep/version.rb +1 -1
- data/smoke/alias/a.rb +0 -3
- data/smoke/alias/b.rb +0 -1
- data/smoke/alias/c.rb +0 -2
- data/smoke/alias/test.yaml +73 -0
- data/smoke/and/a.rb +0 -3
- data/smoke/and/test.yaml +24 -0
- data/smoke/array/a.rb +0 -3
- data/smoke/array/b.rb +0 -2
- data/smoke/array/c.rb +0 -1
- data/smoke/array/test.yaml +80 -0
- data/smoke/block/a.rb +0 -2
- data/smoke/block/b.rb +0 -2
- data/smoke/block/d.rb +0 -4
- data/smoke/block/test.yaml +96 -0
- data/smoke/broken/Steepfile +5 -0
- data/smoke/broken/broken.rb +0 -0
- data/smoke/broken/broken.rbs +0 -0
- data/smoke/broken/test.yaml +6 -0
- data/smoke/case/a.rb +0 -3
- data/smoke/case/test.yaml +36 -0
- data/smoke/class/a.rb +0 -3
- data/smoke/class/c.rb +0 -1
- data/smoke/class/f.rb +0 -1
- data/smoke/class/g.rb +0 -2
- data/smoke/class/i.rb +0 -2
- data/smoke/class/test.yaml +89 -0
- data/smoke/const/a.rb +0 -3
- data/smoke/const/b.rb +7 -0
- data/smoke/const/b.rbs +5 -0
- data/smoke/const/test.yaml +96 -0
- data/smoke/diagnostics-rbs-duplicated/Steepfile +5 -0
- data/smoke/diagnostics-rbs-duplicated/a.rbs +5 -0
- data/smoke/diagnostics-rbs-duplicated/test.yaml +10 -0
- data/smoke/diagnostics-rbs/Steepfile +5 -0
- data/smoke/diagnostics-rbs/duplicated-method-definition.rbs +20 -0
- data/smoke/diagnostics-rbs/generic-parameter-mismatch.rbs +7 -0
- data/smoke/diagnostics-rbs/invalid-method-overload.rbs +3 -0
- data/smoke/diagnostics-rbs/invalid-type-application.rbs +7 -0
- data/smoke/diagnostics-rbs/invalid_variance_annotation.rbs +3 -0
- data/smoke/diagnostics-rbs/recursive-alias.rbs +5 -0
- data/smoke/diagnostics-rbs/recursive-class.rbs +8 -0
- data/smoke/diagnostics-rbs/superclass-mismatch.rbs +7 -0
- data/smoke/diagnostics-rbs/test.yaml +142 -0
- data/smoke/diagnostics-rbs/unknown-method-alias.rbs +3 -0
- data/smoke/diagnostics-rbs/unknown-type-name.rbs +13 -0
- data/smoke/diagnostics/Steepfile +5 -0
- data/smoke/diagnostics/a.rbs +26 -0
- data/smoke/diagnostics/argument_type_mismatch.rb +1 -0
- data/smoke/diagnostics/block_body_type_mismatch.rb +1 -0
- data/smoke/diagnostics/block_type_mismatch.rb +3 -0
- data/smoke/diagnostics/break_type_mismatch.rb +1 -0
- data/smoke/diagnostics/else_on_exhaustive_case.rb +12 -0
- data/smoke/diagnostics/incompatible_annotation.rb +6 -0
- data/smoke/diagnostics/incompatible_argument.rb +1 -0
- data/smoke/diagnostics/incompatible_assignment.rb +8 -0
- data/smoke/diagnostics/method_arity_mismatch.rb +11 -0
- data/smoke/diagnostics/method_body_type_mismatch.rb +6 -0
- data/smoke/diagnostics/method_definition_missing.rb +2 -0
- data/smoke/diagnostics/method_return_type_annotation_mismatch.rb +7 -0
- data/smoke/diagnostics/missing_keyword.rb +1 -0
- data/smoke/diagnostics/no_method.rb +1 -0
- data/smoke/diagnostics/required_block_missing.rb +1 -0
- data/smoke/diagnostics/return_type_mismatch.rb +6 -0
- data/smoke/diagnostics/test.yaml +333 -0
- data/smoke/diagnostics/unexpected_block_given.rb +1 -0
- data/smoke/diagnostics/unexpected_dynamic_method.rb +3 -0
- data/smoke/diagnostics/unexpected_jump.rb +4 -0
- data/smoke/diagnostics/unexpected_jump_value.rb +3 -0
- data/smoke/diagnostics/unexpected_keyword.rb +1 -0
- data/smoke/diagnostics/unexpected_splat.rb +1 -0
- data/smoke/diagnostics/unexpected_yield.rb +6 -0
- data/smoke/diagnostics/unknown_constant_assigned.rb +7 -0
- data/smoke/diagnostics/unresolved_overloading.rb +1 -0
- data/smoke/diagnostics/unsatisfiable_constraint.rb +7 -0
- data/smoke/diagnostics/unsupported_syntax.rb +2 -0
- data/smoke/dstr/a.rb +0 -1
- data/smoke/dstr/test.yaml +10 -0
- data/smoke/ensure/a.rb +0 -4
- data/smoke/ensure/test.yaml +47 -0
- data/smoke/enumerator/a.rb +0 -6
- data/smoke/enumerator/b.rb +0 -3
- data/smoke/enumerator/test.yaml +100 -0
- data/smoke/extension/a.rb +0 -1
- data/smoke/extension/b.rb +0 -2
- data/smoke/extension/c.rb +0 -1
- data/smoke/extension/test.yaml +50 -0
- data/smoke/hash/b.rb +0 -1
- data/smoke/hash/c.rb +0 -3
- data/smoke/hash/d.rb +0 -1
- data/smoke/hash/e.rb +0 -1
- data/smoke/hash/test.yaml +62 -0
- data/smoke/hello/hello.rb +0 -2
- data/smoke/hello/test.yaml +18 -0
- data/smoke/if/a.rb +0 -2
- data/smoke/if/test.yaml +27 -0
- data/smoke/implements/a.rb +0 -2
- data/smoke/implements/test.yaml +16 -0
- data/smoke/initialize/test.yaml +4 -0
- data/smoke/integer/a.rb +0 -7
- data/smoke/integer/test.yaml +66 -0
- data/smoke/interface/a.rb +0 -2
- data/smoke/interface/test.yaml +16 -0
- data/smoke/kwbegin/a.rb +0 -1
- data/smoke/kwbegin/test.yaml +14 -0
- data/smoke/lambda/a.rb +1 -4
- data/smoke/lambda/test.yaml +28 -0
- data/smoke/literal/a.rb +0 -5
- data/smoke/literal/b.rb +0 -2
- data/smoke/literal/test.yaml +79 -0
- data/smoke/map/test.yaml +4 -0
- data/smoke/method/a.rb +0 -5
- data/smoke/method/b.rb +0 -1
- data/smoke/method/test.yaml +71 -0
- data/smoke/module/a.rb +0 -2
- data/smoke/module/b.rb +0 -2
- data/smoke/module/c.rb +0 -1
- data/smoke/module/d.rb +0 -1
- data/smoke/module/f.rb +0 -2
- data/smoke/module/test.yaml +51 -0
- data/smoke/regexp/a.rb +0 -38
- data/smoke/regexp/b.rb +0 -26
- data/smoke/regexp/test.yaml +372 -0
- data/smoke/regression/set_divide.rb +0 -4
- data/smoke/regression/test.yaml +38 -0
- data/smoke/rescue/a.rb +0 -5
- data/smoke/rescue/test.yaml +60 -0
- data/smoke/self/a.rb +0 -2
- data/smoke/self/test.yaml +16 -0
- data/smoke/skip/skip.rb +0 -2
- data/smoke/skip/test.yaml +16 -0
- data/smoke/stdout/test.yaml +4 -0
- data/smoke/super/a.rb +0 -4
- data/smoke/super/test.yaml +52 -0
- data/smoke/toplevel/a.rb +0 -1
- data/smoke/toplevel/test.yaml +12 -0
- data/smoke/tsort/a.rb +0 -3
- data/smoke/tsort/test.yaml +32 -0
- data/smoke/type_case/a.rb +0 -4
- data/smoke/type_case/test.yaml +33 -0
- data/smoke/yield/a.rb +0 -3
- data/smoke/yield/b.rb +6 -0
- data/smoke/yield/test.yaml +49 -0
- data/steep.gemspec +3 -3
- metadata +108 -17
- data/bin/smoke_runner.rb +0 -139
- data/lib/steep/drivers/signature_error_printer.rb +0 -25
- data/lib/steep/errors.rb +0 -594
- data/lib/steep/signature/errors.rb +0 -128
- data/lib/steep/type_assignability.rb +0 -367
@@ -35,10 +35,13 @@ module Steep
|
|
35
35
|
def handle_request(request)
|
36
36
|
case request[:method]
|
37
37
|
when "initialize"
|
38
|
-
#
|
38
|
+
# Start type checking.
|
39
39
|
project.targets.each do |target|
|
40
40
|
enqueue_target(target: target, timestamp: Time.now)
|
41
41
|
end
|
42
|
+
|
43
|
+
writer.write({ id: request[:id], result: nil})
|
44
|
+
|
42
45
|
when "textDocument/didChange"
|
43
46
|
update_source(request)
|
44
47
|
validate_signature_if_required(request)
|
@@ -55,73 +58,18 @@ module Steep
|
|
55
58
|
Steep.logger.info "Finished signature validation: #{target.name} (#{timestamp})"
|
56
59
|
|
57
60
|
diagnostics = case status = target.status
|
58
|
-
when Project::Target::
|
59
|
-
target.signature_files.each.with_object({}) do |(path, file), hash|
|
60
|
-
if file.status.is_a?(Project::SignatureFile::ParseErrorStatus)
|
61
|
-
location = case error = file.status.error
|
62
|
-
when RBS::Parser::SyntaxError
|
63
|
-
if error.error_value.is_a?(String)
|
64
|
-
buf = RBS::Buffer.new(name: path, content: file.content)
|
65
|
-
RBS::Location.new(buffer: buf, start_pos: buf.content.size, end_pos: buf.content.size)
|
66
|
-
else
|
67
|
-
error.error_value.location
|
68
|
-
end
|
69
|
-
when RBS::Parser::SemanticsError
|
70
|
-
error.location
|
71
|
-
else
|
72
|
-
raise
|
73
|
-
end
|
74
|
-
|
75
|
-
hash[path] =
|
76
|
-
[
|
77
|
-
LSP::Interface::Diagnostic.new(
|
78
|
-
message: file.status.error.message,
|
79
|
-
severity: LSP::Constant::DiagnosticSeverity::ERROR,
|
80
|
-
range: LSP::Interface::Range.new(
|
81
|
-
start: LSP::Interface::Position.new(
|
82
|
-
line: location.start_line - 1,
|
83
|
-
character: location.start_column,
|
84
|
-
),
|
85
|
-
end: LSP::Interface::Position.new(
|
86
|
-
line: location.end_line - 1,
|
87
|
-
character: location.end_column
|
88
|
-
)
|
89
|
-
)
|
90
|
-
)
|
91
|
-
]
|
92
|
-
else
|
93
|
-
hash[path] = []
|
94
|
-
end
|
95
|
-
end
|
96
|
-
when Project::Target::SignatureValidationErrorStatus
|
61
|
+
when Project::Target::SignatureErrorStatus
|
97
62
|
error_hash = status.errors.group_by {|error| error.location.buffer.name }
|
63
|
+
formatter = Diagnostic::LSPFormatter.new
|
98
64
|
|
99
65
|
target.signature_files.each_key.with_object({}) do |path, hash|
|
100
66
|
errors = error_hash[path] || []
|
101
|
-
hash[path] = errors.map
|
102
|
-
LSP::Interface::Diagnostic.new(
|
103
|
-
message: StringIO.new.tap {|io| error.puts(io) }.string.split(/\t/, 2).last,
|
104
|
-
severity: LSP::Constant::DiagnosticSeverity::ERROR,
|
105
|
-
range: LSP::Interface::Range.new(
|
106
|
-
start: LSP::Interface::Position.new(
|
107
|
-
line: error.location.start_line - 1,
|
108
|
-
character: error.location.start_column,
|
109
|
-
),
|
110
|
-
end: LSP::Interface::Position.new(
|
111
|
-
line: error.location.end_line - 1,
|
112
|
-
character: error.location.end_column
|
113
|
-
)
|
114
|
-
)
|
115
|
-
)
|
116
|
-
end
|
67
|
+
hash[path] = errors.map {|error| formatter.format(error) }
|
117
68
|
end
|
118
69
|
when Project::Target::TypeCheckStatus
|
119
70
|
target.signature_files.each_key.with_object({}) do |path, hash|
|
120
71
|
hash[path] = []
|
121
72
|
end
|
122
|
-
when Project::Target::SignatureOtherErrorStatus
|
123
|
-
Steep.log_error status.error
|
124
|
-
{}
|
125
73
|
else
|
126
74
|
Steep.logger.info "Unexpected target status: #{status.class}"
|
127
75
|
{}
|
@@ -16,7 +16,7 @@ module Steep
|
|
16
16
|
@name = name
|
17
17
|
end
|
18
18
|
|
19
|
-
def self.spawn_worker(type, name:, steepfile:)
|
19
|
+
def self.spawn_worker(type, name:, steepfile:, delay_shutdown: false)
|
20
20
|
log_level = %w(debug info warn error fatal unknown)[Steep.logger.level]
|
21
21
|
command = case type
|
22
22
|
when :code
|
@@ -29,6 +29,10 @@ module Steep
|
|
29
29
|
raise
|
30
30
|
end
|
31
31
|
|
32
|
+
if delay_shutdown
|
33
|
+
command << "--delay-shutdown"
|
34
|
+
end
|
35
|
+
|
32
36
|
stdin, stdout, thread = Open3.popen2(*command, pgroup: true)
|
33
37
|
stderr = nil
|
34
38
|
|
@@ -38,9 +42,9 @@ module Steep
|
|
38
42
|
new(reader: reader, writer: writer, stderr: stderr, wait_thread: thread, name: name)
|
39
43
|
end
|
40
44
|
|
41
|
-
def self.spawn_code_workers(steepfile:, count: [Etc.nprocessors-3, 1].max)
|
45
|
+
def self.spawn_code_workers(steepfile:, count: [Etc.nprocessors-3, 1].max, delay_shutdown: false)
|
42
46
|
count.times.map do |i|
|
43
|
-
spawn_worker(:code, name: "code@#{i}", steepfile: steepfile)
|
47
|
+
spawn_worker(:code, name: "code@#{i}", steepfile: steepfile, delay_shutdown: delay_shutdown)
|
44
48
|
end
|
45
49
|
end
|
46
50
|
|
@@ -52,12 +56,8 @@ module Steep
|
|
52
56
|
reader.read(&block)
|
53
57
|
end
|
54
58
|
|
55
|
-
def
|
56
|
-
|
57
|
-
self << { method: :exit, params: nil }
|
58
|
-
|
59
|
-
writer.io.close()
|
60
|
-
@wait_thread.join()
|
59
|
+
def kill
|
60
|
+
Process.kill(:TERM, @wait_thread.pid)
|
61
61
|
end
|
62
62
|
end
|
63
63
|
end
|
@@ -129,47 +129,71 @@ module Steep
|
|
129
129
|
def rescue_validation_errors(type_name = nil)
|
130
130
|
yield
|
131
131
|
rescue RBS::InvalidTypeApplicationError => exn
|
132
|
-
@errors <<
|
132
|
+
@errors << Diagnostic::Signature::InvalidTypeApplication.new(
|
133
133
|
name: exn.type_name,
|
134
134
|
args: exn.args.map {|ty| factory.type(ty) },
|
135
135
|
params: exn.params,
|
136
136
|
location: exn.location
|
137
137
|
)
|
138
|
-
rescue RBS::NoTypeFoundError,
|
139
|
-
|
138
|
+
rescue RBS::NoTypeFoundError,
|
139
|
+
RBS::NoSuperclassFoundError,
|
140
|
+
RBS::NoMixinFoundError,
|
141
|
+
RBS::NoSelfTypeFoundError => exn
|
142
|
+
@errors << Diagnostic::Signature::UnknownTypeName.new(
|
140
143
|
name: exn.type_name,
|
141
144
|
location: exn.location
|
142
145
|
)
|
143
146
|
rescue RBS::InvalidOverloadMethodError => exn
|
144
|
-
@errors <<
|
147
|
+
@errors << Diagnostic::Signature::InvalidMethodOverload.new(
|
145
148
|
class_name: exn.type_name,
|
146
149
|
method_name: exn.method_name,
|
147
150
|
location: exn.members[0].location
|
148
151
|
)
|
149
152
|
rescue RBS::DuplicatedMethodDefinitionError => exn
|
150
|
-
@errors <<
|
153
|
+
@errors << Diagnostic::Signature::DuplicatedMethodDefinition.new(
|
151
154
|
class_name: type_name,
|
152
155
|
method_name: exn.method_name,
|
153
156
|
location: exn.location
|
154
157
|
)
|
155
158
|
rescue RBS::DuplicatedInterfaceMethodDefinitionError => exn
|
156
|
-
@errors <<
|
159
|
+
@errors << Diagnostic::Signature::DuplicatedMethodDefinition.new(
|
157
160
|
class_name: type_name,
|
158
161
|
method_name: exn.method_name,
|
159
162
|
location: exn.member.location
|
160
163
|
)
|
161
164
|
rescue RBS::UnknownMethodAliasError => exn
|
162
|
-
@errors <<
|
165
|
+
@errors << Diagnostic::Signature::UnknownMethodAlias.new(
|
163
166
|
class_name: type_name,
|
164
|
-
method_name: exn.
|
167
|
+
method_name: exn.original_name,
|
165
168
|
location: exn.location
|
166
169
|
)
|
167
170
|
rescue RBS::RecursiveAliasDefinitionError => exn
|
168
|
-
@errors <<
|
171
|
+
@errors << Diagnostic::Signature::RecursiveAlias.new(
|
169
172
|
class_name: exn.type.name,
|
170
173
|
names: exn.defs.map(&:name),
|
171
174
|
location: exn.defs[0].original.location
|
172
175
|
)
|
176
|
+
rescue RBS::RecursiveAncestorError => exn
|
177
|
+
@errors << Diagnostic::Signature::RecursiveAncestor.new(
|
178
|
+
ancestors: exn.ancestors,
|
179
|
+
location: exn.location
|
180
|
+
)
|
181
|
+
rescue RBS::SuperclassMismatchError => exn
|
182
|
+
@errors << Diagnostic::Signature::SuperclassMismatch.new(
|
183
|
+
name: exn.name,
|
184
|
+
location: exn.entry.primary.decl.location
|
185
|
+
)
|
186
|
+
rescue RBS::GenericParameterMismatchError => exn
|
187
|
+
@errors << Diagnostic::Signature::GenericParameterMismatch.new(
|
188
|
+
name: exn.name,
|
189
|
+
location: exn.decl.location
|
190
|
+
)
|
191
|
+
rescue RBS::InvalidVarianceAnnotationError => exn
|
192
|
+
@errors << Diagnostic::Signature::InvalidVarianceAnnotation.new(
|
193
|
+
name: exn.type_name,
|
194
|
+
param: exn.param,
|
195
|
+
location: exn.location
|
196
|
+
)
|
173
197
|
end
|
174
198
|
end
|
175
199
|
end
|
@@ -142,10 +142,14 @@ module Steep
|
|
142
142
|
|
143
143
|
if annots&.return_type && method_type&.type&.return_type
|
144
144
|
check_relation(sub_type: annots.return_type, super_type: method_type.type.return_type).else do |result|
|
145
|
-
typing.add_error
|
146
|
-
|
147
|
-
|
148
|
-
|
145
|
+
typing.add_error(
|
146
|
+
Diagnostic::Ruby::MethodReturnTypeAnnotationMismatch.new(
|
147
|
+
node: node,
|
148
|
+
method_type: method_type.type.return_type,
|
149
|
+
annotation_type: annots.return_type,
|
150
|
+
result: result
|
151
|
+
)
|
152
|
+
)
|
149
153
|
end
|
150
154
|
end
|
151
155
|
|
@@ -154,7 +158,7 @@ module Steep
|
|
154
158
|
if method_type
|
155
159
|
var_types = TypeConstruction.parameter_types(args, method_type.type)
|
156
160
|
unless TypeConstruction.valid_parameter_env?(var_types, args.reject {|arg| arg.type == :blockarg}, method_type.type.params)
|
157
|
-
typing.add_error
|
161
|
+
typing.add_error Diagnostic::Ruby::MethodArityMismatch.new(node: node, method_type: method_type)
|
158
162
|
end
|
159
163
|
end
|
160
164
|
|
@@ -574,7 +578,7 @@ module Steep
|
|
574
578
|
lvar_env.assign!(name, node: node, type: type) do |declared_type, assigned_type, result|
|
575
579
|
relation = Subtyping::Relation.new(sub_type: assigned_type, super_type: declared_type)
|
576
580
|
typing.add_error(
|
577
|
-
|
581
|
+
Diagnostic::Ruby::IncompatibleTypeCase.new(
|
578
582
|
node: node,
|
579
583
|
var_name: name,
|
580
584
|
relation: relation,
|
@@ -588,10 +592,12 @@ module Steep
|
|
588
592
|
lvar_env = lvar_env.annotate(annots) do |var, outer_type, inner_type, result|
|
589
593
|
relation = Subtyping::Relation.new(sub_type: inner_type, super_type: outer_type)
|
590
594
|
typing.add_error(
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
+
Diagnostic::Ruby::IncompatibleAnnotation.new(
|
596
|
+
node: node,
|
597
|
+
var_name: var,
|
598
|
+
relation: relation,
|
599
|
+
result: result
|
600
|
+
)
|
595
601
|
)
|
596
602
|
end
|
597
603
|
|
@@ -608,10 +614,12 @@ module Steep
|
|
608
614
|
self_type: self_type
|
609
615
|
) do |var, relation, result|
|
610
616
|
typing.add_error(
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
617
|
+
Diagnostic::Ruby::IncompatibleAnnotation.new(
|
618
|
+
node: node,
|
619
|
+
var_name: var,
|
620
|
+
relation: relation,
|
621
|
+
result: result
|
622
|
+
)
|
615
623
|
)
|
616
624
|
end
|
617
625
|
|
@@ -694,10 +702,14 @@ module Steep
|
|
694
702
|
|
695
703
|
constr = rhs_result.constr.update_lvar_env do |lvar_env|
|
696
704
|
lvar_env.assign(name, node: node, type: rhs_result.type) do |declared_type, actual_type, result|
|
697
|
-
typing.add_error(
|
698
|
-
|
699
|
-
|
700
|
-
|
705
|
+
typing.add_error(
|
706
|
+
Diagnostic::Ruby::IncompatibleAssignment.new(
|
707
|
+
node: node,
|
708
|
+
lhs_type: declared_type,
|
709
|
+
rhs_type: actual_type,
|
710
|
+
result: result
|
711
|
+
)
|
712
|
+
)
|
701
713
|
end
|
702
714
|
end
|
703
715
|
|
@@ -852,7 +864,7 @@ module Steep
|
|
852
864
|
constr.add_call(call)
|
853
865
|
else
|
854
866
|
fallback_to_any node do
|
855
|
-
|
867
|
+
Diagnostic::Ruby::UnexpectedSuper.new(node: node, method: method_context.name)
|
856
868
|
end
|
857
869
|
end
|
858
870
|
else
|
@@ -888,10 +900,14 @@ module Steep
|
|
888
900
|
return_type = expand_alias(new.method_context&.return_type)
|
889
901
|
if return_type && !return_type.is_a?(AST::Types::Void)
|
890
902
|
new.check(body_node, return_type) do |_, actual_type, result|
|
891
|
-
typing.add_error(
|
892
|
-
|
893
|
-
|
894
|
-
|
903
|
+
typing.add_error(
|
904
|
+
Diagnostic::Ruby::MethodBodyTypeMismatch.new(
|
905
|
+
node: node,
|
906
|
+
expected: new.method_context&.return_type,
|
907
|
+
actual: actual_type,
|
908
|
+
result: result
|
909
|
+
)
|
910
|
+
)
|
895
911
|
end
|
896
912
|
else
|
897
913
|
new.synthesize(body_node)
|
@@ -901,10 +917,14 @@ module Steep
|
|
901
917
|
if return_type && !return_type.is_a?(AST::Types::Void)
|
902
918
|
result = check_relation(sub_type: AST::Builtin.nil_type, super_type: return_type)
|
903
919
|
if result.failure?
|
904
|
-
typing.add_error(
|
905
|
-
|
906
|
-
|
907
|
-
|
920
|
+
typing.add_error(
|
921
|
+
Diagnostic::Ruby::MethodBodyTypeMismatch.new(
|
922
|
+
node: node,
|
923
|
+
expected: new.method_context&.return_type,
|
924
|
+
actual: AST::Builtin.nil_type,
|
925
|
+
result: result
|
926
|
+
)
|
927
|
+
)
|
908
928
|
end
|
909
929
|
end
|
910
930
|
|
@@ -956,10 +976,14 @@ module Steep
|
|
956
976
|
return_type = expand_alias(new.method_context&.return_type)
|
957
977
|
if return_type && !return_type.is_a?(AST::Types::Void)
|
958
978
|
new.check(node.children[3], return_type) do |return_type, actual_type, result|
|
959
|
-
typing.add_error(
|
960
|
-
|
961
|
-
|
962
|
-
|
979
|
+
typing.add_error(
|
980
|
+
Diagnostic::Ruby::MethodBodyTypeMismatch.new(
|
981
|
+
node: node,
|
982
|
+
expected: return_type,
|
983
|
+
actual: actual_type,
|
984
|
+
result: result
|
985
|
+
)
|
986
|
+
)
|
963
987
|
end
|
964
988
|
else
|
965
989
|
new.synthesize(node.children[3])
|
@@ -1000,10 +1024,14 @@ module Steep
|
|
1000
1024
|
result = check_relation(sub_type: value_type, super_type: method_return_type)
|
1001
1025
|
|
1002
1026
|
if result.failure?
|
1003
|
-
typing.add_error(
|
1004
|
-
|
1005
|
-
|
1006
|
-
|
1027
|
+
typing.add_error(
|
1028
|
+
Diagnostic::Ruby::ReturnTypeMismatch.new(
|
1029
|
+
node: node,
|
1030
|
+
expected: method_context&.return_type,
|
1031
|
+
actual: value_type,
|
1032
|
+
result: result
|
1033
|
+
)
|
1034
|
+
)
|
1007
1035
|
end
|
1008
1036
|
end
|
1009
1037
|
end
|
@@ -1019,28 +1047,36 @@ module Steep
|
|
1019
1047
|
if break_type = break_context.break_type
|
1020
1048
|
if value
|
1021
1049
|
check(value, break_type) do |break_type, actual_type, result|
|
1022
|
-
typing.add_error
|
1023
|
-
|
1024
|
-
|
1025
|
-
|
1050
|
+
typing.add_error(
|
1051
|
+
Diagnostic::Ruby::BreakTypeMismatch.new(
|
1052
|
+
node: node,
|
1053
|
+
expected: break_type,
|
1054
|
+
actual: actual_type,
|
1055
|
+
result: result
|
1056
|
+
)
|
1057
|
+
)
|
1026
1058
|
end
|
1027
1059
|
else
|
1028
1060
|
check_relation(sub_type: AST::Builtin.nil_type, super_type: break_type).else do |result|
|
1029
|
-
typing.add_error
|
1030
|
-
|
1031
|
-
|
1032
|
-
|
1061
|
+
typing.add_error(
|
1062
|
+
Diagnostic::Ruby::BreakTypeMismatch.new(
|
1063
|
+
node: node,
|
1064
|
+
expected: break_type,
|
1065
|
+
actual: AST::Builtin.nil_type,
|
1066
|
+
result: result
|
1067
|
+
)
|
1068
|
+
)
|
1033
1069
|
end
|
1034
1070
|
end
|
1035
1071
|
else
|
1036
1072
|
if value
|
1037
1073
|
synthesize(value)
|
1038
|
-
typing.add_error
|
1074
|
+
typing.add_error Diagnostic::Ruby::UnexpectedJumpValue.new(node: node)
|
1039
1075
|
end
|
1040
1076
|
end
|
1041
1077
|
else
|
1042
1078
|
synthesize(value) if value
|
1043
|
-
typing.add_error
|
1079
|
+
typing.add_error Diagnostic::Ruby::UnexpectedJump.new(node: node)
|
1044
1080
|
end
|
1045
1081
|
|
1046
1082
|
add_typing(node, type: AST::Builtin.bottom_type)
|
@@ -1054,35 +1090,43 @@ module Steep
|
|
1054
1090
|
|
1055
1091
|
if value
|
1056
1092
|
_, constr = check(value, next_type) do |break_type, actual_type, result|
|
1057
|
-
typing.add_error
|
1058
|
-
|
1059
|
-
|
1060
|
-
|
1093
|
+
typing.add_error(
|
1094
|
+
Diagnostic::Ruby::BreakTypeMismatch.new(
|
1095
|
+
node: node,
|
1096
|
+
expected: break_type,
|
1097
|
+
actual: actual_type,
|
1098
|
+
result: result
|
1099
|
+
)
|
1100
|
+
)
|
1061
1101
|
end
|
1062
1102
|
else
|
1063
1103
|
check_relation(sub_type: AST::Builtin.nil_type, super_type: next_type).else do |result|
|
1064
|
-
typing.add_error
|
1065
|
-
|
1066
|
-
|
1067
|
-
|
1104
|
+
typing.add_error(
|
1105
|
+
Diagnostic::Ruby::BreakTypeMismatch.new(
|
1106
|
+
node: node,
|
1107
|
+
expected: next_type,
|
1108
|
+
actual: AST::Builtin.nil_type,
|
1109
|
+
result: result
|
1110
|
+
)
|
1111
|
+
)
|
1068
1112
|
end
|
1069
1113
|
end
|
1070
1114
|
else
|
1071
1115
|
if value
|
1072
1116
|
synthesize(value)
|
1073
|
-
typing.add_error
|
1117
|
+
typing.add_error Diagnostic::Ruby::UnexpectedJumpValue.new(node: node)
|
1074
1118
|
end
|
1075
1119
|
end
|
1076
1120
|
else
|
1077
1121
|
synthesize(value) if value
|
1078
|
-
typing.add_error
|
1122
|
+
typing.add_error Diagnostic::Ruby::UnexpectedJump.new(node: node)
|
1079
1123
|
end
|
1080
1124
|
|
1081
1125
|
add_typing(node, type: AST::Builtin.bottom_type)
|
1082
1126
|
|
1083
1127
|
when :retry
|
1084
1128
|
unless break_context
|
1085
|
-
typing.add_error
|
1129
|
+
typing.add_error Diagnostic::Ruby::UnexpectedJump.new(node: node)
|
1086
1130
|
end
|
1087
1131
|
add_typing(node, type: AST::Builtin.bottom_type)
|
1088
1132
|
|
@@ -1112,10 +1156,12 @@ module Steep
|
|
1112
1156
|
constr_ = constr.update_lvar_env do |env|
|
1113
1157
|
env.assign(var.name, node: node, type: type) do |declared_type, type, result|
|
1114
1158
|
typing.add_error(
|
1115
|
-
|
1116
|
-
|
1117
|
-
|
1118
|
-
|
1159
|
+
Diagnostic::Ruby::IncompatibleAssignment.new(
|
1160
|
+
node: node,
|
1161
|
+
lhs_type: declared_type,
|
1162
|
+
rhs_type: type,
|
1163
|
+
result: result
|
1164
|
+
)
|
1119
1165
|
)
|
1120
1166
|
end
|
1121
1167
|
end
|
@@ -1131,7 +1177,7 @@ module Steep
|
|
1131
1177
|
if context&.method_context&.method_type
|
1132
1178
|
Steep.logger.error { "Unknown variable: #{node}" }
|
1133
1179
|
end
|
1134
|
-
typing.add_error
|
1180
|
+
typing.add_error Diagnostic::Ruby::FallbackAny.new(node: node)
|
1135
1181
|
type = AST::Builtin::Array.instance_type(AST::Builtin.any_type)
|
1136
1182
|
end
|
1137
1183
|
|
@@ -1146,7 +1192,7 @@ module Steep
|
|
1146
1192
|
if context&.method_context&.method_type
|
1147
1193
|
Steep.logger.error { "Unknown variable: #{node}" }
|
1148
1194
|
end
|
1149
|
-
typing.add_error
|
1195
|
+
typing.add_error Diagnostic::Ruby::FallbackAny.new(node: node)
|
1150
1196
|
type = AST::Builtin::Hash.instance_type(AST::Builtin::Symbol.instance_type, AST::Builtin.any_type)
|
1151
1197
|
end
|
1152
1198
|
|
@@ -1229,7 +1275,7 @@ module Steep
|
|
1229
1275
|
key_types << splat_type.args[0]
|
1230
1276
|
value_types << splat_type.args[1]
|
1231
1277
|
else
|
1232
|
-
typing.add_error
|
1278
|
+
typing.add_error Diagnostic::Ruby::UnexpectedSplat.new(node: child, type: original_type)
|
1233
1279
|
key_types << AST::Builtin.any_type
|
1234
1280
|
value_types << AST::Builtin.any_type
|
1235
1281
|
end
|
@@ -1243,7 +1289,7 @@ module Steep
|
|
1243
1289
|
value_type = value_types.empty? ? AST::Builtin.any_type : AST::Types::Union.build(types: value_types)
|
1244
1290
|
|
1245
1291
|
if key_types.empty? && value_types.empty? && !hint
|
1246
|
-
typing.add_error
|
1292
|
+
typing.add_error Diagnostic::Ruby::FallbackAny.new(node: node)
|
1247
1293
|
end
|
1248
1294
|
|
1249
1295
|
add_typing(node, type: AST::Builtin::Hash.instance_type(key_type, value_type))
|
@@ -1337,7 +1383,7 @@ module Steep
|
|
1337
1383
|
|
1338
1384
|
unless constructor
|
1339
1385
|
typing.add_error(
|
1340
|
-
|
1386
|
+
Diagnostic::Ruby::UnsupportedSyntax.new(
|
1341
1387
|
node: node,
|
1342
1388
|
message: "sclass receiver must be instance type or singleton type, but type given `#{type}`"
|
1343
1389
|
)
|
@@ -1408,12 +1454,22 @@ module Steep
|
|
1408
1454
|
case error
|
1409
1455
|
when Subtyping::Result::Failure
|
1410
1456
|
const_type = type_env.get(const: const_name)
|
1411
|
-
typing.add_error(
|
1412
|
-
|
1413
|
-
|
1414
|
-
|
1457
|
+
typing.add_error(
|
1458
|
+
Diagnostic::Ruby::IncompatibleAssignment.new(
|
1459
|
+
node: node,
|
1460
|
+
lhs_type: const_type,
|
1461
|
+
rhs_type: value_type,
|
1462
|
+
result: error
|
1463
|
+
)
|
1464
|
+
)
|
1415
1465
|
when nil
|
1416
|
-
typing.add_error(
|
1466
|
+
typing.add_error(
|
1467
|
+
Diagnostic::Ruby::UnknownConstantAssigned.new(
|
1468
|
+
node: node,
|
1469
|
+
name: const_name,
|
1470
|
+
context: module_context
|
1471
|
+
)
|
1472
|
+
)
|
1417
1473
|
end
|
1418
1474
|
end
|
1419
1475
|
|
@@ -1431,17 +1487,21 @@ module Steep
|
|
1431
1487
|
block_type.type.params.flat_unnamed_params.map(&:last).zip(node.children).each do |(type, node)|
|
1432
1488
|
if node && type
|
1433
1489
|
check(node, type) do |_, rhs_type, result|
|
1434
|
-
typing.add_error(
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1490
|
+
typing.add_error(
|
1491
|
+
Diagnostic::Ruby::IncompatibleAssignment.new(
|
1492
|
+
node: node,
|
1493
|
+
lhs_type: type,
|
1494
|
+
rhs_type: rhs_type,
|
1495
|
+
result: result
|
1496
|
+
)
|
1497
|
+
)
|
1438
1498
|
end
|
1439
1499
|
end
|
1440
1500
|
end
|
1441
1501
|
|
1442
1502
|
add_typing(node, type: block_type.type.return_type)
|
1443
1503
|
else
|
1444
|
-
typing.add_error(
|
1504
|
+
typing.add_error(Diagnostic::Ruby::UnexpectedYield.new(node: node))
|
1445
1505
|
fallback_to_any node
|
1446
1506
|
end
|
1447
1507
|
else
|
@@ -1457,7 +1517,7 @@ module Steep
|
|
1457
1517
|
}
|
1458
1518
|
add_typing(node, type: union_type(*types))
|
1459
1519
|
else
|
1460
|
-
typing.add_error(
|
1520
|
+
typing.add_error(Diagnostic::Ruby::UnexpectedSuper.new(node: node, method: method_context.name))
|
1461
1521
|
fallback_to_any node
|
1462
1522
|
end
|
1463
1523
|
else
|
@@ -1476,7 +1536,7 @@ module Steep
|
|
1476
1536
|
add_typing node, type: array
|
1477
1537
|
end
|
1478
1538
|
else
|
1479
|
-
typing.add_error
|
1539
|
+
typing.add_error Diagnostic::Ruby::FallbackAny.new(node: node)
|
1480
1540
|
add_typing node, type: AST::Builtin::Array.instance_type(AST::Builtin.any_type)
|
1481
1541
|
end
|
1482
1542
|
else
|
@@ -1580,14 +1640,14 @@ module Steep
|
|
1580
1640
|
end
|
1581
1641
|
|
1582
1642
|
type = case
|
1583
|
-
when check_relation(sub_type: left_type, super_type: AST::Builtin.bool_type).success?
|
1643
|
+
when check_relation(sub_type: left_type, super_type: AST::Builtin.bool_type).success? && !left_type.is_a?(AST::Types::Any)
|
1584
1644
|
AST::Builtin.bool_type
|
1585
1645
|
else
|
1586
1646
|
union_type(left_type, right_type)
|
1587
1647
|
end
|
1588
1648
|
|
1589
1649
|
type = AST::Types::Logic::Env.new(truthy: env, falsy: falsey_env, type: type) if condition
|
1590
|
-
|
1650
|
+
|
1591
1651
|
add_typing(node,
|
1592
1652
|
type: type,
|
1593
1653
|
constr: constr.update_lvar_env { env })
|
@@ -1718,7 +1778,7 @@ module Steep
|
|
1718
1778
|
if when_constr.context.lvar_env[cond_vars.first].is_a?(AST::Types::Bot)
|
1719
1779
|
# Exhaustive
|
1720
1780
|
if els
|
1721
|
-
typing.add_error
|
1781
|
+
typing.add_error Diagnostic::Ruby::ElseOnExhaustiveCase.new(node: els, type: cond_type)
|
1722
1782
|
end
|
1723
1783
|
else
|
1724
1784
|
unless els
|
@@ -1906,7 +1966,7 @@ module Steep
|
|
1906
1966
|
add_typing(node, type: collection_type, constr: constr)
|
1907
1967
|
else
|
1908
1968
|
fallback_to_any(node) do
|
1909
|
-
|
1969
|
+
Diagnostic::Ruby::NoMethod.new(
|
1910
1970
|
node: node,
|
1911
1971
|
method: :each,
|
1912
1972
|
type: collection_type
|
@@ -2055,11 +2115,13 @@ module Steep
|
|
2055
2115
|
end
|
2056
2116
|
|
2057
2117
|
check(rhs, type) do |_, rhs_type, result|
|
2058
|
-
typing.add_error(
|
2059
|
-
|
2060
|
-
|
2061
|
-
|
2062
|
-
|
2118
|
+
typing.add_error(
|
2119
|
+
Diagnostic::Ruby::IncompatibleAssignment.new(
|
2120
|
+
node: node,
|
2121
|
+
lhs_type: type,
|
2122
|
+
rhs_type: rhs_type,
|
2123
|
+
result: result
|
2124
|
+
)
|
2063
2125
|
)
|
2064
2126
|
end
|
2065
2127
|
end
|
@@ -2068,7 +2130,7 @@ module Steep
|
|
2068
2130
|
yield_self do
|
2069
2131
|
name = node.children.first
|
2070
2132
|
type = type_env.get(gvar: name) do
|
2071
|
-
typing.add_error
|
2133
|
+
typing.add_error Diagnostic::Ruby::FallbackAny.new(node: node)
|
2072
2134
|
end
|
2073
2135
|
|
2074
2136
|
add_typing(node, type: type)
|
@@ -2082,24 +2144,29 @@ module Steep
|
|
2082
2144
|
if hint.one_arg?
|
2083
2145
|
# Assumes Symbol#to_proc implementation
|
2084
2146
|
param_type = hint.type.params.required[0]
|
2085
|
-
|
2086
|
-
|
2087
|
-
|
2088
|
-
|
2089
|
-
|
2090
|
-
|
2091
|
-
|
2092
|
-
|
2093
|
-
|
2094
|
-
|
2095
|
-
|
2096
|
-
|
2097
|
-
|
2098
|
-
|
2099
|
-
|
2100
|
-
|
2101
|
-
|
2102
|
-
|
2147
|
+
case param_type
|
2148
|
+
when AST::Types::Any
|
2149
|
+
type = AST::Types::Any.new
|
2150
|
+
else
|
2151
|
+
interface = checker.factory.interface(param_type, private: true)
|
2152
|
+
method = interface.methods[value.children[0]]
|
2153
|
+
if method
|
2154
|
+
return_types = method.method_types.select {|method_type|
|
2155
|
+
method_type.type.params.empty?
|
2156
|
+
}.map {|method_type|
|
2157
|
+
method_type.type.return_type
|
2158
|
+
}
|
2159
|
+
|
2160
|
+
unless return_types.empty?
|
2161
|
+
type = AST::Types::Proc.new(
|
2162
|
+
type: Interface::Function.new(
|
2163
|
+
params: Interface::Function::Params.empty.update(required: [param_type]),
|
2164
|
+
return_type: AST::Types::Union.build(types: return_types),
|
2165
|
+
location: nil
|
2166
|
+
),
|
2167
|
+
block: nil
|
2168
|
+
)
|
2169
|
+
end
|
2103
2170
|
end
|
2104
2171
|
end
|
2105
2172
|
else
|
@@ -2137,10 +2204,12 @@ module Steep
|
|
2137
2204
|
add_typing node, type: type, constr: constr
|
2138
2205
|
else
|
2139
2206
|
fallback_to_any node do
|
2140
|
-
|
2141
|
-
|
2142
|
-
|
2143
|
-
|
2207
|
+
Diagnostic::Ruby::IncompatibleAssignment.new(
|
2208
|
+
node: node,
|
2209
|
+
lhs_type: var_type,
|
2210
|
+
rhs_type: type,
|
2211
|
+
result: result
|
2212
|
+
)
|
2144
2213
|
end
|
2145
2214
|
end
|
2146
2215
|
else
|
@@ -2165,7 +2234,7 @@ module Steep
|
|
2165
2234
|
when :splat
|
2166
2235
|
yield_self do
|
2167
2236
|
typing.add_error(
|
2168
|
-
|
2237
|
+
Diagnostic::Ruby::UnsupportedSyntax.new(
|
2169
2238
|
node: node,
|
2170
2239
|
message: "Unsupported splat node occurrence"
|
2171
2240
|
)
|
@@ -2188,7 +2257,7 @@ module Steep
|
|
2188
2257
|
add_typing node, type: AST::Builtin.any_type, constr: constr
|
2189
2258
|
|
2190
2259
|
else
|
2191
|
-
typing.add_error(
|
2260
|
+
typing.add_error(Diagnostic::Ruby::UnsupportedSyntax.new(node: node))
|
2192
2261
|
|
2193
2262
|
end.tap do |pair|
|
2194
2263
|
unless pair.is_a?(Pair) && !pair.type.is_a?(Pair)
|
@@ -2218,10 +2287,14 @@ module Steep
|
|
2218
2287
|
case error
|
2219
2288
|
when Subtyping::Result::Failure
|
2220
2289
|
type = type_env.get(ivar: name)
|
2221
|
-
typing.add_error(
|
2222
|
-
|
2223
|
-
|
2224
|
-
|
2290
|
+
typing.add_error(
|
2291
|
+
Diagnostic::Ruby::IncompatibleAssignment.new(
|
2292
|
+
node: node,
|
2293
|
+
lhs_type: type,
|
2294
|
+
rhs_type: rhs_type,
|
2295
|
+
result: error
|
2296
|
+
)
|
2297
|
+
)
|
2225
2298
|
when nil
|
2226
2299
|
fallback_to_any node
|
2227
2300
|
end
|
@@ -2244,10 +2317,12 @@ module Steep
|
|
2244
2317
|
name = node.children[0].name
|
2245
2318
|
env = context.lvar_env.assign(name, node: node, type: type) do |declared_type, type, result|
|
2246
2319
|
typing.add_error(
|
2247
|
-
|
2248
|
-
|
2249
|
-
|
2250
|
-
|
2320
|
+
Diagnostic::Ruby::IncompatibleAssignment.new(
|
2321
|
+
node: node,
|
2322
|
+
lhs_type: declared_type,
|
2323
|
+
rhs_type: type,
|
2324
|
+
result: result
|
2325
|
+
)
|
2251
2326
|
)
|
2252
2327
|
end
|
2253
2328
|
|
@@ -2261,10 +2336,14 @@ module Steep
|
|
2261
2336
|
case error
|
2262
2337
|
when Subtyping::Result::Failure
|
2263
2338
|
var_type = type_env.get(ivar: ivar)
|
2264
|
-
typing.add_error(
|
2265
|
-
|
2266
|
-
|
2267
|
-
|
2339
|
+
typing.add_error(
|
2340
|
+
Diagnostic::Ruby::IncompatibleAssignment.new(
|
2341
|
+
node: node,
|
2342
|
+
lhs_type: var_type,
|
2343
|
+
rhs_type: type,
|
2344
|
+
result: error
|
2345
|
+
)
|
2346
|
+
)
|
2268
2347
|
when nil
|
2269
2348
|
fallback_to_any node
|
2270
2349
|
end
|
@@ -2462,8 +2541,8 @@ module Steep
|
|
2462
2541
|
if expected_block_type = block_constr.block_context.body_type
|
2463
2542
|
check_relation(sub_type: return_type, super_type: expected_block_type).else do |result|
|
2464
2543
|
block_constr.typing.add_error(
|
2465
|
-
|
2466
|
-
node:
|
2544
|
+
Diagnostic::Ruby::BlockBodyTypeMismatch.new(
|
2545
|
+
node: node,
|
2467
2546
|
expected: expected_block_type,
|
2468
2547
|
actual: return_type,
|
2469
2548
|
result: result
|
@@ -2525,7 +2604,7 @@ module Steep
|
|
2525
2604
|
end
|
2526
2605
|
end
|
2527
2606
|
else
|
2528
|
-
error =
|
2607
|
+
error = Diagnostic::Ruby::UnresolvedOverloading.new(
|
2529
2608
|
node: node,
|
2530
2609
|
receiver_type: receiver_type,
|
2531
2610
|
method_name: method_name,
|
@@ -2581,7 +2660,7 @@ module Steep
|
|
2581
2660
|
context: context.method_context,
|
2582
2661
|
method_name: method_name,
|
2583
2662
|
receiver_type: receiver_type,
|
2584
|
-
error:
|
2663
|
+
error: Diagnostic::Ruby::NoMethod.new(node: node, method: method_name, type: receiver_type)
|
2585
2664
|
)
|
2586
2665
|
)
|
2587
2666
|
end
|
@@ -2619,7 +2698,7 @@ module Steep
|
|
2619
2698
|
context: context.method_context,
|
2620
2699
|
method_name: method_name,
|
2621
2700
|
receiver_type: receiver_type,
|
2622
|
-
error:
|
2701
|
+
error: Diagnostic::Ruby::NoMethod.new(node: node, method: method_name, type: receiver_type)
|
2623
2702
|
)
|
2624
2703
|
)
|
2625
2704
|
|
@@ -2636,7 +2715,7 @@ module Steep
|
|
2636
2715
|
context: context.method_context,
|
2637
2716
|
method_name: method_name,
|
2638
2717
|
receiver_type: receiver_type,
|
2639
|
-
error:
|
2718
|
+
error: Diagnostic::Ruby::NoMethod.new(node: node, method: method_name, type: receiver_type)
|
2640
2719
|
)
|
2641
2720
|
)
|
2642
2721
|
else
|
@@ -2677,7 +2756,7 @@ module Steep
|
|
2677
2756
|
Steep.log_error(exn, message: "Unexpected error in #type_send: #{exn.message} (#{exn.class})")
|
2678
2757
|
end
|
2679
2758
|
|
2680
|
-
error =
|
2759
|
+
error = Diagnostic::Ruby::UnexpectedError.new(node: node, error: exn)
|
2681
2760
|
|
2682
2761
|
type_any_rec(node)
|
2683
2762
|
|
@@ -2731,7 +2810,8 @@ module Steep
|
|
2731
2810
|
all_decls = method.method_types.each.with_object(Set[]) do |method_type, set|
|
2732
2811
|
set.merge(method_type.method_decls)
|
2733
2812
|
end
|
2734
|
-
|
2813
|
+
|
2814
|
+
error = Diagnostic::Ruby::IncompatibleArguments.new(node: node, method_name: method_name, receiver_type: receiver_type, method_types: method.method_types)
|
2735
2815
|
call = TypeInference::MethodCall::Error.new(
|
2736
2816
|
node: node,
|
2737
2817
|
context: context.method_context,
|
@@ -2796,7 +2876,7 @@ module Steep
|
|
2796
2876
|
|
2797
2877
|
if keyword_type
|
2798
2878
|
check(value_node, keyword_type, constraints: constraints) do |expected, actual, result|
|
2799
|
-
return
|
2879
|
+
return Diagnostic::Ruby::IncompatibleAssignment.new(
|
2800
2880
|
node: value_node,
|
2801
2881
|
lhs_type: expected,
|
2802
2882
|
rhs_type: actual,
|
@@ -2809,7 +2889,7 @@ module Steep
|
|
2809
2889
|
|
2810
2890
|
else
|
2811
2891
|
check(key_node, AST::Builtin::Symbol.instance_type, constraints: constraints) do |expected, actual, result|
|
2812
|
-
return
|
2892
|
+
return Diagnostic::Ruby::IncompatibleAssignment.new(
|
2813
2893
|
node: key_node,
|
2814
2894
|
lhs_type: expected,
|
2815
2895
|
rhs_type: actual,
|
@@ -2822,7 +2902,7 @@ module Steep
|
|
2822
2902
|
Steep.logger.warn("Keyword arg with kwsplat(**) node are not supported.")
|
2823
2903
|
|
2824
2904
|
check(element.children[0], keyword_hash_type, constraints: constraints) do |expected, actual, result|
|
2825
|
-
return
|
2905
|
+
return Diagnostic::Ruby::IncompatibleAssignment.new(
|
2826
2906
|
node: node,
|
2827
2907
|
lhs_type: expected,
|
2828
2908
|
rhs_type: actual,
|
@@ -2838,14 +2918,18 @@ module Steep
|
|
2838
2918
|
when Set
|
2839
2919
|
missing_keywords = Set.new(params.required_keywords.keys) - given_keys
|
2840
2920
|
unless missing_keywords.empty?
|
2841
|
-
return
|
2842
|
-
|
2921
|
+
return Diagnostic::Ruby::MissingKeyword.new(
|
2922
|
+
node: node,
|
2923
|
+
missing_keywords: missing_keywords
|
2924
|
+
)
|
2843
2925
|
end
|
2844
2926
|
|
2845
2927
|
extra_keywords = given_keys - Set.new(params.required_keywords.keys) - Set.new(params.optional_keywords.keys)
|
2846
2928
|
if extra_keywords.any? && !params.rest_keywords
|
2847
|
-
return
|
2848
|
-
|
2929
|
+
return Diagnostic::Ruby::UnexpectedKeyword.new(
|
2930
|
+
node: node,
|
2931
|
+
unexpected_keywords: extra_keywords
|
2932
|
+
)
|
2849
2933
|
end
|
2850
2934
|
end
|
2851
2935
|
else
|
@@ -2872,12 +2956,13 @@ module Steep
|
|
2872
2956
|
|
2873
2957
|
node_type = synthesize(node, hint: hash_type).type
|
2874
2958
|
|
2875
|
-
check_relation(sub_type: node_type, super_type: hash_type).else do
|
2876
|
-
return
|
2959
|
+
check_relation(sub_type: node_type, super_type: hash_type).else do |result|
|
2960
|
+
return Diagnostic::Ruby::ArgumentTypeMismatch.new(
|
2877
2961
|
node: node,
|
2878
2962
|
receiver_type: receiver_type,
|
2879
2963
|
expected: hash_type,
|
2880
|
-
actual: node_type
|
2964
|
+
actual: node_type,
|
2965
|
+
result: result
|
2881
2966
|
)
|
2882
2967
|
end
|
2883
2968
|
end
|
@@ -2912,11 +2997,12 @@ module Steep
|
|
2912
2997
|
constr.synthesize(arg_node, hint: topdown_hint ? param_type : nil)
|
2913
2998
|
end
|
2914
2999
|
|
2915
|
-
check_relation(sub_type: arg_type, super_type: param_type, constraints: constraints).else do
|
2916
|
-
errors <<
|
2917
|
-
|
2918
|
-
|
2919
|
-
|
3000
|
+
check_relation(sub_type: arg_type, super_type: param_type, constraints: constraints).else do |result|
|
3001
|
+
errors << Diagnostic::Ruby::ArgumentTypeMismatch.new(node: arg_node,
|
3002
|
+
receiver_type: receiver_type,
|
3003
|
+
expected: param_type,
|
3004
|
+
actual: arg_type,
|
3005
|
+
result: result)
|
2920
3006
|
end
|
2921
3007
|
else
|
2922
3008
|
# keyword
|
@@ -2925,7 +3011,7 @@ module Steep
|
|
2925
3011
|
method_type: method_type,
|
2926
3012
|
constraints: constraints)
|
2927
3013
|
|
2928
|
-
if result.is_a?(
|
3014
|
+
if result.is_a?(Diagnostic::Ruby::Base)
|
2929
3015
|
errors << result
|
2930
3016
|
end
|
2931
3017
|
end
|
@@ -2961,7 +3047,7 @@ module Steep
|
|
2961
3047
|
|
2962
3048
|
if param.type
|
2963
3049
|
check_relation(sub_type: type, super_type: param.type, constraints: constraints).else do |result|
|
2964
|
-
error =
|
3050
|
+
error = Diagnostic::Ruby::IncompatibleAssignment.new(
|
2965
3051
|
node: param.node,
|
2966
3052
|
lhs_type: param.type,
|
2967
3053
|
rhs_type: type,
|
@@ -3005,36 +3091,20 @@ module Steep
|
|
3005
3091
|
end
|
3006
3092
|
|
3007
3093
|
when Subtyping::Result::Failure
|
3008
|
-
|
3009
|
-
|
3010
|
-
|
3011
|
-
|
3012
|
-
|
3013
|
-
),
|
3014
|
-
block: nil
|
3015
|
-
)
|
3016
|
-
|
3017
|
-
method_block_type = AST::Types::Proc.new(
|
3018
|
-
type: Interface::Function.new(
|
3019
|
-
params: method_type.block.type.params,
|
3020
|
-
return_type: method_type.block.type.return_type,
|
3021
|
-
location: nil
|
3022
|
-
),
|
3023
|
-
block: nil
|
3094
|
+
errors << Diagnostic::Ruby::BlockBodyTypeMismatch.new(
|
3095
|
+
node: node,
|
3096
|
+
expected: method_type.block.type.return_type,
|
3097
|
+
actual: block_body_type,
|
3098
|
+
result: result
|
3024
3099
|
)
|
3025
3100
|
|
3026
|
-
errors << Errors::BlockTypeMismatch.new(node: node,
|
3027
|
-
expected: method_block_type,
|
3028
|
-
actual: given_block_type,
|
3029
|
-
result: result)
|
3030
|
-
|
3031
3101
|
return_type = method_type.type.return_type
|
3032
3102
|
end
|
3033
3103
|
|
3034
3104
|
block_constr.typing.save!
|
3035
3105
|
|
3036
3106
|
rescue Subtyping::Constraints::UnsatisfiableConstraint => exn
|
3037
|
-
errors <<
|
3107
|
+
errors << Diagnostic::Ruby::UnsatisfiableConstraint.new(
|
3038
3108
|
node: node,
|
3039
3109
|
method_type: method_type,
|
3040
3110
|
var: exn.var,
|
@@ -3052,7 +3122,7 @@ module Steep
|
|
3052
3122
|
method_type = method_type.subst(s)
|
3053
3123
|
end
|
3054
3124
|
else
|
3055
|
-
errors <<
|
3125
|
+
errors << Diagnostic::Ruby::UnsupportedSyntax.new(
|
3056
3126
|
node: block_params,
|
3057
3127
|
message: "Unsupported block params pattern, probably masgn?"
|
3058
3128
|
)
|
@@ -3067,7 +3137,7 @@ module Steep
|
|
3067
3137
|
errors << error
|
3068
3138
|
end
|
3069
3139
|
|
3070
|
-
errors <<
|
3140
|
+
errors << Diagnostic::Ruby::UnexpectedBlockGiven.new(
|
3071
3141
|
node: node,
|
3072
3142
|
method_type: method_type
|
3073
3143
|
)
|
@@ -3085,7 +3155,7 @@ module Steep
|
|
3085
3155
|
s = constraints.solution(checker, variance: variance, variables: fresh_vars, self_type: self_type)
|
3086
3156
|
method_type = method_type.subst(s)
|
3087
3157
|
|
3088
|
-
errors <<
|
3158
|
+
errors << Diagnostic::Ruby::UnexpectedBlockGiven.new(
|
3089
3159
|
node: node,
|
3090
3160
|
method_type: method_type
|
3091
3161
|
)
|
@@ -3093,7 +3163,7 @@ module Steep
|
|
3093
3163
|
else
|
3094
3164
|
unless args.block_pass_arg
|
3095
3165
|
# Required block is missing
|
3096
|
-
errors <<
|
3166
|
+
errors << Diagnostic::Ruby::RequiredBlockMissing.new(
|
3097
3167
|
node: node,
|
3098
3168
|
method_type: method_type
|
3099
3169
|
)
|
@@ -3118,10 +3188,12 @@ module Steep
|
|
3118
3188
|
|
3119
3189
|
result = check_relation(sub_type: given_block_type, super_type: method_block_type, constraints: constraints)
|
3120
3190
|
result.else do |result|
|
3121
|
-
errors <<
|
3122
|
-
|
3123
|
-
|
3124
|
-
|
3191
|
+
errors << Diagnostic::Ruby::BlockTypeMismatch.new(
|
3192
|
+
node: args.block_pass_arg,
|
3193
|
+
expected: method_block_type,
|
3194
|
+
actual: given_block_type,
|
3195
|
+
result: result
|
3196
|
+
)
|
3125
3197
|
end
|
3126
3198
|
|
3127
3199
|
method_type = method_type.subst(constraints.solution(checker, self_type: self_type, variance: variance, variables: method_type.free_variables))
|
@@ -3178,7 +3250,7 @@ module Steep
|
|
3178
3250
|
if expected_block_type = block_constr.block_context.body_type
|
3179
3251
|
block_constr.check_relation(sub_type: block_type, super_type: expected_block_type).else do |result|
|
3180
3252
|
block_constr.typing.add_error(
|
3181
|
-
|
3253
|
+
Diagnostic::Ruby::BlockBodyTypeMismatch.new(
|
3182
3254
|
node: node,
|
3183
3255
|
expected: expected_block_type,
|
3184
3256
|
actual: block_type,
|
@@ -3391,10 +3463,14 @@ module Steep
|
|
3391
3463
|
# ok
|
3392
3464
|
else
|
3393
3465
|
if module_name.name == module_context&.class_name
|
3394
|
-
typing.add_error
|
3395
|
-
|
3396
|
-
|
3397
|
-
|
3466
|
+
typing.add_error(
|
3467
|
+
Diagnostic::Ruby::MethodDefinitionMissing.new(
|
3468
|
+
node: node,
|
3469
|
+
module_name: module_name.name,
|
3470
|
+
kind: :instance,
|
3471
|
+
missing_method: method_name
|
3472
|
+
)
|
3473
|
+
)
|
3398
3474
|
end
|
3399
3475
|
end
|
3400
3476
|
end
|
@@ -3406,26 +3482,32 @@ module Steep
|
|
3406
3482
|
# ok
|
3407
3483
|
else
|
3408
3484
|
if module_name.name == module_context&.class_name
|
3409
|
-
typing.add_error
|
3410
|
-
|
3411
|
-
|
3412
|
-
|
3485
|
+
typing.add_error(
|
3486
|
+
Diagnostic::Ruby::MethodDefinitionMissing.new(node: node,
|
3487
|
+
module_name: module_name.name,
|
3488
|
+
kind: :module,
|
3489
|
+
missing_method: method_name)
|
3490
|
+
)
|
3413
3491
|
end
|
3414
3492
|
end
|
3415
3493
|
end
|
3416
3494
|
|
3417
3495
|
annotations.instance_dynamics.each do |method_name|
|
3418
3496
|
unless expected_instance_method_names.member?(method_name)
|
3419
|
-
typing.add_error
|
3420
|
-
|
3421
|
-
|
3497
|
+
typing.add_error(
|
3498
|
+
Diagnostic::Ruby::UnexpectedDynamicMethod.new(node: node,
|
3499
|
+
module_name: module_name.name,
|
3500
|
+
method_name: method_name)
|
3501
|
+
)
|
3422
3502
|
end
|
3423
3503
|
end
|
3424
3504
|
annotations.module_dynamics.each do |method_name|
|
3425
3505
|
unless expected_module_method_names.member?(method_name)
|
3426
|
-
typing.add_error
|
3427
|
-
|
3428
|
-
|
3506
|
+
typing.add_error(
|
3507
|
+
Diagnostic::Ruby::UnexpectedDynamicMethod.new(node: node,
|
3508
|
+
module_name: module_name.name,
|
3509
|
+
method_name: method_name)
|
3510
|
+
)
|
3429
3511
|
end
|
3430
3512
|
end
|
3431
3513
|
end
|
@@ -3453,7 +3535,7 @@ module Steep
|
|
3453
3535
|
if block_given?
|
3454
3536
|
typing.add_error yield
|
3455
3537
|
else
|
3456
|
-
typing.add_error
|
3538
|
+
typing.add_error Diagnostic::Ruby::FallbackAny.new(node: node)
|
3457
3539
|
end
|
3458
3540
|
|
3459
3541
|
add_typing node, type: AST::Builtin.any_type
|