steep 0.1.0.pre2 → 0.1.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.
Files changed (119) hide show
  1. checksums.yaml +5 -5
  2. data/.travis.yml +1 -1
  3. data/README.md +146 -33
  4. data/bin/smoke_runner.rb +43 -10
  5. data/lib/steep/ast/annotation/collection.rb +93 -0
  6. data/lib/steep/ast/annotation.rb +131 -0
  7. data/lib/steep/ast/buffer.rb +47 -0
  8. data/lib/steep/ast/location.rb +82 -0
  9. data/lib/steep/ast/method_type.rb +116 -0
  10. data/lib/steep/ast/signature/class.rb +33 -0
  11. data/lib/steep/ast/signature/const.rb +17 -0
  12. data/lib/steep/ast/signature/env.rb +123 -0
  13. data/lib/steep/ast/signature/extension.rb +21 -0
  14. data/lib/steep/ast/signature/gvar.rb +17 -0
  15. data/lib/steep/ast/signature/interface.rb +31 -0
  16. data/lib/steep/ast/signature/members.rb +71 -0
  17. data/lib/steep/ast/signature/module.rb +21 -0
  18. data/lib/steep/ast/type_params.rb +13 -0
  19. data/lib/steep/ast/types/any.rb +39 -0
  20. data/lib/steep/ast/types/bot.rb +39 -0
  21. data/lib/steep/ast/types/class.rb +35 -0
  22. data/lib/steep/ast/types/helper.rb +21 -0
  23. data/lib/steep/ast/types/instance.rb +39 -0
  24. data/lib/steep/ast/types/intersection.rb +74 -0
  25. data/lib/steep/ast/types/name.rb +124 -0
  26. data/lib/steep/ast/types/self.rb +39 -0
  27. data/lib/steep/ast/types/top.rb +39 -0
  28. data/lib/steep/ast/types/union.rb +74 -0
  29. data/lib/steep/ast/types/var.rb +57 -0
  30. data/lib/steep/ast/types/void.rb +35 -0
  31. data/lib/steep/cli.rb +28 -1
  32. data/lib/steep/drivers/annotations.rb +32 -0
  33. data/lib/steep/drivers/check.rb +53 -77
  34. data/lib/steep/drivers/scaffold.rb +303 -0
  35. data/lib/steep/drivers/utils/each_signature.rb +66 -0
  36. data/lib/steep/drivers/utils/validator.rb +115 -0
  37. data/lib/steep/drivers/validate.rb +39 -0
  38. data/lib/steep/errors.rb +291 -19
  39. data/lib/steep/interface/abstract.rb +44 -0
  40. data/lib/steep/interface/builder.rb +470 -0
  41. data/lib/steep/interface/instantiated.rb +126 -0
  42. data/lib/steep/interface/ivar_chain.rb +26 -0
  43. data/lib/steep/interface/method.rb +60 -0
  44. data/lib/steep/{interface.rb → interface/method_type.rb} +111 -100
  45. data/lib/steep/interface/substitution.rb +65 -0
  46. data/lib/steep/module_name.rb +116 -0
  47. data/lib/steep/parser.rb +1314 -814
  48. data/lib/steep/parser.y +536 -175
  49. data/lib/steep/source.rb +220 -25
  50. data/lib/steep/subtyping/check.rb +673 -0
  51. data/lib/steep/subtyping/constraints.rb +275 -0
  52. data/lib/steep/subtyping/relation.rb +41 -0
  53. data/lib/steep/subtyping/result.rb +126 -0
  54. data/lib/steep/subtyping/trace.rb +48 -0
  55. data/lib/steep/subtyping/variable_occurrence.rb +49 -0
  56. data/lib/steep/subtyping/variable_variance.rb +69 -0
  57. data/lib/steep/type_construction.rb +1630 -524
  58. data/lib/steep/type_inference/block_params.rb +100 -0
  59. data/lib/steep/type_inference/constant_env.rb +55 -0
  60. data/lib/steep/type_inference/send_args.rb +222 -0
  61. data/lib/steep/type_inference/type_env.rb +226 -0
  62. data/lib/steep/type_name.rb +27 -7
  63. data/lib/steep/typing.rb +4 -0
  64. data/lib/steep/version.rb +1 -1
  65. data/lib/steep.rb +71 -16
  66. data/smoke/and/a.rb +4 -2
  67. data/smoke/array/a.rb +4 -5
  68. data/smoke/array/b.rb +4 -4
  69. data/smoke/block/a.rb +2 -2
  70. data/smoke/block/a.rbi +2 -0
  71. data/smoke/block/b.rb +15 -0
  72. data/smoke/case/a.rb +3 -3
  73. data/smoke/class/a.rb +3 -3
  74. data/smoke/class/b.rb +0 -2
  75. data/smoke/class/d.rb +2 -2
  76. data/smoke/class/e.rb +1 -1
  77. data/smoke/class/f.rb +2 -2
  78. data/smoke/class/g.rb +8 -0
  79. data/smoke/const/a.rb +3 -3
  80. data/smoke/dstr/a.rb +1 -1
  81. data/smoke/ensure/a.rb +22 -0
  82. data/smoke/enumerator/a.rb +6 -6
  83. data/smoke/enumerator/b.rb +22 -0
  84. data/smoke/extension/a.rb +2 -2
  85. data/smoke/extension/b.rb +3 -3
  86. data/smoke/extension/c.rb +1 -1
  87. data/smoke/hello/hello.rb +2 -2
  88. data/smoke/if/a.rb +4 -2
  89. data/smoke/kwbegin/a.rb +8 -0
  90. data/smoke/literal/a.rb +5 -5
  91. data/smoke/method/a.rb +5 -5
  92. data/smoke/method/a.rbi +4 -0
  93. data/smoke/method/b.rb +29 -0
  94. data/smoke/module/a.rb +3 -3
  95. data/smoke/module/a.rbi +9 -0
  96. data/smoke/module/b.rb +2 -2
  97. data/smoke/module/c.rb +1 -1
  98. data/smoke/module/d.rb +5 -0
  99. data/smoke/module/e.rb +13 -0
  100. data/smoke/module/f.rb +13 -0
  101. data/smoke/rescue/a.rb +62 -0
  102. data/smoke/super/a.rb +2 -2
  103. data/smoke/type_case/a.rb +35 -0
  104. data/smoke/yield/a.rb +2 -2
  105. data/stdlib/builtin.rbi +463 -24
  106. data/steep.gemspec +3 -2
  107. metadata +91 -29
  108. data/lib/steep/annotation.rb +0 -223
  109. data/lib/steep/signature/class.rb +0 -450
  110. data/lib/steep/signature/extension.rb +0 -51
  111. data/lib/steep/signature/interface.rb +0 -49
  112. data/lib/steep/types/any.rb +0 -31
  113. data/lib/steep/types/class.rb +0 -27
  114. data/lib/steep/types/instance.rb +0 -27
  115. data/lib/steep/types/merge.rb +0 -32
  116. data/lib/steep/types/name.rb +0 -57
  117. data/lib/steep/types/union.rb +0 -42
  118. data/lib/steep/types/var.rb +0 -38
  119. data/lib/steep/types.rb +0 -4
data/lib/steep.rb CHANGED
@@ -1,33 +1,88 @@
1
1
  require "steep/version"
2
2
 
3
3
  require "pathname"
4
- require "parser/current"
5
4
  require "ast_utils"
5
+ require "active_support/core_ext/object/try"
6
+ require "logger"
7
+ require "active_support/tagged_logging"
8
+ require "rainbow"
9
+
10
+ require "steep/module_name"
11
+ require "steep/ast/location"
12
+ require "steep/ast/types/helper"
13
+ require "steep/ast/types/any"
14
+ require "steep/ast/types/instance"
15
+ require "steep/ast/types/class"
16
+ require "steep/ast/types/union"
17
+ require "steep/ast/types/var"
18
+ require "steep/ast/types/name"
19
+ require "steep/ast/types/self"
20
+ require "steep/ast/types/intersection"
21
+ require "steep/ast/types/void"
22
+ require "steep/ast/types/bot"
23
+ require "steep/ast/types/top"
24
+ require "steep/ast/method_type"
25
+ require "steep/ast/type_params"
26
+ require "steep/ast/signature/class"
27
+ require "steep/ast/signature/module"
28
+ require "steep/ast/signature/members"
29
+ require "steep/ast/signature/extension"
30
+ require "steep/ast/signature/interface"
31
+ require "steep/ast/signature/env"
32
+ require "steep/ast/signature/const"
33
+ require "steep/ast/signature/gvar"
34
+ require "steep/ast/annotation"
35
+ require "steep/ast/annotation/collection"
36
+ require "steep/ast/buffer"
6
37
 
7
- require "steep/types"
8
38
  require "steep/type_name"
9
- require "steep/interface"
10
- require "steep/signature/class"
11
- require "steep/signature/interface"
39
+
40
+ require "steep/interface/method_type"
41
+ require "steep/interface/method"
42
+ require "steep/interface/builder"
43
+ require "steep/interface/substitution"
44
+ require "steep/interface/abstract"
45
+ require "steep/interface/instantiated"
46
+ require "steep/interface/ivar_chain"
47
+
48
+ require "steep/subtyping/check"
49
+ require "steep/subtyping/result"
50
+ require "steep/subtyping/relation"
51
+ require "steep/subtyping/trace"
52
+ require "steep/subtyping/constraints"
53
+ require "steep/subtyping/variable_variance"
54
+ require "steep/subtyping/variable_occurrence"
55
+
12
56
  require "steep/signature/errors"
13
- require "steep/signature/extension"
14
- require "steep/types/any"
15
- require "steep/types/name"
16
- require "steep/types/var"
17
- require "steep/types/union"
18
- require "steep/types/class"
19
- require "steep/types/instance"
20
- require "steep/types/merge"
21
- require "steep/type_assignability"
22
57
  require "steep/parser"
23
- require "steep/annotation"
24
58
  require "steep/source"
25
59
  require "steep/typing"
26
60
  require "steep/errors"
27
61
  require "steep/type_construction"
62
+ require "steep/type_inference/send_args"
63
+ require "steep/type_inference/block_params"
64
+ require "steep/type_inference/constant_env"
65
+ require "steep/type_inference/type_env"
28
66
 
67
+ require "steep/drivers/utils/validator"
68
+ require "steep/drivers/utils/each_signature"
29
69
  require "steep/drivers/check"
70
+ require "steep/drivers/validate"
71
+ require "steep/drivers/annotations"
72
+ require "steep/drivers/scaffold"
73
+
74
+ if ENV["NO_COLOR"]
75
+ Rainbow.enabled = false
76
+ end
30
77
 
31
78
  module Steep
32
- # Your code goes here...
79
+ def self.logger
80
+ unless @logger
81
+ @logger = ActiveSupport::TaggedLogging.new(Logger.new(STDERR))
82
+ @logger.push_tags "Steep #{VERSION}"
83
+ @logger.level = Logger::ERROR
84
+ end
85
+
86
+ @logger
87
+ end
33
88
  end
data/smoke/and/a.rb CHANGED
@@ -1,9 +1,11 @@
1
1
  # @type var b: String
2
- # @type var c: Integer
2
+ # @type var c: ::Integer
3
3
 
4
4
  a = "foo"
5
5
 
6
+ # !expects IncompatibleAssignment: lhs_type=::String, rhs_type=(::NilClass | ::String)
6
7
  b = a && a.to_str
7
8
 
8
- # !expects IncompatibleAssignment: lhs_type=Integer, rhs_type=String
9
+ # !expects IncompatibleAssignment: lhs_type=::Integer, rhs_type=(::NilClass | ::String)
9
10
  c = a && a.to_str
11
+
data/smoke/array/a.rb CHANGED
@@ -3,20 +3,19 @@
3
3
  a = []
4
4
  a[1] = 3
5
5
 
6
- # !expects ArgumentTypeMismatch: type=Array<Integer>, method=[]=
6
+ # !expects ArgumentTypeMismatch: receiver=::Array<::Integer>, expected=::Integer, actual=::String
7
7
  a[2] = "foo"
8
8
 
9
9
  # @type var i: Integer
10
- # @type var s: String
11
-
12
10
  i = a[0]
13
11
 
14
- # !expects IncompatibleAssignment: lhs_type=String, rhs_type=Integer
12
+ # @type var s: String
13
+ # !expects IncompatibleAssignment: lhs_type=::String, rhs_type=::Integer
15
14
  s = a[1]
16
15
 
17
16
 
18
17
  b = ["a", "b", "c"]
19
18
 
20
19
  s = b[0]
21
- # !expects IncompatibleAssignment: lhs_type=Integer, rhs_type=String
20
+ # !expects IncompatibleAssignment: lhs_type=::Integer, rhs_type=::String
22
21
  i = b[1]
data/smoke/array/b.rb CHANGED
@@ -1,16 +1,16 @@
1
1
  x = ""
2
2
  y = 1
3
3
 
4
- # !expects IncompatibleAssignment: lhs_type=String, rhs_type=Integer
4
+ # !expects IncompatibleAssignment: lhs_type=::String, rhs_type=::Integer
5
5
  x = y
6
- # !expects IncompatibleAssignment: lhs_type=Integer, rhs_type=String
6
+ # !expects IncompatibleAssignment: lhs_type=::Integer, rhs_type=::String
7
7
  y = x
8
8
 
9
9
  # @type var a: Array<Integer>
10
10
  # @type var b: Array<String>
11
11
 
12
12
  a = []
13
- # !expects IncompatibleAssignment: lhs_type=Array<String>, rhs_type=Array<Integer>
13
+ # !expects IncompatibleAssignment: lhs_type=::Array<::String>, rhs_type=::Array<::Integer>
14
14
  b = a
15
- # !expects IncompatibleAssignment: lhs_type=Array<Integer>, rhs_type=Array<String>
15
+ # !expects IncompatibleAssignment: lhs_type=::Array<::Integer>, rhs_type=::Array<::String>
16
16
  a = b
data/smoke/block/a.rb CHANGED
@@ -5,8 +5,8 @@ a = A.new
5
5
  # @type var i: Integer
6
6
  # @type var s: String
7
7
 
8
- # !expects IncompatibleAssignment: lhs_type=String, rhs_type=Integer
8
+ # !expects IncompatibleAssignment: lhs_type=::String, rhs_type=::Integer
9
9
  s = a.foo
10
10
 
11
- # !expects IncompatibleAssignment: lhs_type=Integer, rhs_type=String
11
+ # !expects IncompatibleAssignment: lhs_type=::Integer, rhs_type=::String
12
12
  i = a.foo { nil }
data/smoke/block/a.rbi CHANGED
@@ -1,4 +1,6 @@
1
1
  class A
2
2
  def foo: { (String) -> any } -> String
3
3
  | -> Integer
4
+
5
+ def bar: { (String) -> Integer } -> Symbol
4
6
  end
data/smoke/block/b.rb ADDED
@@ -0,0 +1,15 @@
1
+ # @type var a: A
2
+ a = (_ = nil)
3
+
4
+ a.bar do |x|
5
+ # !expects BreakTypeMismatch: expected=::Symbol, actual=::Integer
6
+ break 3
7
+ end
8
+
9
+ # @type var s: ::String
10
+
11
+ # !expects IncompatibleAssignment: lhs_type=::String, rhs_type=(::Integer | ::Symbol)
12
+ s = a.bar do |x|
13
+ # @type break: ::Integer
14
+ break 3
15
+ end
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=Integer | Array<String> | String
3
+ # !expects IncompatibleAssignment: lhs_type=::Integer, rhs_type=(::Array<::String> | ::Integer | ::NilClass | ::String)
4
4
  a = case 1
5
5
  when 2
6
6
  1
@@ -14,7 +14,7 @@ a = case 1
14
14
  end
15
15
 
16
16
  a = case
17
- # !expects ArgumentTypeMismatch: type=Integer, method=+
17
+ # !expects ArgumentTypeMismatch: receiver=::Integer, expected=::Integer, actual=::String
18
18
  when 1+"a"
19
- nil
19
+ (_ = nil)
20
20
  end
data/smoke/class/a.rb CHANGED
@@ -8,13 +8,13 @@ class A
8
8
  end
9
9
 
10
10
  # A#bar is defined but the implementation is incompatible.
11
- # !expects MethodParameterTypeMismatch: method=bar
11
+ # !expects MethodArityMismatch: method=bar
12
12
  def bar(y)
13
13
  y
14
14
  end
15
15
 
16
16
  # Object#to_s is defined but the implementation is incompatible.
17
- # !expects MethodBodyTypeMismatch: method=to_s, expected=String, actual=Integer
17
+ # !expects MethodBodyTypeMismatch: method=to_s, expected=::String, actual=::Integer
18
18
  def to_s
19
19
  3
20
20
  end
@@ -24,7 +24,7 @@ class A
24
24
  5
25
25
  end
26
26
 
27
- # !expects MethodBodyTypeMismatch: method=self.baz, expected=Integer, actual=String
27
+ # !expects MethodBodyTypeMismatch: method=self.baz, expected=::Integer, actual=::String
28
28
  def self.baz
29
29
  "baz"
30
30
  end
data/smoke/class/b.rb CHANGED
@@ -2,6 +2,4 @@
2
2
  # @var type a: Integer
3
3
 
4
4
  s = "".class.allocate
5
-
6
- # !expects IncompatibleAssignment: lhs_type=String, rhs_type=Integer
7
5
  s = 3.class.allocate
data/smoke/class/d.rb CHANGED
@@ -2,8 +2,8 @@
2
2
  # @type const B: A.class constructor
3
3
  # @type const C: A.class noconstructor
4
4
 
5
- # !expects NoMethodError: type=A.module, method=new
5
+ # !expects NoMethodError: type=::A.class, method=new
6
6
  a = A.new
7
7
  b = B.new
8
- # !expects NoMethodError: type=A.module noconstructor, method=new
8
+ # !expects NoMethodError: type=::A.class noconstructor, method=new
9
9
  c = C.new
data/smoke/class/e.rb CHANGED
@@ -6,7 +6,7 @@ class C
6
6
  end
7
7
 
8
8
  def bar
9
- # !expects NoMethodError: type=C.module noconstructor, method=new
9
+ # !expects NoMethodError: type=C.class noconstructor, method=new
10
10
  self.class.new
11
11
  end
12
12
  end
data/smoke/class/f.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # @type var e: E
2
2
  # @type var d: D
3
3
 
4
- e = nil
5
- d = nil
4
+ e = (_ = nil)
5
+ d = (_ = nil)
6
6
 
7
7
  e = d
8
8
  d = e
data/smoke/class/g.rb ADDED
@@ -0,0 +1,8 @@
1
+ # !expects MethodDefinitionMissing: module=::B, method=name
2
+ class B
3
+ end
4
+
5
+ # !expects MethodDefinitionMissing: module=::B, method=name
6
+ class C
7
+ # @implements ::B
8
+ end
data/smoke/const/a.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # @type const A: Integer
2
2
  # @type var x: String
3
3
 
4
- # !expects IncompatibleAssignment: lhs_type=String, rhs_type=Integer
4
+ # !expects IncompatibleAssignment: lhs_type=::String, rhs_type=::Integer
5
5
  x = A
6
6
 
7
7
  x = B
@@ -12,7 +12,7 @@ module X
12
12
  def foo
13
13
  # @type var x: String
14
14
 
15
- # !expects IncompatibleAssignment: lhs_type=String, rhs_type=Integer
15
+ # !expects IncompatibleAssignment: lhs_type=::String, rhs_type=::Integer
16
16
  x = A
17
17
 
18
18
  x = B
@@ -22,7 +22,7 @@ end
22
22
 
23
23
  # @type const Foo::Bar::Baz: Integer
24
24
 
25
- # !expects IncompatibleAssignment: lhs_type=String, rhs_type=Integer
25
+ # !expects IncompatibleAssignment: lhs_type=::String, rhs_type=::Integer
26
26
  x = Foo::Bar::Baz
27
27
 
28
28
  z = Foo
data/smoke/dstr/a.rb CHANGED
@@ -2,5 +2,5 @@
2
2
 
3
3
  a = 0
4
4
 
5
- # !expects NoMethodError: type=Integer, method=foo
5
+ # !expects NoMethodError: type=::Integer, method=foo
6
6
  b = "Hello #{a.foo} world!"
data/smoke/ensure/a.rb ADDED
@@ -0,0 +1,22 @@
1
+ # @type var a: Integer
2
+ # @type var b: Integer
3
+
4
+ # !expects IncompatibleAssignment: lhs_type=::Integer, rhs_type=::String
5
+ a = begin
6
+ 'foo'
7
+ ensure
8
+ # !expects IncompatibleAssignment: lhs_type=::Integer, rhs_type=::Symbol
9
+ b = :foo
10
+ 1
11
+ end
12
+
13
+ # @type method foo: (String) -> String
14
+
15
+ # !expects MethodBodyTypeMismatch: method=foo, expected=::String, actual=::Integer
16
+ def foo(a)
17
+ 10
18
+ ensure
19
+ # !expects ArgumentTypeMismatch: receiver=::Integer, expected=::Integer, actual=::String
20
+ 1 + '1'
21
+ a
22
+ end
@@ -2,18 +2,18 @@
2
2
 
3
3
  a = [1]
4
4
 
5
- # !expects IncompatibleAssignment: lhs_type=Hash<Symbol, String>, rhs_type=String
5
+ # !expects IncompatibleAssignment: lhs_type=::Hash<::Symbol, ::String>, rhs_type=::String
6
6
  hash = a.each.with_object("") do |x, y|
7
- # !expects IncompatibleAssignment: lhs_type=Hash<Symbol, String>, rhs_type=Integer
7
+ # !expects IncompatibleAssignment: lhs_type=::Hash<::Symbol, ::String>, rhs_type=::Integer
8
8
  hash = x
9
- # !expects IncompatibleAssignment: lhs_type=Hash<Symbol, String>, rhs_type=String
9
+ # !expects IncompatibleAssignment: lhs_type=::Hash<::Symbol, ::String>, rhs_type=::String
10
10
  hash = y
11
11
  end
12
12
 
13
- # !expects IncompatibleAssignment: lhs_type=Hash<Symbol, String>, rhs_type=Array<Integer>
13
+ # !expects IncompatibleAssignment: lhs_type=::Hash<::Symbol, ::String>, rhs_type=::Array<::Integer>
14
14
  hash = a.each.with_index do |x, y|
15
- # !expects IncompatibleAssignment: lhs_type=Hash<Symbol, String>, rhs_type=Integer
15
+ # !expects IncompatibleAssignment: lhs_type=::Hash<::Symbol, ::String>, rhs_type=::Integer
16
16
  hash = x
17
- # !expects IncompatibleAssignment: lhs_type=Hash<Symbol, String>, rhs_type=Integer
17
+ # !expects IncompatibleAssignment: lhs_type=::Hash<::Symbol, ::String>, rhs_type=::Integer
18
18
  hash = y
19
19
  end
@@ -0,0 +1,22 @@
1
+ # @type var b: Array<String>
2
+ # @type var c: Array<Integer>
3
+
4
+ a = [1]
5
+
6
+ # !expects* UnsatisfiableConstraint:
7
+ b = a.each.with_object([]) do |i, xs|
8
+ # @type var xs: String
9
+ xs << i.to_s
10
+ end
11
+
12
+ # !expects IncompatibleAssignment: lhs_type=::Array<::Integer>, rhs_type=::Array<::String>
13
+ c = a.each.with_object([]) do |i, xs|
14
+ # @type var xs: Array<String>
15
+ xs << i.to_s
16
+ end
17
+
18
+ # @type var d: String
19
+ # !expects IncompatibleAssignment: lhs_type=::String, rhs_type=::Array<any>
20
+ d = a.each.with_object([]) do |i, xs|
21
+ xs << i.to_s
22
+ end
data/smoke/extension/a.rb CHANGED
@@ -1,11 +1,11 @@
1
1
  # @type var foo: Foo
2
2
 
3
- foo = nil
3
+ foo = (_ = nil)
4
4
 
5
5
  foo.try do |x|
6
6
  # @type var string: String
7
7
 
8
- # !expects IncompatibleAssignment: lhs_type=String, rhs_type=Foo
8
+ # !expects IncompatibleAssignment: lhs_type=::String, rhs_type=::Foo
9
9
  string = x
10
10
  end
11
11
 
data/smoke/extension/b.rb CHANGED
@@ -1,12 +1,12 @@
1
1
  # @type var foo: Foo
2
- foo = nil
2
+ foo = (_ = nil)
3
3
 
4
4
  # @type var integer: Integer
5
5
 
6
6
  # Foo#f returns String because overridden
7
- # !expects IncompatibleAssignment: lhs_type=Integer, rhs_type=String
7
+ # !expects IncompatibleAssignment: lhs_type=::Integer, rhs_type=::String
8
8
  integer = foo.f()
9
9
 
10
10
  # String#f returns Object because Object(X)#f is used
11
- # !expects IncompatibleAssignment: lhs_type=Integer, rhs_type=Object
11
+ # !expects IncompatibleAssignment: lhs_type=::Integer, rhs_type=::Object
12
12
  integer = "".f()
data/smoke/extension/c.rb CHANGED
@@ -3,7 +3,7 @@ class Foo
3
3
 
4
4
  def f()
5
5
  # @type var string: String
6
- # !expects IncompatibleAssignment: lhs_type=String, rhs_type=Object
6
+ # !expects IncompatibleAssignment: lhs_type=::String, rhs_type=::Object
7
7
  string = super()
8
8
  end
9
9
  end
data/smoke/hello/hello.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  # @type var x: _Foo
2
2
  # @type var y: _Bar
3
3
 
4
- x = nil
5
- y = nil
4
+ x = (_ = nil)
5
+ y = (_ = nil)
6
6
 
7
7
  a = x.foo
8
8
 
data/smoke/if/a.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  # @type var a: String
2
2
 
3
- # !expects IncompatibleAssignment: lhs_type=String, rhs_type=Symbol
3
+ x = y = z = (_ = nil)
4
+
5
+ # !expects IncompatibleAssignment: lhs_type=::String, rhs_type=::Symbol
4
6
  a = if x
5
7
  :foo
6
8
  end
@@ -11,7 +13,7 @@ else
11
13
  "baz"
12
14
  end
13
15
 
14
- # !expects IncompatibleAssignment: lhs_type=String, rhs_type=String | Integer
16
+ # !expects IncompatibleAssignment: lhs_type=::String, rhs_type=(::Integer | ::String)
15
17
  a = if z
16
18
  "foofoo"
17
19
  else
@@ -0,0 +1,8 @@
1
+ # @type var a: Integer
2
+
3
+ # !expects IncompatibleAssignment: lhs_type=::Integer, rhs_type=::String
4
+ a = begin
5
+ # @type var x: String
6
+ x = '1'
7
+ x
8
+ end
data/smoke/literal/a.rb CHANGED
@@ -1,16 +1,16 @@
1
1
  # @type var x: String
2
2
  # @type var y: Integer
3
3
 
4
- # !expects IncompatibleAssignment: lhs_type=String, rhs_type=Integer
4
+ # !expects IncompatibleAssignment: lhs_type=::String, rhs_type=::Integer
5
5
  x = 1
6
6
 
7
- # !expects IncompatibleAssignment: lhs_type=String, rhs_type=Symbol
7
+ # !expects IncompatibleAssignment: lhs_type=::String, rhs_type=::Symbol
8
8
  x = :foo
9
9
 
10
- # !expects IncompatibleAssignment: lhs_type=Integer, rhs_type=String
10
+ # !expects IncompatibleAssignment: lhs_type=::Integer, rhs_type=::String
11
11
  y = "foo"
12
12
 
13
- # !expects IncompatibleAssignment: lhs_type=String, rhs_type=_Boolean
13
+ # !expects IncompatibleAssignment: lhs_type=::String, rhs_type=_Boolean
14
14
  x = true
15
- # !expects IncompatibleAssignment: lhs_type=Integer, rhs_type=_Boolean
15
+ # !expects IncompatibleAssignment: lhs_type=::Integer, rhs_type=_Boolean
16
16
  y = false
data/smoke/method/a.rb CHANGED
@@ -1,13 +1,13 @@
1
1
  # @type method foo: (Integer, y: Integer) -> String
2
2
 
3
- # !expects MethodBodyTypeMismatch: method=foo, expected=String, actual=Integer
3
+ # !expects MethodBodyTypeMismatch: method=foo, expected=::String, actual=::Integer
4
4
  def foo(x, y:)
5
5
  # @type var z: String
6
6
 
7
- # !expects IncompatibleAssignment: lhs_type=String, rhs_type=Integer
7
+ # !expects IncompatibleAssignment: lhs_type=::String, rhs_type=::Integer
8
8
  z = x
9
9
 
10
- # !expects IncompatibleAssignment: lhs_type=String, rhs_type=Integer
10
+ # !expects IncompatibleAssignment: lhs_type=::String, rhs_type=::Integer
11
11
  z = y
12
12
 
13
13
  3
@@ -15,11 +15,11 @@ end
15
15
 
16
16
  # @type method bar: (Integer) -> String
17
17
 
18
- # !expects MethodParameterTypeMismatch: method=bar
18
+ # !expects MethodArityMismatch: method=bar
19
19
  def bar(x, y)
20
20
  # @type var z: String
21
21
 
22
- # !expects IncompatibleAssignment: lhs_type=String, rhs_type=Integer
22
+ # !expects IncompatibleAssignment: lhs_type=::String, rhs_type=::Integer
23
23
  z = x
24
24
 
25
25
  z = y
data/smoke/method/a.rbi CHANGED
@@ -0,0 +1,4 @@
1
+ class X
2
+ def foo: (String) -> Integer
3
+ | (Integer) -> String
4
+ end
data/smoke/method/b.rb ADDED
@@ -0,0 +1,29 @@
1
+ class A
2
+ # @implements X
3
+
4
+ # !expects*@+2 MethodDefinitionWithOverloading: method=foo, types=
5
+ # !expects MethodBodyTypeMismatch: method=foo, expected=(::Integer | ::String), actual=::Symbol
6
+ def foo(x)
7
+ :foobar
8
+ end
9
+ end
10
+
11
+ class B
12
+ # @implements X
13
+
14
+ # @type method foo: (::String | ::Integer) -> any
15
+ def foo(x)
16
+ 3
17
+ end
18
+ end
19
+
20
+ class C
21
+ # @implements X
22
+
23
+ # @type method foo: (Symbol) -> Symbol
24
+
25
+ # !expects IncompatibleMethodTypeAnnotation: interface_method=::X.foo, annotation_method=foo
26
+ def foo(x)
27
+ :foo
28
+ end
29
+ end
data/smoke/module/a.rb CHANGED
@@ -2,7 +2,7 @@ module A
2
2
  # @implements A
3
3
 
4
4
  def count
5
- # @type var n: Integer
5
+ # @type var n: ::Integer
6
6
  n = 0
7
7
 
8
8
  each do |_|
@@ -10,10 +10,10 @@ module A
10
10
  end
11
11
 
12
12
  # @type var s: String
13
- # !expects IncompatibleAssignment: lhs_type=String, rhs_type=Integer
13
+ # !expects IncompatibleAssignment: lhs_type=::String, rhs_type=::Integer
14
14
  s = n
15
15
 
16
- # !expects NoMethodError: type=Object + _Each<Integer> + A, method=foo
16
+ # !expects NoMethodError: type=(::A & ::Object & _Each<::Integer>), method=foo
17
17
  foo()
18
18
 
19
19
  n
data/smoke/module/a.rbi CHANGED
@@ -5,3 +5,12 @@ end
5
5
  module A : _Each<Integer>
6
6
  def count: () -> Integer
7
7
  end
8
+
9
+ module X
10
+ def foo: () -> Integer
11
+ end
12
+
13
+ module Palette
14
+ def self?.defacto_palette: -> Array<Array<Integer>>
15
+ def self.nestopia_palette: -> Array<Array<Integer>>
16
+ end
data/smoke/module/b.rb CHANGED
@@ -1,8 +1,8 @@
1
+ # ALLOW FAILURE
2
+
1
3
  # @type var klass: Class<any>
2
4
  # @type var mod: Module
3
5
 
4
6
  3.is_a?(3.class)
5
7
  klass = 3.class
6
8
  mod = "".class
7
-
8
-
data/smoke/module/c.rb CHANGED
@@ -18,6 +18,6 @@ module A
18
18
  # ok
19
19
  block_given?
20
20
 
21
- # !expects NoMethodError: type=Module + A.module, method=no_such_method_in_module
21
+ # !expects NoMethodError: type=(::A.module & ::Module), method=no_such_method_in_module
22
22
  no_such_method_in_module
23
23
  end
data/smoke/module/d.rb ADDED
@@ -0,0 +1,5 @@
1
+ # If there is a same name module definition, it automatically implements.
2
+
3
+ # !expects MethodDefinitionMissing: module=::X, method=foo
4
+ module X
5
+ end
data/smoke/module/e.rb ADDED
@@ -0,0 +1,13 @@
1
+ # If module has a @implements annotation, it wins
2
+
3
+ module X
4
+ # @implements A
5
+
6
+ def count
7
+ 3
8
+ end
9
+
10
+ def foo
11
+ "3"
12
+ end
13
+ end