steep 1.8.0.dev.2 → 1.8.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +33 -0
- data/bin/mem_graph.rb +67 -0
- data/bin/mem_prof.rb +102 -0
- data/bin/stackprof_test.rb +19 -0
- data/bin/steep-check.rb +251 -0
- data/lib/steep/annotation_parser.rb +1 -1
- data/lib/steep/ast/builtin.rb +5 -5
- data/lib/steep/ast/node/type_application.rb +7 -6
- data/lib/steep/ast/types/any.rb +1 -9
- data/lib/steep/ast/types/boolean.rb +8 -16
- data/lib/steep/ast/types/bot.rb +2 -10
- data/lib/steep/ast/types/class.rb +1 -13
- data/lib/steep/ast/types/factory.rb +101 -85
- data/lib/steep/ast/types/instance.rb +1 -13
- data/lib/steep/ast/types/intersection.rb +8 -15
- data/lib/steep/ast/types/literal.rb +2 -8
- data/lib/steep/ast/types/logic.rb +3 -24
- data/lib/steep/ast/types/name.rb +5 -16
- data/lib/steep/ast/types/nil.rb +3 -12
- data/lib/steep/ast/types/proc.rb +4 -13
- data/lib/steep/ast/types/record.rb +21 -12
- data/lib/steep/ast/types/self.rb +1 -13
- data/lib/steep/ast/types/shared_instance.rb +11 -0
- data/lib/steep/ast/types/top.rb +1 -9
- data/lib/steep/ast/types/tuple.rb +4 -10
- data/lib/steep/ast/types/union.rb +10 -15
- data/lib/steep/ast/types/var.rb +4 -13
- data/lib/steep/ast/types/void.rb +2 -10
- data/lib/steep/diagnostic/ruby.rb +4 -4
- data/lib/steep/drivers/check.rb +11 -14
- data/lib/steep/drivers/checkfile.rb +8 -10
- data/lib/steep/drivers/stats.rb +17 -13
- data/lib/steep/drivers/utils/driver_helper.rb +24 -3
- data/lib/steep/drivers/watch.rb +3 -3
- data/lib/steep/interface/builder.rb +162 -138
- data/lib/steep/interface/method_type.rb +12 -20
- data/lib/steep/interface/shape.rb +66 -10
- data/lib/steep/interface/substitution.rb +2 -0
- data/lib/steep/interface/type_param.rb +20 -7
- data/lib/steep/located_value.rb +20 -0
- data/lib/steep/server/change_buffer.rb +5 -7
- data/lib/steep/server/custom_methods.rb +61 -0
- data/lib/steep/server/delay_queue.rb +8 -1
- data/lib/steep/server/interaction_worker.rb +10 -5
- data/lib/steep/server/lsp_formatter.rb +8 -6
- data/lib/steep/server/master.rb +193 -140
- data/lib/steep/server/type_check_worker.rb +18 -19
- data/lib/steep/server/work_done_progress.rb +64 -0
- data/lib/steep/services/completion_provider.rb +24 -22
- data/lib/steep/services/goto_service.rb +3 -2
- data/lib/steep/services/hover_provider/ruby.rb +7 -6
- data/lib/steep/services/signature_help_provider.rb +7 -6
- data/lib/steep/services/signature_service.rb +1 -1
- data/lib/steep/services/type_check_service.rb +3 -3
- data/lib/steep/signature/validator.rb +17 -20
- data/lib/steep/subtyping/check.rb +105 -55
- data/lib/steep/subtyping/constraints.rb +11 -15
- data/lib/steep/type_construction.rb +100 -100
- data/lib/steep/type_inference/block_params.rb +6 -6
- data/lib/steep/type_inference/logic_type_interpreter.rb +11 -7
- data/lib/steep/type_inference/method_call.rb +3 -3
- data/lib/steep/type_inference/method_params.rb +1 -1
- data/lib/steep/type_inference/send_args.rb +1 -1
- data/lib/steep/typing.rb +158 -102
- data/lib/steep/version.rb +1 -1
- data/lib/steep.rb +28 -3
- data/steep.gemspec +2 -2
- metadata +16 -9
- data/lib/steep/type_inference/context_array.rb +0 -112
@@ -11,9 +11,7 @@ module Steep
|
|
11
11
|
TypeCheckCodeJob = _ = Struct.new(:guid, :path, keyword_init: true)
|
12
12
|
ValidateAppSignatureJob = _ = Struct.new(:guid, :path, keyword_init: true)
|
13
13
|
ValidateLibrarySignatureJob = _ = Struct.new(:guid, :path, keyword_init: true)
|
14
|
-
GotoJob
|
15
|
-
# @implements GotoJob
|
16
|
-
|
14
|
+
class GotoJob < Struct.new(:id, :kind, :params, keyword_init: true)
|
17
15
|
def self.implementation(id:, params:)
|
18
16
|
new(
|
19
17
|
kind: :implementation,
|
@@ -57,7 +55,6 @@ module Steep
|
|
57
55
|
super(project: project, reader: reader, writer: writer)
|
58
56
|
|
59
57
|
@assignment = assignment
|
60
|
-
@service = Services::TypeCheckService.new(project: project)
|
61
58
|
@buffered_changes = {}
|
62
59
|
@mutex = Mutex.new()
|
63
60
|
@queue = Queue.new
|
@@ -65,30 +62,35 @@ module Steep
|
|
65
62
|
@current_type_check_guid = nil
|
66
63
|
end
|
67
64
|
|
65
|
+
def service
|
66
|
+
@service ||= Services::TypeCheckService.new(project: project)
|
67
|
+
end
|
68
|
+
|
68
69
|
def handle_request(request)
|
69
70
|
case request[:method]
|
70
71
|
when "initialize"
|
71
|
-
load_files(project: project, commandline_args: commandline_args)
|
72
72
|
writer.write({ id: request[:id], result: nil})
|
73
73
|
|
74
74
|
when "textDocument/didChange"
|
75
75
|
collect_changes(request)
|
76
76
|
|
77
|
-
when
|
78
|
-
|
79
|
-
|
77
|
+
when CustomMethods::FileLoad::METHOD
|
78
|
+
input = request[:params][:content]
|
79
|
+
load_files(input)
|
80
|
+
|
81
|
+
when CustomMethods::FileReset::METHOD
|
82
|
+
params = request[:params] #: CustomMethods::FileReset::params
|
83
|
+
uri = params[:uri]
|
84
|
+
text = params[:content]
|
80
85
|
reset_change(uri: uri, text: text)
|
81
86
|
|
82
87
|
when "workspace/symbol"
|
83
88
|
query = request[:params][:query]
|
84
89
|
queue << WorkspaceSymbolJob.new(id: request[:id], query: query)
|
85
|
-
when
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
end
|
90
|
-
when "$/typecheck/start"
|
91
|
-
params = request[:params]
|
90
|
+
when CustomMethods::Stats::METHOD
|
91
|
+
queue << StatsJob.new(id: request[:id])
|
92
|
+
when CustomMethods::TypeCheck__Start::METHOD
|
93
|
+
params = request[:params] #: CustomMethods::TypeCheck__Start::params
|
92
94
|
enqueue_typecheck_jobs(params)
|
93
95
|
when "textDocument/definition"
|
94
96
|
queue << GotoJob.definition(id: request[:id], params: request[:params])
|
@@ -241,10 +243,7 @@ module Steep
|
|
241
243
|
end
|
242
244
|
|
243
245
|
def typecheck_progress(guid:, path:)
|
244
|
-
writer.write(
|
245
|
-
method: "$/typecheck/progress",
|
246
|
-
params: { guid: guid, path: path }
|
247
|
-
)
|
246
|
+
writer.write(CustomMethods::TypeCheck__Progress.notification({ guid: guid, path: path.to_s }))
|
248
247
|
end
|
249
248
|
|
250
249
|
def workspace_symbol_result(query)
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Steep
|
2
|
+
module Server
|
3
|
+
class WorkDoneProgress
|
4
|
+
attr_reader :sender, :guid, :percentage
|
5
|
+
|
6
|
+
def initialize(guid, &block)
|
7
|
+
@sender = block
|
8
|
+
@guid = guid
|
9
|
+
@percentage = 0
|
10
|
+
end
|
11
|
+
|
12
|
+
def begin(title, message = nil, request_id:)
|
13
|
+
sender.call(
|
14
|
+
{
|
15
|
+
id: request_id,
|
16
|
+
method: "window/workDoneProgress/create",
|
17
|
+
params: { token: guid }
|
18
|
+
}
|
19
|
+
)
|
20
|
+
|
21
|
+
value = { kind: "begin", cancellable: false, title: title, percentage: percentage }
|
22
|
+
value[:message] = message if message
|
23
|
+
|
24
|
+
sender.call(
|
25
|
+
{
|
26
|
+
method: "$/progress",
|
27
|
+
params: { token: guid, value: value }
|
28
|
+
}
|
29
|
+
)
|
30
|
+
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
def report(percentage, message = nil)
|
35
|
+
@percentage = percentage
|
36
|
+
value = { kind: "report", percentage: percentage }
|
37
|
+
value[:message] = message if message
|
38
|
+
|
39
|
+
sender.call(
|
40
|
+
{
|
41
|
+
method: "$/progress",
|
42
|
+
params: { token: guid, value: value }
|
43
|
+
}
|
44
|
+
)
|
45
|
+
|
46
|
+
self
|
47
|
+
end
|
48
|
+
|
49
|
+
def end(message = nil)
|
50
|
+
value = { kind: "end" }
|
51
|
+
value[:message] = message if message
|
52
|
+
|
53
|
+
sender.call(
|
54
|
+
{
|
55
|
+
method: "$/progress",
|
56
|
+
params: { token: guid, value: value }
|
57
|
+
}
|
58
|
+
)
|
59
|
+
|
60
|
+
self
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -183,8 +183,9 @@ module Steep
|
|
183
183
|
end
|
184
184
|
|
185
185
|
Steep.measure "typechecking" do
|
186
|
+
location = source.buffer.loc_to_pos([line, column])
|
186
187
|
resolver = RBS::Resolver::ConstantResolver.new(builder: subtyping.factory.definition_builder)
|
187
|
-
@typing = TypeCheckService.type_check(source: source, subtyping: subtyping, constant_resolver: resolver)
|
188
|
+
@typing = TypeCheckService.type_check(source: source, subtyping: subtyping, constant_resolver: resolver, cursor: location)
|
188
189
|
end
|
189
190
|
end
|
190
191
|
|
@@ -348,7 +349,7 @@ module Steep
|
|
348
349
|
|
349
350
|
items = [] #: Array[item]
|
350
351
|
|
351
|
-
context = typing.
|
352
|
+
context = typing.cursor_context.context or raise
|
352
353
|
|
353
354
|
case
|
354
355
|
when node.type == :send && node.children[0] == nil && at_end?(position, of: (_ = node.loc).selector)
|
@@ -469,7 +470,7 @@ module Steep
|
|
469
470
|
|
470
471
|
if at_end?(shift_pos, of: node.loc)
|
471
472
|
begin
|
472
|
-
context = typing.
|
473
|
+
context = typing.cursor_context.context or raise
|
473
474
|
receiver_type =
|
474
475
|
case (type = typing.type_of(node: node))
|
475
476
|
when AST::Types::Self
|
@@ -499,7 +500,7 @@ module Steep
|
|
499
500
|
|
500
501
|
if at_end?(shift_pos, of: node.loc)
|
501
502
|
begin
|
502
|
-
context = typing.
|
503
|
+
context = typing.cursor_context.context or raise
|
503
504
|
receiver_type =
|
504
505
|
case (type = typing.type_of(node: node))
|
505
506
|
when AST::Types::Self
|
@@ -529,11 +530,11 @@ module Steep
|
|
529
530
|
case node&.type
|
530
531
|
when :const
|
531
532
|
# Constant:: ←
|
532
|
-
context = typing.
|
533
|
+
context = typing.cursor_context.context or raise
|
533
534
|
constant_items_for_context(context, parent: node, position: position, items: items, prefix: "")
|
534
535
|
when nil
|
535
536
|
# :: ←
|
536
|
-
context = typing.
|
537
|
+
context = typing.cursor_context.context or raise
|
537
538
|
constant_items_for_context(context, parent: nil, position: position, items: items, prefix: "")
|
538
539
|
end
|
539
540
|
|
@@ -552,7 +553,7 @@ module Steep
|
|
552
553
|
|
553
554
|
return [] unless node
|
554
555
|
|
555
|
-
context = typing.
|
556
|
+
context = typing.cursor_context.context or raise
|
556
557
|
items = [] #: Array[item]
|
557
558
|
instance_variable_items_for_context(context, prefix: "@", position: position, items: items)
|
558
559
|
items
|
@@ -561,7 +562,7 @@ module Steep
|
|
561
562
|
def items_for_rbs(position:, buffer:)
|
562
563
|
items = [] #: Array[item]
|
563
564
|
|
564
|
-
context = typing.
|
565
|
+
context = typing.cursor_context.context or raise
|
565
566
|
completion = TypeNameCompletion.new(env: context.env, context: context.module_context.nesting, dirs: [])
|
566
567
|
prefix = TypeNameCompletion::Prefix.parse(buffer, line: position.line, column: position.column)
|
567
568
|
|
@@ -609,7 +610,7 @@ module Steep
|
|
609
610
|
|
610
611
|
def method_items_for_receiver_type(type, include_private:, prefix:, position:, items:)
|
611
612
|
range = range_for(position, prefix: prefix)
|
612
|
-
context = typing.
|
613
|
+
context = typing.cursor_context.context or raise
|
613
614
|
|
614
615
|
config =
|
615
616
|
if (module_type = context.module_context&.module_type) && (instance_type = context.module_context&.instance_type)
|
@@ -634,39 +635,40 @@ module Steep
|
|
634
635
|
case type
|
635
636
|
when AST::Types::Name::Instance, AST::Types::Name::Interface, AST::Types::Name::Singleton
|
636
637
|
# Simple method type
|
637
|
-
all_decls = Set.new(method_entry.
|
638
|
+
all_decls = Set.new(method_entry.overloads.flat_map {|overload| overload.method_decls(name) }).sort_by {|decl| decl.method_name.to_s }
|
638
639
|
all_members = Set.new(all_decls.flat_map {|decl| decl.method_def.member })
|
639
640
|
all_members.each do |member|
|
640
641
|
associated_decl = all_decls.find {|decl| decl.method_def.member == member } or next
|
641
|
-
|
642
|
+
overloads = method_entry.overloads.select {|overload| overload.method_defs.any? {|defn| defn.member == member }}
|
642
643
|
items << SimpleMethodNameItem.new(
|
643
644
|
identifier: name,
|
644
645
|
range: range,
|
645
646
|
receiver_type: type,
|
646
647
|
method_name: associated_decl.method_name,
|
647
|
-
method_types:
|
648
|
+
method_types: overloads.map {|overload| subtyping.factory.method_type_1(overload.method_type) },
|
648
649
|
method_member: member
|
649
650
|
)
|
650
651
|
end
|
651
652
|
else
|
652
|
-
|
653
|
+
generated_overloads, defined_overloads =
|
654
|
+
method_entry.overloads.partition {|overload| overload.method_defs.empty? }
|
653
655
|
|
654
|
-
unless
|
656
|
+
unless defined_overloads.empty?
|
655
657
|
items << ComplexMethodNameItem.new(
|
656
658
|
identifier: name,
|
657
659
|
range: range,
|
658
660
|
receiver_type: type,
|
659
|
-
method_types:
|
660
|
-
method_decls:
|
661
|
+
method_types: defined_overloads.map { subtyping.factory.method_type_1(_1.method_type) },
|
662
|
+
method_decls: defined_overloads.flat_map { _1.method_decls(name).to_a }.sort_by {|decl| decl.method_name.to_s }
|
661
663
|
)
|
662
664
|
end
|
663
665
|
|
664
|
-
unless
|
666
|
+
unless generated_overloads.empty?
|
665
667
|
items << GeneratedMethodNameItem.new(
|
666
668
|
identifier: name,
|
667
669
|
range: range,
|
668
670
|
receiver_type: type,
|
669
|
-
method_types:
|
671
|
+
method_types: generated_overloads.map { subtyping.factory.method_type_1(_1.method_type) }
|
670
672
|
)
|
671
673
|
end
|
672
674
|
end
|
@@ -731,7 +733,7 @@ module Steep
|
|
731
733
|
|
732
734
|
case call
|
733
735
|
when TypeInference::MethodCall::Typed, TypeInference::MethodCall::Error
|
734
|
-
context = typing.
|
736
|
+
context = typing.cursor_context.context or raise
|
735
737
|
type = call.receiver_type
|
736
738
|
type = type.subst(Interface::Substitution.build([], self_type: context.self_type, module_type: context.module_context&.module_type, instance_type: context.module_context&.instance_type))
|
737
739
|
|
@@ -739,8 +741,8 @@ module Steep
|
|
739
741
|
if shape = subtyping.builder.shape(type, config)
|
740
742
|
shape = shape.public_shape if private_send?(call_node)
|
741
743
|
if method = shape.methods[call.method_name]
|
742
|
-
method.
|
743
|
-
defn =
|
744
|
+
method.overloads.each.with_index do |overload, i|
|
745
|
+
defn = overload.method_decls(call.method_name).to_a[0]&.method_def
|
744
746
|
if defn && defn.type.type
|
745
747
|
range = range_for(position, prefix: prefix)
|
746
748
|
kwargs = argument_nodes.find { |arg| arg.type == :kwargs }&.children || []
|
@@ -790,7 +792,7 @@ module Steep
|
|
790
792
|
def unwrap_optional(type)
|
791
793
|
if type.is_a?(AST::Types::Union) && type.types.include?(AST::Builtin.nil_type)
|
792
794
|
types = type.types.reject { |t| t == AST::Builtin.nil_type }
|
793
|
-
AST::Types::Union.new(types: types
|
795
|
+
AST::Types::Union.new(types: types)
|
794
796
|
else
|
795
797
|
type
|
796
798
|
end
|
@@ -176,7 +176,7 @@ module Steep
|
|
176
176
|
when :def, :defs
|
177
177
|
named_location = (_ = node.location) #: Parser::AST::_NamedLocation
|
178
178
|
if test_ast_location(named_location.name, line: line, column: column)
|
179
|
-
if method_context = typing.
|
179
|
+
if method_context = typing.cursor_context.context&.method_context
|
180
180
|
if method = method_context.method
|
181
181
|
method.defs.each do |defn|
|
182
182
|
singleton_method =
|
@@ -285,8 +285,9 @@ module Steep
|
|
285
285
|
source = Source.parse(content, path: path, factory: subtyping.factory)
|
286
286
|
source = source.without_unrelated_defs(line: line, column: column)
|
287
287
|
resolver = RBS::Resolver::ConstantResolver.new(builder: subtyping.factory.definition_builder)
|
288
|
+
loc = source.buffer.loc_to_pos([line, column])
|
288
289
|
[
|
289
|
-
Services::TypeCheckService.type_check(source: source, subtyping: subtyping, constant_resolver: resolver),
|
290
|
+
Services::TypeCheckService.type_check(source: source, subtyping: subtyping, constant_resolver: resolver, cursor: loc),
|
290
291
|
signature_service
|
291
292
|
]
|
292
293
|
rescue
|
@@ -84,7 +84,8 @@ module Steep
|
|
84
84
|
source = Source.parse(content, path: path, factory: subtyping.factory)
|
85
85
|
source = source.without_unrelated_defs(line: line, column: column)
|
86
86
|
resolver = ::RBS::Resolver::ConstantResolver.new(builder: subtyping.factory.definition_builder)
|
87
|
-
|
87
|
+
pos = source.buffer.loc_to_pos([line, column])
|
88
|
+
Services::TypeCheckService.type_check(source: source, subtyping: subtyping, constant_resolver: resolver, cursor: pos)
|
88
89
|
rescue
|
89
90
|
nil
|
90
91
|
end
|
@@ -118,8 +119,8 @@ module Steep
|
|
118
119
|
case node.type
|
119
120
|
when :lvar
|
120
121
|
var_name = node.children[0]
|
121
|
-
context = typing.
|
122
|
-
var_type = context.type_env[var_name] || AST::Types::Any.
|
122
|
+
context = typing.cursor_context.context or raise
|
123
|
+
var_type = context.type_env[var_name] || AST::Types::Any.instance()
|
123
124
|
|
124
125
|
return VariableContent.new(
|
125
126
|
node: node,
|
@@ -130,7 +131,7 @@ module Steep
|
|
130
131
|
|
131
132
|
when :lvasgn
|
132
133
|
var_name, rhs = node.children
|
133
|
-
context = typing.
|
134
|
+
context = typing.cursor_context.context or raise
|
134
135
|
type = context.type_env[var_name] || typing.type_of(node: node)
|
135
136
|
|
136
137
|
return VariableContent.new(
|
@@ -165,7 +166,7 @@ module Steep
|
|
165
166
|
end
|
166
167
|
|
167
168
|
when :def, :defs
|
168
|
-
context = typing.
|
169
|
+
context = typing.cursor_context.context or raise
|
169
170
|
method_context = context.method_context
|
170
171
|
|
171
172
|
if method_context && method_context.method
|
@@ -181,7 +182,7 @@ module Steep
|
|
181
182
|
end
|
182
183
|
|
183
184
|
when :const, :casgn
|
184
|
-
context = typing.
|
185
|
+
context = typing.cursor_context.context or raise
|
185
186
|
|
186
187
|
type = typing.type_of(node: node)
|
187
188
|
const_name = typing.source_index.reference(constant_node: node)
|
@@ -76,7 +76,8 @@ module Steep
|
|
76
76
|
def type_check!(line:, column:)
|
77
77
|
source = self.source.without_unrelated_defs(line: line, column: column)
|
78
78
|
resolver = RBS::Resolver::ConstantResolver.new(builder: subtyping.factory.definition_builder)
|
79
|
-
|
79
|
+
pos = self.source.buffer.loc_to_pos([line, column])
|
80
|
+
TypeCheckService.type_check(source: source, subtyping: subtyping, constant_resolver: resolver, cursor: pos)
|
80
81
|
end
|
81
82
|
|
82
83
|
def last_argument_nodes_for(argument_nodes:, line:, column:)
|
@@ -99,7 +100,7 @@ module Steep
|
|
99
100
|
|
100
101
|
def signature_help_for(node, argument, last_argument, typing)
|
101
102
|
call = typing.call_of(node: node)
|
102
|
-
context = typing.
|
103
|
+
context = typing.cursor_context.context or raise
|
103
104
|
|
104
105
|
items = [] #: Array[Item]
|
105
106
|
index = nil #: Integer?
|
@@ -113,14 +114,14 @@ module Steep
|
|
113
114
|
shape = shape.public_shape if private_send?(node)
|
114
115
|
|
115
116
|
if method = shape.methods[call.method_name]
|
116
|
-
method.
|
117
|
-
defn =
|
117
|
+
method.overloads.each.with_index do |overload, i|
|
118
|
+
defn = overload.method_defs[0]
|
118
119
|
|
119
120
|
active_parameter = active_parameter_for(defn&.type, argument, last_argument, node)
|
120
|
-
items << Item.new(subtyping.factory.method_type_1(method_type), defn&.comment, active_parameter)
|
121
|
+
items << Item.new(subtyping.factory.method_type_1(overload.method_type), defn&.comment, active_parameter)
|
121
122
|
|
122
123
|
if call.is_a?(MethodCall::Typed)
|
123
|
-
if
|
124
|
+
if call.method_decls.intersect?(overload.method_decls(call.method_name).to_set)
|
124
125
|
index = i
|
125
126
|
end
|
126
127
|
end
|
@@ -156,6 +156,7 @@ module Steep
|
|
156
156
|
old_text = files[path]&.content
|
157
157
|
content = cs.inject(old_text || "") {|text, change| change.apply_to(text) }
|
158
158
|
|
159
|
+
content ||= "" # It was not clear why `content` can be `nil`, but it happens with `master_test`.
|
159
160
|
buffer = RBS::Buffer.new(name: path, content: content)
|
160
161
|
|
161
162
|
update[path] =
|
@@ -228,7 +229,6 @@ module Steep
|
|
228
229
|
end
|
229
230
|
|
230
231
|
def update_env(updated_files, paths:)
|
231
|
-
|
232
232
|
Steep.logger.tagged "#update_env" do
|
233
233
|
errors = [] #: Array[RBS::BaseError]
|
234
234
|
new_decls = Set[].compare_by_identity #: Set[RBS::AST::Declarations::t]
|
@@ -363,7 +363,7 @@ module Steep
|
|
363
363
|
def type_check_file(target:, subtyping:, path:, text:)
|
364
364
|
Steep.logger.tagged "#type_check_file(#{path}@#{target.name})" do
|
365
365
|
source = Source.parse(text, path: path, factory: subtyping.factory)
|
366
|
-
typing = TypeCheckService.type_check(source: source, subtyping: subtyping, constant_resolver: yield)
|
366
|
+
typing = TypeCheckService.type_check(source: source, subtyping: subtyping, constant_resolver: yield, cursor: nil)
|
367
367
|
ignores = Source::IgnoreRanges.new(ignores: source.ignores)
|
368
368
|
SourceFile.with_typing(path: path, content: text, node: source.node, typing: typing, ignores: ignores)
|
369
369
|
end
|
@@ -380,7 +380,7 @@ module Steep
|
|
380
380
|
SourceFile.no_data(path: path, content: text)
|
381
381
|
end
|
382
382
|
|
383
|
-
def self.type_check(source:, subtyping:, constant_resolver:)
|
383
|
+
def self.type_check(source:, subtyping:, constant_resolver:, cursor:)
|
384
384
|
annotations = source.annotations(block: source.node, factory: subtyping.factory, context: nil)
|
385
385
|
|
386
386
|
definition = subtyping.factory.definition_builder.build_instance(AST::Builtin::Object.module_name)
|
@@ -418,7 +418,7 @@ module Steep
|
|
418
418
|
variable_context: TypeInference::Context::TypeVariableContext.empty
|
419
419
|
)
|
420
420
|
|
421
|
-
typing = Typing.new(source: source, root_context: context)
|
421
|
+
typing = Typing.new(source: source, root_context: context, cursor: cursor)
|
422
422
|
|
423
423
|
construction = TypeConstruction.new(
|
424
424
|
checker: subtyping,
|
@@ -79,8 +79,8 @@ module Steep
|
|
79
79
|
type_params.zip(type_args).each do |param, arg|
|
80
80
|
arg or raise
|
81
81
|
|
82
|
-
if param.
|
83
|
-
upper_bound_type = factory.type(param.
|
82
|
+
if param.upper_bound_type
|
83
|
+
upper_bound_type = factory.type(param.upper_bound_type).subst(subst)
|
84
84
|
arg_type = factory.type(arg)
|
85
85
|
|
86
86
|
constraints = Subtyping::Constraints.empty
|
@@ -101,7 +101,8 @@ module Steep
|
|
101
101
|
name: param.name,
|
102
102
|
upper_bound: upper_bound_type,
|
103
103
|
variance: param.variance,
|
104
|
-
unchecked: param.unchecked
|
104
|
+
unchecked: param.unchecked?,
|
105
|
+
default_type: factory.type_opt(param.default_type)
|
105
106
|
),
|
106
107
|
location: location
|
107
108
|
)
|
@@ -162,9 +163,9 @@ module Steep
|
|
162
163
|
|
163
164
|
case
|
164
165
|
when ancestor.name.interface?
|
165
|
-
AST::Types::Name::Interface.new(name: ancestor.name, args: args
|
166
|
+
AST::Types::Name::Interface.new(name: ancestor.name, args: args)
|
166
167
|
when ancestor.name.class?
|
167
|
-
AST::Types::Name::Instance.new(name: ancestor.name, args: args
|
168
|
+
AST::Types::Name::Instance.new(name: ancestor.name, args: args)
|
168
169
|
else
|
169
170
|
raise "#{ancestor.name}"
|
170
171
|
end
|
@@ -181,7 +182,7 @@ module Steep
|
|
181
182
|
if immediate_self_types && !immediate_self_types.empty?
|
182
183
|
# @type var sts: Array[AST::Types::t]
|
183
184
|
sts = immediate_self_types.map {|st| ancestor_to_type(st) }
|
184
|
-
self_type = AST::Types::Intersection.build(types: sts.push(self_type)
|
185
|
+
self_type = AST::Types::Intersection.build(types: sts.push(self_type))
|
185
186
|
end
|
186
187
|
|
187
188
|
mixin_ancestors.each do |ancestor|
|
@@ -236,7 +237,7 @@ module Steep
|
|
236
237
|
def validate_definition_type(definition)
|
237
238
|
each_method_type(definition) do |method_type|
|
238
239
|
upper_bounds = method_type.type_params.each.with_object({}) do |param, hash|
|
239
|
-
hash[param.name] = factory.type_opt(param.
|
240
|
+
hash[param.name] = factory.type_opt(param.upper_bound_type)
|
240
241
|
end
|
241
242
|
|
242
243
|
checker.push_variable_bounds(upper_bounds) do
|
@@ -255,23 +256,21 @@ module Steep
|
|
255
256
|
rescue_validation_errors(name) do
|
256
257
|
Steep.logger.debug { "Validating class definition `#{name}`..." }
|
257
258
|
|
258
|
-
class_type = AST::Types::Name::Singleton.new(name: name
|
259
|
+
class_type = AST::Types::Name::Singleton.new(name: name)
|
259
260
|
instance_type = AST::Types::Name::Instance.new(
|
260
261
|
name: name,
|
261
|
-
args: entry.type_params.map { AST::Types::Any.
|
262
|
-
location: nil
|
262
|
+
args: entry.type_params.map { AST::Types::Any.instance() }
|
263
263
|
)
|
264
264
|
|
265
265
|
Steep.logger.tagged "#{name}" do
|
266
266
|
builder.build_instance(name).tap do |definition|
|
267
267
|
upper_bounds = definition.type_params_decl.each.with_object({}) do |param, bounds|
|
268
|
-
bounds[param.name] = factory.type_opt(param.
|
268
|
+
bounds[param.name] = factory.type_opt(param.upper_bound_type)
|
269
269
|
end
|
270
270
|
|
271
271
|
self_type = AST::Types::Name::Instance.new(
|
272
272
|
name: name,
|
273
|
-
args: entry.type_params.map { AST::Types::Var.new(name: _1.name) }
|
274
|
-
location: nil
|
273
|
+
args: entry.type_params.map { AST::Types::Var.new(name: _1.name) }
|
275
274
|
)
|
276
275
|
|
277
276
|
push_context(self_type: self_type, class_type: class_type, instance_type: instance_type) do
|
@@ -482,13 +481,12 @@ module Steep
|
|
482
481
|
definition = builder.build_interface(name)
|
483
482
|
|
484
483
|
upper_bounds = definition.type_params_decl.each.with_object({}) do |param, bounds|
|
485
|
-
bounds[param.name] = factory.type_opt(param.
|
484
|
+
bounds[param.name] = factory.type_opt(param.upper_bound_type)
|
486
485
|
end
|
487
486
|
|
488
487
|
self_type = AST::Types::Name::Interface.new(
|
489
488
|
name: name,
|
490
|
-
args: definition.type_params.map { AST::Types::Var.new(name: _1) }
|
491
|
-
location: nil
|
489
|
+
args: definition.type_params.map { AST::Types::Var.new(name: _1) }
|
492
490
|
)
|
493
491
|
|
494
492
|
push_context(self_type: self_type, class_type: nil, instance_type: nil) do
|
@@ -561,11 +559,10 @@ module Steep
|
|
561
559
|
def validate_one_alias(name, entry = env.type_alias_decls[name])
|
562
560
|
*, inner_most_outer_module = entry.outer
|
563
561
|
if inner_most_outer_module
|
564
|
-
class_type = AST::Types::Name::Singleton.new(name: inner_most_outer_module.name
|
562
|
+
class_type = AST::Types::Name::Singleton.new(name: inner_most_outer_module.name)
|
565
563
|
instance_type = AST::Types::Name::Instance.new(
|
566
564
|
name: inner_most_outer_module.name,
|
567
|
-
args: inner_most_outer_module.type_params.map { AST::Types::Any.
|
568
|
-
location: nil
|
565
|
+
args: inner_most_outer_module.type_params.map { AST::Types::Any.instance() },
|
569
566
|
)
|
570
567
|
end
|
571
568
|
|
@@ -579,7 +576,7 @@ module Steep
|
|
579
576
|
end
|
580
577
|
|
581
578
|
upper_bounds = entry.decl.type_params.each.with_object({}) do |param, bounds|
|
582
|
-
bounds[param.name] = factory.type_opt(param.
|
579
|
+
bounds[param.name] = factory.type_opt(param.upper_bound_type)
|
583
580
|
end
|
584
581
|
|
585
582
|
validator.validate_type_alias(entry: entry) do |type|
|