steep 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/steep.rb +4 -0
- data/lib/steep/ast/types/any.rb +4 -0
- data/lib/steep/ast/types/boolean.rb +53 -0
- data/lib/steep/ast/types/bot.rb +4 -0
- data/lib/steep/ast/types/class.rb +4 -0
- data/lib/steep/ast/types/instance.rb +4 -0
- data/lib/steep/ast/types/intersection.rb +4 -0
- data/lib/steep/ast/types/literal.rb +59 -0
- data/lib/steep/ast/types/name.rb +4 -0
- data/lib/steep/ast/types/nil.rb +48 -0
- data/lib/steep/ast/types/self.rb +4 -0
- data/lib/steep/ast/types/top.rb +4 -0
- data/lib/steep/ast/types/tuple.rb +51 -0
- data/lib/steep/ast/types/union.rb +4 -0
- data/lib/steep/ast/types/var.rb +4 -0
- data/lib/steep/ast/types/void.rb +4 -0
- data/lib/steep/drivers/scaffold.rb +1 -1
- data/lib/steep/errors.rb +15 -0
- data/lib/steep/interface/builder.rb +5 -0
- data/lib/steep/interface/method.rb +10 -0
- data/lib/steep/parser.y +81 -39
- data/lib/steep/subtyping/check.rb +78 -0
- data/lib/steep/type_construction.rb +325 -195
- data/lib/steep/type_inference/type_env.rb +1 -1
- data/lib/steep/typing.rb +34 -19
- data/lib/steep/version.rb +1 -1
- data/smoke/and/a.rb +2 -2
- data/smoke/case/a.rb +1 -1
- data/smoke/literal/a.rb +2 -2
- data/stdlib/builtin.rbi +86 -84
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 376c287eb4edd3b191575c4dae0d6f928394ba2a52ee41ed6245c4b73579d3f0
|
4
|
+
data.tar.gz: ef83cd047a6f35f597e3709f45ee3918c0bad4944c970002827baf2ea012df76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f350dd1d6043f7389bb97ec1c6526fbc7a62aa86a9fb3b4b4f1c01241d6bd691c9fe51a5e91a242900e4c9528cc50d2ed5638b5b70e6e21645088bd6f85fffc
|
7
|
+
data.tar.gz: 3df8d10e17edeb6cad99199370f21925681f81cfebf29a471cee4087edb5a1efd13580dae0c9ddc46e2f64b3a6314d18b0a72f0299a42dd597134512fa32593f
|
data/CHANGELOG.md
CHANGED
data/lib/steep.rb
CHANGED
@@ -21,6 +21,10 @@ require "steep/ast/types/intersection"
|
|
21
21
|
require "steep/ast/types/void"
|
22
22
|
require "steep/ast/types/bot"
|
23
23
|
require "steep/ast/types/top"
|
24
|
+
require "steep/ast/types/nil"
|
25
|
+
require "steep/ast/types/literal"
|
26
|
+
require "steep/ast/types/boolean"
|
27
|
+
require "steep/ast/types/tuple"
|
24
28
|
require "steep/ast/method_type"
|
25
29
|
require "steep/ast/type_params"
|
26
30
|
require "steep/ast/signature/class"
|
data/lib/steep/ast/types/any.rb
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
module Steep
|
2
|
+
module AST
|
3
|
+
module Types
|
4
|
+
class Boolean
|
5
|
+
attr_reader :location
|
6
|
+
|
7
|
+
def initialize(location: nil)
|
8
|
+
@location = location
|
9
|
+
end
|
10
|
+
|
11
|
+
def ==(other)
|
12
|
+
other.is_a?(Boolean)
|
13
|
+
end
|
14
|
+
|
15
|
+
def hash
|
16
|
+
self.class.hash
|
17
|
+
end
|
18
|
+
|
19
|
+
alias eql? ==
|
20
|
+
|
21
|
+
def subst(s)
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_s
|
26
|
+
"bool"
|
27
|
+
end
|
28
|
+
|
29
|
+
def free_variables
|
30
|
+
Set.new
|
31
|
+
end
|
32
|
+
|
33
|
+
def level
|
34
|
+
[0]
|
35
|
+
end
|
36
|
+
|
37
|
+
def with_location(new_location)
|
38
|
+
self.class.new(location: new_location)
|
39
|
+
end
|
40
|
+
|
41
|
+
def back_type
|
42
|
+
Union.build(types:
|
43
|
+
[
|
44
|
+
Name.new_instance(name: "::TrueClass", location: location),
|
45
|
+
Name.new_instance(name: "::FalseClass", location: location)
|
46
|
+
],
|
47
|
+
location: location)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
data/lib/steep/ast/types/bot.rb
CHANGED
@@ -0,0 +1,59 @@
|
|
1
|
+
module Steep
|
2
|
+
module AST
|
3
|
+
module Types
|
4
|
+
class Literal
|
5
|
+
attr_reader :location
|
6
|
+
attr_reader :value
|
7
|
+
|
8
|
+
def initialize(value:, location: nil)
|
9
|
+
@location = location
|
10
|
+
@value = value
|
11
|
+
end
|
12
|
+
|
13
|
+
def ==(other)
|
14
|
+
other.is_a?(Literal) &&
|
15
|
+
other.value == value
|
16
|
+
end
|
17
|
+
|
18
|
+
def hash
|
19
|
+
self.class.hash
|
20
|
+
end
|
21
|
+
|
22
|
+
alias eql? ==
|
23
|
+
|
24
|
+
def subst(s)
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_s
|
29
|
+
value.inspect
|
30
|
+
end
|
31
|
+
|
32
|
+
def free_variables
|
33
|
+
Set.new
|
34
|
+
end
|
35
|
+
|
36
|
+
def level
|
37
|
+
[0]
|
38
|
+
end
|
39
|
+
|
40
|
+
def with_location(new_location)
|
41
|
+
self.class.new(location: new_location)
|
42
|
+
end
|
43
|
+
|
44
|
+
def back_type
|
45
|
+
case value
|
46
|
+
when Integer
|
47
|
+
Name.new_instance(name: "::Integer")
|
48
|
+
when String
|
49
|
+
Name.new_instance(name: "::String")
|
50
|
+
when Symbol
|
51
|
+
Name.new_instance(name: "::Symbol")
|
52
|
+
else
|
53
|
+
raise "Unexpected literal type: #{value.inspect}"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/steep/ast/types/name.rb
CHANGED
@@ -32,6 +32,10 @@ module Steep
|
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
|
+
def with_location(new_location)
|
36
|
+
self.class.new(name: name, args: args, location: new_location)
|
37
|
+
end
|
38
|
+
|
35
39
|
def self.new_module(location: nil, name:, args: [])
|
36
40
|
name = ModuleName.parse(name) unless name.is_a?(ModuleName)
|
37
41
|
new(location: location,
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module Steep
|
2
|
+
module AST
|
3
|
+
module Types
|
4
|
+
class Nil
|
5
|
+
attr_reader :location
|
6
|
+
|
7
|
+
def initialize(location: nil)
|
8
|
+
@location = location
|
9
|
+
end
|
10
|
+
|
11
|
+
def ==(other)
|
12
|
+
other.is_a?(Nil)
|
13
|
+
end
|
14
|
+
|
15
|
+
def hash
|
16
|
+
self.class.hash
|
17
|
+
end
|
18
|
+
|
19
|
+
alias eql? ==
|
20
|
+
|
21
|
+
def subst(s)
|
22
|
+
self
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_s
|
26
|
+
"nil"
|
27
|
+
end
|
28
|
+
|
29
|
+
def free_variables
|
30
|
+
Set.new
|
31
|
+
end
|
32
|
+
|
33
|
+
def level
|
34
|
+
[0]
|
35
|
+
end
|
36
|
+
|
37
|
+
def with_location(new_location)
|
38
|
+
self.class.new(location: new_location)
|
39
|
+
end
|
40
|
+
|
41
|
+
def back_type
|
42
|
+
Name.new_instance(name: "::NilClass", location: location)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
data/lib/steep/ast/types/self.rb
CHANGED
data/lib/steep/ast/types/top.rb
CHANGED
@@ -0,0 +1,51 @@
|
|
1
|
+
module Steep
|
2
|
+
module AST
|
3
|
+
module Types
|
4
|
+
class Tuple
|
5
|
+
attr_reader :types
|
6
|
+
attr_reader :location
|
7
|
+
|
8
|
+
def initialize(types:, location: nil)
|
9
|
+
@types = types
|
10
|
+
@location = location
|
11
|
+
end
|
12
|
+
|
13
|
+
def ==(other)
|
14
|
+
other.is_a?(Tuple) &&
|
15
|
+
other.types == types
|
16
|
+
end
|
17
|
+
|
18
|
+
def hash
|
19
|
+
self.class.hash ^ types.hash
|
20
|
+
end
|
21
|
+
|
22
|
+
alias eql? ==
|
23
|
+
|
24
|
+
def subst(s)
|
25
|
+
self.class.new(location: location,
|
26
|
+
types: types.map {|ty| ty.subst(s) })
|
27
|
+
end
|
28
|
+
|
29
|
+
def to_s
|
30
|
+
"[#{types.join(", ")}]"
|
31
|
+
end
|
32
|
+
|
33
|
+
def free_variables
|
34
|
+
types.each.with_object(Set.new) do |type, set|
|
35
|
+
set.merge(type.free_variables)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
include Helper::ChildrenLevel
|
40
|
+
|
41
|
+
def level
|
42
|
+
[0] + level_of_children(types)
|
43
|
+
end
|
44
|
+
|
45
|
+
def with_location(new_location)
|
46
|
+
self.class.new(types: types, location: new_location)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/steep/ast/types/var.rb
CHANGED
data/lib/steep/ast/types/void.rb
CHANGED
data/lib/steep/errors.rb
CHANGED
@@ -475,5 +475,20 @@ module Steep
|
|
475
475
|
"#{location_to_str}: UnexpectedSplat: type=#{type}"
|
476
476
|
end
|
477
477
|
end
|
478
|
+
|
479
|
+
class IncompatibleTuple < Base
|
480
|
+
attr_reader :expected_tuple
|
481
|
+
include ResultPrinter
|
482
|
+
|
483
|
+
def initialize(node:, expected_tuple:, result:)
|
484
|
+
super(node: node)
|
485
|
+
@result = result
|
486
|
+
@expected_tuple = expected_tuple
|
487
|
+
end
|
488
|
+
|
489
|
+
def to_s
|
490
|
+
"#{location_to_str}: IncompatibleTuple: expected_tuple=#{expected_tuple}"
|
491
|
+
end
|
492
|
+
end
|
478
493
|
end
|
479
494
|
end
|
@@ -68,6 +68,11 @@ module Steep
|
|
68
68
|
types: type.types.map {|ty| absolute_type(ty, current: current) },
|
69
69
|
location: type.location
|
70
70
|
)
|
71
|
+
when AST::Types::Tuple
|
72
|
+
AST::Types::Tuple.new(
|
73
|
+
types: type.types.map {|ty| absolute_type(ty, current:current) },
|
74
|
+
location: type.location
|
75
|
+
)
|
71
76
|
else
|
72
77
|
type
|
73
78
|
end
|
@@ -48,6 +48,16 @@ module Steep
|
|
48
48
|
)
|
49
49
|
end
|
50
50
|
|
51
|
+
def with_types(types)
|
52
|
+
self.class.new(
|
53
|
+
type_name: type_name,
|
54
|
+
name: name,
|
55
|
+
types: types,
|
56
|
+
super_method: super_method,
|
57
|
+
attributes: attributes
|
58
|
+
)
|
59
|
+
end
|
60
|
+
|
51
61
|
def include_in_chain?(method)
|
52
62
|
(method.type_name == type_name &&
|
53
63
|
method.name == name &&
|