Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions scenario/known-issues/absolute-constant-path.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## update
class ::Foo
def foo = 1
end

## assert
class Foo
def foo: -> Integer
end

## update
module M
class ::Bar
def bar = 1
end
end

## assert
module M
class ::Bar
def bar: -> Integer
end
end

## update
module M
end

class ::M::Baz
def baz = 1
end

## assert
module M
end
class M::Baz
def baz: -> Integer
end
16 changes: 16 additions & 0 deletions scenario/known-issues/array-aref-range.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## update
def foo
[1, 2, 3][1..]
end

def bar(a)
a[0..1]
end

bar([1, "str"])

## assert
class Object
def foo: -> Array[Integer]?
def bar: ([Integer, String]) -> Array[Integer | String]?
end
38 changes: 38 additions & 0 deletions scenario/known-issues/attr-with-visibility.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## update
class Foo
def initialize(name)
@name = name
end

private attr_reader :name

def label = name
end

Foo.new("foo").label

## assert
class Foo
def initialize: (String) -> void
def name: -> String
def label: -> String
end

## update
class Foo
def initialize(count)
@count = count
end

public attr_accessor :count
end

foo = Foo.new(1)
foo.count = 2

## assert
class Foo
def initialize: (Integer) -> void
def count: -> Integer
def count=: (Integer) -> Integer
end
30 changes: 30 additions & 0 deletions scenario/known-issues/attrasgn-value.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## update
class C
def foo=(x)
:ret
end

def []=(k, v)
:ret
end
end

def check_attrasgn
c = C.new
c.foo = 1
end

def check_index_asgn
c = C.new
c[:a] = 1
end

## assert
class C
def foo=: (Integer) -> :ret
def []=: (:a, Integer) -> :ret
end
class Object
def check_attrasgn: -> Integer
def check_index_asgn: -> Integer
end
17 changes: 17 additions & 0 deletions scenario/known-issues/block-autosplat-non-array.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## update
# A sole non-Array value is bound to the first parameter, not splatted.
def yield_one
yield 1
end

def check1 = yield_one {|x, y| [x, y] }
def check2 = [1, "str"].map {|x, y| x }
def check3 = [[1, 2], :sym].map {|x, y| x }

## assert
class Object
def yield_one: { (Integer) -> [Integer, nil] } -> [Integer, nil]
def check1: -> [Integer, nil]
def check2: -> Array[Integer | String]
def check3: -> Array[:sym | Integer]
end
11 changes: 11 additions & 0 deletions scenario/known-issues/block-rest-param.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## update
def check1 = [1].map {|*b| b }
def check2 = [[1, "str"]].map {|a, *b| b }
def check3 = [[1, "str", :sym]].map {|a, *b, c| c }

## assert
class Object
def check1: -> Array[Array[Integer]]
def check2: -> Array[Array[String]]
def check3: -> Array[:sym]
end
20 changes: 20 additions & 0 deletions scenario/known-issues/case-in-local-assignment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## update
def foo(value)
label = :none
case value
in Integer
label = :integer
in String
label = :string
else
end
label
end

foo(1)
foo("str")

## assert
class Object
def foo: (Integer | String) -> (:integer | :none | :string)
end
40 changes: 40 additions & 0 deletions scenario/known-issues/constant-alias.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## update
module M
CONST = 1
end

Alias = M

def test = Alias::CONST

## assert
module M
CONST: Integer
end
Alias: singleton(M)
class Object
def test: -> Integer
end

## update
class Base
def hello = :hi
end

Alias = Base

class Foo < Alias
end

def test = Foo.new.hello

## assert
class Base
def hello: -> :hi
end
Alias: singleton(Base)
class Foo < Base
end
class Object
def test: -> :hi
end
28 changes: 28 additions & 0 deletions scenario/known-issues/cyclic-include.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## update
module A
end

module B
include A
end

module A
include B
end

class C
include A
def foo = bar
end

## assert
module A
end
module B
end
module A
end
class C
include A
def foo: -> untyped
end
15 changes: 15 additions & 0 deletions scenario/known-issues/defined.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
## update
def foo
x = 1
defined?(x)
end

def bar
defined?(@unknown)
end

## assert
class Object
def foo: -> String?
def bar: -> String?
end
35 changes: 35 additions & 0 deletions scenario/known-issues/destructuring-param-rest.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## update
def check1((a, *b))
b
end

check1([1, 2, 3])

def check2((a, *b, c))
c
end

check2([1, 2, :sym])

def check3((a, (b, c)))
c
end

check3([1, [2, "str"]])

## assert
class Object
def check1: ([Integer, Integer, Integer]) -> Array[Integer]
def check2: ([Integer, Integer, :sym]) -> :sym
def check3: ([Integer, [Integer, String]]) -> String
end

## update
def check
[[1, "str", :sym]].map {|(a, *b)| b }
end

## assert
class Object
def check: -> Array[Array[:sym | String]]
end
27 changes: 27 additions & 0 deletions scenario/known-issues/dynamic-constant-scope.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## update
class Foo
X = 1

def self.foo = self::X
end

## assert
class Foo
X: Integer
def self.foo: -> Integer
end

## update
class Foo
X = 1

def foo = self.class::X
end

Foo.new.foo

## assert
class Foo
X: Integer
def foo: -> Integer
end
19 changes: 19 additions & 0 deletions scenario/known-issues/for-loop-index-variable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## update
def foo
for i in [1, 2, 3]
return i
end
nil
end

def bar
for s in ["a", "b"]
end
s
end

## assert
class Object
def foo: -> Integer?
def bar: -> String?
end
23 changes: 23 additions & 0 deletions scenario/known-issues/hash-pattern-capture.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## update
def foo(h)
case h
in { v: x }
x
end
end

def bar(h)
case h
in { v: }
v
end
end

foo({ v: 1 })
bar({ v: "str" })

## assert
class Object
def foo: ({ v: Integer }) -> Integer
def bar: ({ v: String }) -> String
end
21 changes: 21 additions & 0 deletions scenario/known-issues/include-in-singleton-class.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## update
module Helpers
def helper = :ok
end

class Foo
class << self
include Helpers

def bar = helper
end
end

## assert
module Helpers
def helper: -> :ok
end
class Foo
extend Helpers
def self.bar: -> :ok
end
Loading
Loading