steep 0.11.1 → 0.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +27 -0
- data/.gitmodules +3 -0
- data/CHANGELOG.md +5 -0
- data/README.md +48 -90
- data/Rakefile +10 -6
- data/Steepfile +1 -0
- data/bin/setup +1 -0
- data/bin/smoke_runner.rb +9 -14
- data/exe/rbs +3 -0
- data/exe/ruby-signature +3 -0
- data/exe/steep +1 -0
- data/lib/steep.rb +32 -26
- data/lib/steep/annotation_parser.rb +167 -0
- data/lib/steep/ast/annotation/collection.rb +7 -7
- data/lib/steep/ast/types.rb +60 -0
- data/lib/steep/ast/types/any.rb +1 -1
- data/lib/steep/ast/types/factory.rb +535 -0
- data/lib/steep/ast/types/name.rb +3 -3
- data/lib/steep/ast/types/var.rb +1 -1
- data/lib/steep/cli.rb +56 -240
- data/lib/steep/drivers/annotations.rb +36 -19
- data/lib/steep/drivers/check.rb +55 -91
- data/lib/steep/drivers/init.rb +54 -0
- data/lib/steep/drivers/langserver.rb +241 -150
- data/lib/steep/drivers/print_project.rb +56 -0
- data/lib/steep/drivers/signature_error_printer.rb +25 -0
- data/lib/steep/drivers/trace_printer.rb +25 -0
- data/lib/steep/drivers/utils/driver_helper.rb +26 -0
- data/lib/steep/drivers/validate.rb +18 -38
- data/lib/steep/drivers/vendor.rb +46 -0
- data/lib/steep/drivers/watch.rb +78 -140
- data/lib/steep/errors.rb +22 -13
- data/lib/steep/interface/interface.rb +91 -0
- data/lib/steep/interface/method.rb +0 -4
- data/lib/steep/interface/method_type.rb +362 -2
- data/lib/steep/interface/substitution.rb +22 -0
- data/lib/steep/project.rb +25 -233
- data/lib/steep/project/dsl.rb +132 -0
- data/lib/steep/project/file.rb +93 -76
- data/lib/steep/project/file_loader.rb +63 -0
- data/lib/steep/project/options.rb +7 -0
- data/lib/steep/project/target.rb +190 -0
- data/lib/steep/signature/errors.rb +25 -77
- data/lib/steep/signature/validator.rb +122 -0
- data/lib/steep/source.rb +12 -7
- data/lib/steep/subtyping/check.rb +357 -633
- data/lib/steep/subtyping/constraints.rb +2 -2
- data/lib/steep/subtyping/trace.rb +23 -0
- data/lib/steep/type_construction.rb +509 -455
- data/lib/steep/type_inference/constant_env.rb +16 -24
- data/lib/steep/type_inference/type_env.rb +26 -18
- data/lib/steep/version.rb +1 -1
- data/sample/Steepfile +6 -0
- data/sample/lib/conference.rb +12 -0
- data/sample/sig/conference.rbs +6 -0
- data/smoke/alias/Steepfile +4 -0
- data/smoke/alias/a.rb +2 -2
- data/smoke/alias/{a.rbi → a.rbs} +1 -1
- data/smoke/and/Steepfile +4 -0
- data/smoke/array/Steepfile +4 -0
- data/smoke/array/a.rb +2 -2
- data/smoke/array/b.rb +4 -4
- data/smoke/array/c.rb +2 -2
- data/smoke/block/Steepfile +5 -0
- data/smoke/block/{a.rbi → a.rbs} +1 -1
- data/smoke/block/{c.rbi → c.rbs} +0 -0
- data/smoke/block/d.rb +6 -6
- data/smoke/case/Steepfile +4 -0
- data/smoke/case/a.rb +4 -3
- data/smoke/class/Steepfile +4 -0
- data/smoke/class/a.rb +1 -4
- data/smoke/class/a.rbs +24 -0
- data/smoke/class/h.rb +6 -2
- data/smoke/class/{h.rbi → h.rbs} +1 -2
- data/smoke/class/i.rb +1 -2
- data/smoke/class/i.rbs +9 -0
- data/smoke/const/Steepfile +4 -0
- data/smoke/dstr/Steepfile +4 -0
- data/smoke/ensure/Steepfile +4 -0
- data/smoke/ensure/a.rb +1 -1
- data/smoke/enumerator/Steepfile +4 -0
- data/smoke/enumerator/a.rb +7 -7
- data/smoke/enumerator/b.rb +6 -6
- data/smoke/extension/Steepfile +4 -0
- data/smoke/extension/{a.rbi → a.rbs} +2 -2
- data/smoke/extension/{e.rbi → e.rbs} +2 -2
- data/smoke/hash/Steepfile +4 -0
- data/smoke/hash/{a.rbi → a.rbs} +0 -0
- data/smoke/hash/b.rb +2 -2
- data/smoke/hash/c.rb +1 -1
- data/smoke/hash/e.rbs +3 -0
- data/smoke/hash/f.rb +1 -1
- data/smoke/hello/Steepfile +4 -0
- data/smoke/hello/hello.rbs +7 -0
- data/smoke/if/Steepfile +4 -0
- data/smoke/implements/Steepfile +4 -0
- data/smoke/implements/a.rbs +6 -0
- data/smoke/initialize/Steepfile +4 -0
- data/smoke/initialize/a.rbs +3 -0
- data/smoke/integer/Steepfile +4 -0
- data/smoke/integer/a.rb +5 -3
- data/smoke/interface/Steepfile +4 -0
- data/smoke/interface/{a.rbi → a.rbs} +0 -0
- data/smoke/kwbegin/Steepfile +4 -0
- data/smoke/lambda/Steepfile +4 -0
- data/smoke/lambda/a.rb +9 -2
- data/smoke/literal/Steepfile +4 -0
- data/smoke/literal/{literal_methods.rbi → literal_methods.rbs} +0 -0
- data/smoke/map/Steepfile +4 -0
- data/smoke/map/a.rb +1 -1
- data/smoke/method/Steepfile +4 -0
- data/smoke/method/{a.rbi → a.rbs} +0 -0
- data/smoke/method/b.rb +1 -4
- data/smoke/method/d.rb +1 -0
- data/smoke/method/d.rbs +3 -0
- data/smoke/module/Steepfile +4 -0
- data/smoke/module/a.rb +1 -1
- data/smoke/module/a.rbs +16 -0
- data/smoke/module/c.rb +1 -1
- data/smoke/regexp/Steepfile +4 -0
- data/smoke/regexp/a.rb +2 -2
- data/smoke/regexp/b.rb +16 -16
- data/smoke/regression/Steepfile +5 -0
- data/smoke/regression/array.rb +2 -2
- data/smoke/regression/hash.rb +2 -2
- data/smoke/regression/poly_new.rb +2 -0
- data/smoke/regression/poly_new.rbs +4 -0
- data/smoke/regression/set_divide.rb +2 -2
- data/smoke/rescue/Steepfile +4 -0
- data/smoke/rescue/a.rb +1 -1
- data/smoke/self/Steepfile +4 -0
- data/smoke/self/a.rbs +4 -0
- data/smoke/skip/Steepfile +4 -0
- data/smoke/stdout/Steepfile +4 -0
- data/smoke/stdout/{a.rbi → a.rbs} +1 -1
- data/smoke/super/Steepfile +4 -0
- data/smoke/super/a.rbs +10 -0
- data/smoke/type_case/Steepfile +4 -0
- data/smoke/type_case/a.rb +1 -1
- data/smoke/yield/Steepfile +4 -0
- data/smoke/yield/a.rb +2 -2
- data/steep.gemspec +14 -7
- data/vendor/ruby-signature/.github/workflows/ruby.yml +27 -0
- data/vendor/ruby-signature/.gitignore +12 -0
- data/vendor/ruby-signature/.rubocop.yml +15 -0
- data/vendor/ruby-signature/BSDL +22 -0
- data/vendor/ruby-signature/COPYING +56 -0
- data/vendor/ruby-signature/Gemfile +6 -0
- data/vendor/ruby-signature/README.md +93 -0
- data/vendor/ruby-signature/Rakefile +66 -0
- data/vendor/ruby-signature/bin/annotate-with-rdoc +156 -0
- data/vendor/ruby-signature/bin/console +14 -0
- data/vendor/ruby-signature/bin/query-rdoc +103 -0
- data/vendor/ruby-signature/bin/setup +10 -0
- data/vendor/ruby-signature/bin/sort +88 -0
- data/vendor/ruby-signature/bin/test_runner.rb +17 -0
- data/vendor/ruby-signature/docs/CONTRIBUTING.md +97 -0
- data/vendor/ruby-signature/docs/sigs.md +148 -0
- data/vendor/ruby-signature/docs/stdlib.md +152 -0
- data/vendor/ruby-signature/docs/syntax.md +528 -0
- data/vendor/ruby-signature/exe/rbs +3 -0
- data/vendor/ruby-signature/exe/ruby-signature +7 -0
- data/vendor/ruby-signature/lib/ruby/signature.rb +64 -0
- data/vendor/ruby-signature/lib/ruby/signature/ast/annotation.rb +29 -0
- data/vendor/ruby-signature/lib/ruby/signature/ast/comment.rb +29 -0
- data/vendor/ruby-signature/lib/ruby/signature/ast/declarations.rb +391 -0
- data/vendor/ruby-signature/lib/ruby/signature/ast/members.rb +364 -0
- data/vendor/ruby-signature/lib/ruby/signature/buffer.rb +52 -0
- data/vendor/ruby-signature/lib/ruby/signature/builtin_names.rb +54 -0
- data/vendor/ruby-signature/lib/ruby/signature/cli.rb +534 -0
- data/vendor/ruby-signature/lib/ruby/signature/constant.rb +28 -0
- data/vendor/ruby-signature/lib/ruby/signature/constant_table.rb +152 -0
- data/vendor/ruby-signature/lib/ruby/signature/definition.rb +172 -0
- data/vendor/ruby-signature/lib/ruby/signature/definition_builder.rb +921 -0
- data/vendor/ruby-signature/lib/ruby/signature/environment.rb +283 -0
- data/vendor/ruby-signature/lib/ruby/signature/environment_loader.rb +138 -0
- data/vendor/ruby-signature/lib/ruby/signature/environment_walker.rb +126 -0
- data/vendor/ruby-signature/lib/ruby/signature/errors.rb +189 -0
- data/vendor/ruby-signature/lib/ruby/signature/location.rb +104 -0
- data/vendor/ruby-signature/lib/ruby/signature/method_type.rb +125 -0
- data/vendor/ruby-signature/lib/ruby/signature/namespace.rb +93 -0
- data/vendor/ruby-signature/lib/ruby/signature/parser.y +1343 -0
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +441 -0
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rbi.rb +579 -0
- data/vendor/ruby-signature/lib/ruby/signature/prototype/runtime.rb +383 -0
- data/vendor/ruby-signature/lib/ruby/signature/substitution.rb +48 -0
- data/vendor/ruby-signature/lib/ruby/signature/test.rb +28 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/errors.rb +63 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/hook.rb +290 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/setup.rb +58 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +324 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/test_helper.rb +185 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/type_check.rb +256 -0
- data/vendor/ruby-signature/lib/ruby/signature/type_name.rb +72 -0
- data/vendor/ruby-signature/lib/ruby/signature/types.rb +932 -0
- data/vendor/ruby-signature/lib/ruby/signature/variance_calculator.rb +140 -0
- data/vendor/ruby-signature/lib/ruby/signature/vendorer.rb +49 -0
- data/vendor/ruby-signature/lib/ruby/signature/version.rb +5 -0
- data/vendor/ruby-signature/lib/ruby/signature/writer.rb +271 -0
- data/vendor/ruby-signature/ruby-signature.gemspec +45 -0
- data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +3 -0
- data/vendor/ruby-signature/stdlib/base64/base64.rbs +15 -0
- data/vendor/ruby-signature/stdlib/builtin/array.rbs +1997 -0
- data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +280 -0
- data/vendor/ruby-signature/stdlib/builtin/binding.rbs +177 -0
- data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +35 -0
- data/vendor/ruby-signature/stdlib/builtin/class.rbs +145 -0
- data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +116 -0
- data/vendor/ruby-signature/stdlib/builtin/complex.rbs +400 -0
- data/vendor/ruby-signature/stdlib/builtin/constants.rbs +37 -0
- data/vendor/ruby-signature/stdlib/builtin/data.rbs +5 -0
- data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +2 -0
- data/vendor/ruby-signature/stdlib/builtin/dir.rbs +419 -0
- data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +606 -0
- data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +404 -0
- data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +260 -0
- data/vendor/ruby-signature/stdlib/builtin/errno.rbs +781 -0
- data/vendor/ruby-signature/stdlib/builtin/errors.rbs +582 -0
- data/vendor/ruby-signature/stdlib/builtin/exception.rbs +193 -0
- data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +40 -0
- data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +68 -0
- data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +12 -0
- data/vendor/ruby-signature/stdlib/builtin/file.rbs +476 -0
- data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +59 -0
- data/vendor/ruby-signature/stdlib/builtin/float.rbs +696 -0
- data/vendor/ruby-signature/stdlib/builtin/gc.rbs +121 -0
- data/vendor/ruby-signature/stdlib/builtin/hash.rbs +1029 -0
- data/vendor/ruby-signature/stdlib/builtin/integer.rbs +710 -0
- data/vendor/ruby-signature/stdlib/builtin/io.rbs +683 -0
- data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +574 -0
- data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +135 -0
- data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +141 -0
- data/vendor/ruby-signature/stdlib/builtin/math.rbs +66 -0
- data/vendor/ruby-signature/stdlib/builtin/method.rbs +182 -0
- data/vendor/ruby-signature/stdlib/builtin/module.rbs +248 -0
- data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +82 -0
- data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +409 -0
- data/vendor/ruby-signature/stdlib/builtin/object.rbs +824 -0
- data/vendor/ruby-signature/stdlib/builtin/proc.rbs +426 -0
- data/vendor/ruby-signature/stdlib/builtin/process.rbs +354 -0
- data/vendor/ruby-signature/stdlib/builtin/random.rbs +93 -0
- data/vendor/ruby-signature/stdlib/builtin/range.rbs +226 -0
- data/vendor/ruby-signature/stdlib/builtin/rational.rbs +424 -0
- data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +10 -0
- data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +131 -0
- data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +14 -0
- data/vendor/ruby-signature/stdlib/builtin/signal.rbs +55 -0
- data/vendor/ruby-signature/stdlib/builtin/string.rbs +770 -0
- data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +13 -0
- data/vendor/ruby-signature/stdlib/builtin/struct.rbs +40 -0
- data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +230 -0
- data/vendor/ruby-signature/stdlib/builtin/thread.rbs +1112 -0
- data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +23 -0
- data/vendor/ruby-signature/stdlib/builtin/time.rbs +739 -0
- data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +91 -0
- data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +46 -0
- data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +159 -0
- data/vendor/ruby-signature/stdlib/builtin/warning.rbs +17 -0
- data/vendor/ruby-signature/stdlib/erb/erb.rbs +18 -0
- data/vendor/ruby-signature/stdlib/find/find.rbs +44 -0
- data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +21 -0
- data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +23 -0
- data/vendor/ruby-signature/stdlib/prime/prime.rbs +188 -0
- data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +9 -0
- data/vendor/ruby-signature/stdlib/set/set.rbs +77 -0
- data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +53 -0
- metadata +244 -54
- data/.travis.yml +0 -7
- data/lib/steep/ast/signature/alias.rb +0 -19
- data/lib/steep/ast/signature/class.rb +0 -33
- data/lib/steep/ast/signature/const.rb +0 -17
- data/lib/steep/ast/signature/env.rb +0 -138
- data/lib/steep/ast/signature/extension.rb +0 -21
- data/lib/steep/ast/signature/gvar.rb +0 -17
- data/lib/steep/ast/signature/interface.rb +0 -31
- data/lib/steep/ast/signature/members.rb +0 -115
- data/lib/steep/ast/signature/module.rb +0 -21
- data/lib/steep/drivers/print_interface.rb +0 -94
- data/lib/steep/drivers/scaffold.rb +0 -321
- data/lib/steep/drivers/utils/each_signature.rb +0 -31
- data/lib/steep/interface/abstract.rb +0 -68
- data/lib/steep/interface/builder.rb +0 -637
- data/lib/steep/interface/instantiated.rb +0 -163
- data/lib/steep/interface/ivar_chain.rb +0 -26
- data/lib/steep/parser.y +0 -1278
- data/lib/steep/project/listener.rb +0 -53
- data/smoke/class/a.rbi +0 -24
- data/smoke/class/d.rb +0 -9
- data/smoke/class/e.rb +0 -12
- data/smoke/class/i.rbi +0 -9
- data/smoke/hash/e.rbi +0 -3
- data/smoke/hello/hello.rbi +0 -7
- data/smoke/implements/a.rbi +0 -6
- data/smoke/initialize/a.rbi +0 -3
- data/smoke/module/a.rbi +0 -16
- data/smoke/self/a.rbi +0 -4
- data/smoke/super/a.rbi +0 -10
- data/stdlib/builtin.rbi +0 -787
@@ -1,20 +1,18 @@
|
|
1
1
|
module Steep
|
2
2
|
module TypeInference
|
3
3
|
class ConstantEnv
|
4
|
-
attr_reader :builder
|
5
4
|
attr_reader :context
|
6
5
|
attr_reader :cache
|
6
|
+
attr_reader :factory
|
7
|
+
attr_reader :table
|
7
8
|
|
8
|
-
# ConstantEnv receives an
|
9
|
+
# ConstantEnv receives an Names::Module as a context, not a Namespace, because this is a simulation of Ruby.
|
9
10
|
# Any namespace is a module or class.
|
10
|
-
def initialize(
|
11
|
+
def initialize(factory:, context:)
|
11
12
|
@cache = {}
|
12
|
-
@
|
13
|
+
@factory = factory
|
13
14
|
@context = context
|
14
|
-
|
15
|
-
|
16
|
-
def signatures
|
17
|
-
builder.signatures
|
15
|
+
@table = Ruby::Signature::ConstantTable.new(builder: factory.definition_builder)
|
18
16
|
end
|
19
17
|
|
20
18
|
def namespace
|
@@ -26,24 +24,18 @@ module Steep
|
|
26
24
|
end
|
27
25
|
|
28
26
|
def lookup(name)
|
29
|
-
cache[name] ||=
|
30
|
-
|
27
|
+
cache[name] ||= begin
|
28
|
+
constant = table.resolve_constant_reference(
|
29
|
+
factory.type_name_1(name),
|
30
|
+
context: factory.namespace_1(namespace)
|
31
|
+
)
|
31
32
|
|
32
|
-
|
33
|
-
|
34
|
-
full_name = name.in_namespace(namespace)
|
35
|
-
case
|
36
|
-
when signatures.module_name?(full_name)
|
37
|
-
AST::Types::Name::Module.new(name: full_name)
|
38
|
-
when signatures.class_name?(full_name)
|
39
|
-
AST::Types::Name::Class.new(name: full_name, constructor: true)
|
40
|
-
when signatures.const_name?(full_name)
|
41
|
-
builder.absolute_type(signatures.find_const(name, current_module: namespace).type,
|
42
|
-
current: namespace)
|
43
|
-
else
|
44
|
-
unless namespace.empty?
|
45
|
-
lookup0(name, namespace: namespace.parent)
|
33
|
+
if constant
|
34
|
+
factory.type(constant.type)
|
46
35
|
end
|
36
|
+
rescue => exn
|
37
|
+
Steep.logger.error "Looking up a constant failed: name=#{name}, context=#{context}, error=#{exn.inspect}"
|
38
|
+
nil
|
47
39
|
end
|
48
40
|
end
|
49
41
|
end
|
@@ -37,23 +37,27 @@ module Steep
|
|
37
37
|
annotations.const_types.each do |name, type|
|
38
38
|
env.set(const: name, type: type)
|
39
39
|
end
|
40
|
-
signatures.
|
41
|
-
type =
|
42
|
-
env.set(gvar: name, type: type)
|
40
|
+
signatures.name_to_global.each do |name, global|
|
41
|
+
type = signatures.absolute_type(global.type, namespace: Ruby::Signature::Namespace.root) {|ty| ty.name.absolute! }
|
42
|
+
env.set(gvar: name, type: subtyping.factory.type(type))
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
def with_annotations(lvar_types: {}, ivar_types: {}, const_types: {}, gvar_types: {}, &block)
|
47
|
+
def with_annotations(lvar_types: {}, ivar_types: {}, const_types: {}, gvar_types: {}, self_type:, &block)
|
48
48
|
dup.tap do |env|
|
49
|
-
merge!(original_env: env.lvar_types, override_env: lvar_types, &block)
|
50
|
-
merge!(original_env: env.ivar_types, override_env: ivar_types, &block)
|
51
|
-
merge!(original_env: env.gvar_types, override_env: gvar_types, &block)
|
49
|
+
merge!(original_env: env.lvar_types, override_env: lvar_types, self_type: self_type, &block)
|
50
|
+
merge!(original_env: env.ivar_types, override_env: ivar_types, self_type: self_type, &block)
|
51
|
+
merge!(original_env: env.gvar_types, override_env: gvar_types, self_type: self_type, &block)
|
52
52
|
|
53
53
|
const_types.each do |name, annotated_type|
|
54
54
|
original_type = self.const_types[name] || const_env.lookup(name)
|
55
55
|
if original_type
|
56
|
-
assert_annotation name,
|
56
|
+
assert_annotation name,
|
57
|
+
original_type: original_type,
|
58
|
+
annotated_type: annotated_type,
|
59
|
+
self_type: self_type,
|
60
|
+
&block
|
57
61
|
end
|
58
62
|
env.const_types[name] = annotated_type
|
59
63
|
end
|
@@ -142,14 +146,14 @@ module Steep
|
|
142
146
|
# | (gvar: Symbol, type: AST::Type) { (Subtyping::Result::Failure | nil) -> void } -> AST::Type
|
143
147
|
# | (ivar: Symbol, type: AST::Type) { (Subtyping::Result::Failure | nil) -> void } -> AST::Type
|
144
148
|
# | (lvar: Symbol | LabeledName, type: AST::Type) { (Subtyping::Result::Failure) -> void } -> AST::Type
|
145
|
-
def assign(lvar: nil, const: nil, gvar: nil, ivar: nil, type:, &block)
|
149
|
+
def assign(lvar: nil, const: nil, gvar: nil, ivar: nil, type:, self_type:, &block)
|
146
150
|
case
|
147
151
|
when lvar
|
148
152
|
yield_self do
|
149
153
|
name = lvar_name(lvar)
|
150
154
|
var_type = lvar_types[name]
|
151
155
|
if var_type
|
152
|
-
assert_assign(var_type: var_type, lhs_type: type, &block)
|
156
|
+
assert_assign(var_type: var_type, lhs_type: type, self_type: self_type, &block)
|
153
157
|
else
|
154
158
|
lvar_types[name] = type
|
155
159
|
end
|
@@ -158,7 +162,7 @@ module Steep
|
|
158
162
|
yield_self do
|
159
163
|
const_type = const_types[const] || const_env.lookup(const)
|
160
164
|
if const_type
|
161
|
-
assert_assign(var_type: const_type, lhs_type: type, &block)
|
165
|
+
assert_assign(var_type: const_type, lhs_type: type, self_type: self_type, &block)
|
162
166
|
else
|
163
167
|
yield nil
|
164
168
|
AST::Types::Any.new
|
@@ -167,7 +171,7 @@ module Steep
|
|
167
171
|
else
|
168
172
|
lookup_dictionary(ivar: ivar, gvar: gvar) do |var_name, dictionary|
|
169
173
|
if dictionary.key?(var_name)
|
170
|
-
assert_assign(var_type: dictionary[var_name], lhs_type: type, &block)
|
174
|
+
assert_assign(var_type: dictionary[var_name], lhs_type: type, self_type: self_type, &block)
|
171
175
|
else
|
172
176
|
yield nil
|
173
177
|
AST::Types::Any.new
|
@@ -194,34 +198,38 @@ module Steep
|
|
194
198
|
end
|
195
199
|
end
|
196
200
|
|
197
|
-
def assert_assign(var_type:, lhs_type:)
|
201
|
+
def assert_assign(var_type:, lhs_type:, self_type:)
|
202
|
+
return var_type if var_type == lhs_type
|
203
|
+
|
198
204
|
var_type = subtyping.expand_alias(var_type)
|
199
205
|
lhs_type = subtyping.expand_alias(lhs_type)
|
200
206
|
|
201
207
|
relation = Subtyping::Relation.new(sub_type: lhs_type, super_type: var_type)
|
202
208
|
constraints = Subtyping::Constraints.new(unknowns: Set.new)
|
203
209
|
|
204
|
-
subtyping.check(relation, constraints: constraints).else do |result|
|
210
|
+
subtyping.check(relation, self_type: self_type, constraints: constraints).else do |result|
|
205
211
|
yield result
|
206
212
|
end
|
207
213
|
|
208
214
|
var_type
|
209
215
|
end
|
210
216
|
|
211
|
-
def merge!(original_env:, override_env:, &block)
|
217
|
+
def merge!(original_env:, override_env:, self_type:, &block)
|
212
218
|
original_env.merge!(override_env) do |name, original_type, override_type|
|
213
|
-
assert_annotation name, annotated_type: override_type, original_type: original_type, &block
|
219
|
+
assert_annotation name, annotated_type: override_type, original_type: original_type, self_type: self_type, &block
|
214
220
|
end
|
215
221
|
end
|
216
222
|
|
217
|
-
def assert_annotation(name, annotated_type:, original_type:)
|
223
|
+
def assert_annotation(name, annotated_type:, original_type:, self_type:)
|
224
|
+
return annotated_type if annotated_type == original_type
|
225
|
+
|
218
226
|
annotated_type = subtyping.expand_alias(annotated_type)
|
219
227
|
original_type = subtyping.expand_alias(original_type)
|
220
228
|
|
221
229
|
relation = Subtyping::Relation.new(sub_type: annotated_type, super_type: original_type)
|
222
230
|
constraints = Subtyping::Constraints.new(unknowns: Set.new)
|
223
231
|
|
224
|
-
subtyping.check(relation, constraints: constraints).else do |result|
|
232
|
+
subtyping.check(relation, constraints: constraints, self_type: self_type).else do |result|
|
225
233
|
yield name, relation, result
|
226
234
|
end
|
227
235
|
|
data/lib/steep/version.rb
CHANGED
data/sample/Steepfile
ADDED
data/smoke/alias/a.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# @type var x: foo
|
2
2
|
x = ""
|
3
3
|
|
4
|
-
# !expects
|
4
|
+
# !expects ArgumentTypeMismatch: receiver=(::Integer | ::String), expected=::String, actual=::Integer
|
5
5
|
x + 123
|
6
6
|
|
7
|
-
# @type var y: bar
|
7
|
+
# @type var y: bar
|
8
8
|
y = x
|
9
9
|
y = []
|
10
10
|
|
data/smoke/alias/{a.rbi → a.rbs}
RENAMED
data/smoke/and/Steepfile
ADDED
data/smoke/array/a.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
# @type var a: Array
|
1
|
+
# @type var a: Array[Integer]
|
2
2
|
|
3
3
|
a = []
|
4
4
|
a[1] = 3
|
5
5
|
|
6
|
-
# !expects
|
6
|
+
# !expects* UnresolvedOverloading: receiver=::Array[::Integer], method_name=[]=,
|
7
7
|
a[2] = "foo"
|
8
8
|
|
9
9
|
# @type var i: Integer
|
data/smoke/array/b.rb
CHANGED
@@ -6,11 +6,11 @@ x = y
|
|
6
6
|
# !expects IncompatibleAssignment: lhs_type=::Integer, rhs_type=::String
|
7
7
|
y = x
|
8
8
|
|
9
|
-
# @type var a: Array
|
10
|
-
# @type var b: Array
|
9
|
+
# @type var a: Array[Integer]
|
10
|
+
# @type var b: Array[String]
|
11
11
|
|
12
12
|
a = []
|
13
|
-
# !expects IncompatibleAssignment: lhs_type=::Array
|
13
|
+
# !expects IncompatibleAssignment: lhs_type=::Array[::String], rhs_type=::Array[::Integer]
|
14
14
|
b = a
|
15
|
-
# !expects IncompatibleAssignment: lhs_type=::Array
|
15
|
+
# !expects IncompatibleAssignment: lhs_type=::Array[::Integer], rhs_type=::Array[::String]
|
16
16
|
a = b
|
data/smoke/array/c.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
# @type var x: Array
|
1
|
+
# @type var x: Array[String?]
|
2
2
|
|
3
3
|
x = ["foo"]
|
4
4
|
x = [nil]
|
5
5
|
|
6
|
-
# !expects IncompatibleAssignment: lhs_type=::Array
|
6
|
+
# !expects IncompatibleAssignment: lhs_type=::Array[(::String | nil)], rhs_type=::Array[::Integer]
|
7
7
|
x = [1]
|
data/smoke/block/{a.rbi → a.rbs}
RENAMED
data/smoke/block/{c.rbi → c.rbs}
RENAMED
File without changes
|
data/smoke/block/d.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
# @type var a: ^(Integer) -> String
|
2
2
|
a = -> (x) { x.to_s }
|
3
3
|
|
4
|
-
# @type var b: Array
|
4
|
+
# @type var b: Array[Float]
|
5
5
|
|
6
|
-
# !expects IncompatibleAssignment: lhs_type=::Array
|
6
|
+
# !expects IncompatibleAssignment: lhs_type=::Array[::Float], rhs_type=::Array[::String]
|
7
7
|
b = [1,2,3].map(&a)
|
8
8
|
|
9
|
-
# !expects IncompatibleAssignment: lhs_type=::Array
|
9
|
+
# !expects IncompatibleAssignment: lhs_type=::Array[::Float], rhs_type=::Array[::String]
|
10
10
|
b = [1,2,3].map(&:to_s)
|
11
11
|
|
12
|
-
# !expects*
|
12
|
+
# !expects* UnresolvedOverloading: receiver=::Array[::Integer], method_name=map,
|
13
13
|
[1,2,3].map(&:no_such_method)
|
14
|
-
# !expects*
|
15
|
-
[1,2,3].map(&:
|
14
|
+
# !expects* UnresolvedOverloading: receiver=::Array[::Integer], method_name=map,
|
15
|
+
[1,2,3].map(&:divmod)
|
data/smoke/case/a.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# @type var a: Integer
|
2
2
|
|
3
|
-
# !expects IncompatibleAssignment: lhs_type=::Integer, rhs_type=(::Array
|
3
|
+
# !expects IncompatibleAssignment: lhs_type=::Integer, rhs_type=(::Array[::String] | ::Integer | ::String | nil)
|
4
4
|
a = case 1
|
5
5
|
when 2
|
6
6
|
1
|
@@ -13,8 +13,9 @@ a = case 1
|
|
13
13
|
"string"
|
14
14
|
end
|
15
15
|
|
16
|
+
# !expects IncompatibleAssignment: lhs_type=::Integer, rhs_type=(::Integer | nil)
|
16
17
|
a = case
|
17
|
-
# !expects
|
18
|
+
# !expects* UnresolvedOverloading: receiver=::Integer, method_name=+,
|
18
19
|
when 1+"a"
|
19
|
-
|
20
|
+
30
|
20
21
|
end
|
data/smoke/class/a.rb
CHANGED
data/smoke/class/a.rbs
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
class A
|
2
|
+
def foo: (String) -> untyped
|
3
|
+
def bar: () -> String
|
4
|
+
def self.baz: -> Integer
|
5
|
+
end
|
6
|
+
|
7
|
+
class B
|
8
|
+
def name: -> String
|
9
|
+
end
|
10
|
+
|
11
|
+
class C
|
12
|
+
def foo: -> instance
|
13
|
+
def bar: -> instance
|
14
|
+
end
|
15
|
+
|
16
|
+
class D
|
17
|
+
def initialize: (String) -> untyped
|
18
|
+
def foo: -> untyped
|
19
|
+
end
|
20
|
+
|
21
|
+
class E
|
22
|
+
def initialize: () -> untyped
|
23
|
+
def foo: -> untyped
|
24
|
+
end
|
data/smoke/class/h.rb
CHANGED
data/smoke/class/{h.rbi → h.rbs}
RENAMED
data/smoke/class/i.rb
CHANGED
@@ -8,10 +8,9 @@ class IncompatibleChild
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def initialize()
|
11
|
-
# !expects IncompatibleArguments: receiver=::IncompatibleChild, method_type=(name: ::String) ->
|
11
|
+
# !expects IncompatibleArguments: receiver=::IncompatibleChild, method_type=(name: ::String) -> untyped
|
12
12
|
super()
|
13
13
|
|
14
|
-
# !expects IncompatibleZuper: method=initialize
|
15
14
|
super
|
16
15
|
end
|
17
16
|
end
|