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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 123376eb779b7118cfc9fb097cbd2bd028c4ce154526d5c79339902b170ad2c3
4
- data.tar.gz: b6b4c6e49b3f998103582a7c416a5f3603cb9204ab672b2c4b4f911eebc8adcb
3
+ metadata.gz: 376c287eb4edd3b191575c4dae0d6f928394ba2a52ee41ed6245c4b73579d3f0
4
+ data.tar.gz: ef83cd047a6f35f597e3709f45ee3918c0bad4944c970002827baf2ea012df76
5
5
  SHA512:
6
- metadata.gz: 0f5df26d1601a390adba84efabadd1a6947c601df83ab48fb538dea000b1cc05bb26dffd894f2c7c8c198c2c63e54972e695390de21b9580249b283e6a54d3d4
7
- data.tar.gz: c8e99c6e9247fbec030279f02891ba2aa6d2b217b7c8a61f9decc0afa308841245088785e21590858cc5e73f79827cf1515f4e9fa399ffcab18637e6851ac292
6
+ metadata.gz: 6f350dd1d6043f7389bb97ec1c6526fbc7a62aa86a9fb3b4b4f1c01241d6bd691c9fe51a5e91a242900e4c9528cc50d2ed5638b5b70e6e21645088bd6f85fffc
7
+ data.tar.gz: 3df8d10e17edeb6cad99199370f21925681f81cfebf29a471cee4087edb5a1efd13580dae0c9ddc46e2f64b3a6314d18b0a72f0299a42dd597134512fa32593f
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.4.0 (2018-06-14)
6
+
7
+ * Add *tuple* type (#40)
8
+ * Add `bool` and `nil` types (#39)
9
+ * Add *literal type* (#37)
10
+
5
11
  ## 0.3.0 (2018-05-31)
6
12
 
7
13
  * Add `interface` command to print interface built for given type
@@ -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"
@@ -33,6 +33,10 @@ module Steep
33
33
  def level
34
34
  [1]
35
35
  end
36
+
37
+ def with_location(new_location)
38
+ self.class.new(location: new_location)
39
+ end
36
40
  end
37
41
  end
38
42
  end
@@ -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
+
@@ -33,6 +33,10 @@ module Steep
33
33
  def level
34
34
  [2]
35
35
  end
36
+
37
+ def with_location(new_location)
38
+ self.class.new(location: new_location)
39
+ end
36
40
  end
37
41
  end
38
42
  end
@@ -29,6 +29,10 @@ module Steep
29
29
  def level
30
30
  [0]
31
31
  end
32
+
33
+ def with_location(new_location)
34
+ self.class.new(location: new_location)
35
+ end
32
36
  end
33
37
  end
34
38
  end
@@ -33,6 +33,10 @@ module Steep
33
33
  def level
34
34
  [0]
35
35
  end
36
+
37
+ def with_location(new_location)
38
+ self.class.new(location: new_location)
39
+ end
36
40
  end
37
41
  end
38
42
  end
@@ -68,6 +68,10 @@ module Steep
68
68
  def level
69
69
  [0] + level_of_children(types)
70
70
  end
71
+
72
+ def with_location(new_location)
73
+ self.class.new(types: types, location: new_location)
74
+ end
71
75
  end
72
76
  end
73
77
  end
@@ -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
@@ -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
+
@@ -33,6 +33,10 @@ module Steep
33
33
  def level
34
34
  [0]
35
35
  end
36
+
37
+ def with_location(new_location)
38
+ self.class.new(location: new_location)
39
+ end
36
40
  end
37
41
  end
38
42
  end
@@ -33,6 +33,10 @@ module Steep
33
33
  def level
34
34
  [2]
35
35
  end
36
+
37
+ def with_location(new_location)
38
+ self.class.new(location: new_location)
39
+ end
36
40
  end
37
41
  end
38
42
  end
@@ -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
@@ -68,6 +68,10 @@ module Steep
68
68
  def level
69
69
  [0] + level_of_children(types)
70
70
  end
71
+
72
+ def with_location(new_location)
73
+ self.class.new(types: types, location: new_location)
74
+ end
71
75
  end
72
76
  end
73
77
  end
@@ -51,6 +51,10 @@ module Steep
51
51
  def level
52
52
  [0]
53
53
  end
54
+
55
+ def with_location(new_location)
56
+ self.class.new(name: name, location: new_location)
57
+ end
54
58
  end
55
59
  end
56
60
  end
@@ -29,6 +29,10 @@ module Steep
29
29
  def free_variables
30
30
  Set.new
31
31
  end
32
+
33
+ def with_location(new_location)
34
+ self.class.new(location: new_location)
35
+ end
32
36
  end
33
37
  end
34
38
  end
@@ -213,7 +213,7 @@ module Steep
213
213
  return "any" unless node
214
214
  case node.type
215
215
  when :false, :true
216
- "_Boolean"
216
+ "bool"
217
217
  when :int
218
218
  "Integer"
219
219
  when :float
@@ -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 &&