diff --git a/scenario/known-issues/accumulator-in-block.rb b/scenario/known-issues/accumulator-in-block.rb new file mode 100644 index 00000000..4ff98128 --- /dev/null +++ b/scenario/known-issues/accumulator-in-block.rb @@ -0,0 +1,29 @@ +## update +def foo(arr) + result = [] + arr.each {|x| result << x * 2 } + result +end + +foo([1, 2, 3]) + +## assert +class Object + def foo: ([Integer, Integer, Integer]) -> Array[Integer] +end + +## update +def collect(arr) + acc = [] + arr.each_with_index do |x, i| + acc << [i, x] + end + acc +end + +collect(["a", "b"]) + +## assert +class Object + def collect: ([String, String]) -> Array[[Integer, String]] +end diff --git a/scenario/known-issues/alias-output.rb b/scenario/known-issues/alias-output.rb new file mode 100644 index 00000000..21743ee9 --- /dev/null +++ b/scenario/known-issues/alias-output.rb @@ -0,0 +1,27 @@ +## update +class C + def hello = "hi" + alias greet hello +end + +C.new.greet + +## assert +class C + def hello: -> String + alias greet hello +end + +## update +class C + def hello = "hi" + alias_method :greet, :hello +end + +C.new.greet + +## assert +class C + def hello: -> String + alias greet hello +end diff --git a/scenario/known-issues/data-define.rb b/scenario/known-issues/data-define.rb new file mode 100644 index 00000000..f4aae7e8 --- /dev/null +++ b/scenario/known-issues/data-define.rb @@ -0,0 +1,24 @@ +## update +Foo = Data.define(:x, :y) +Foo.new(x: 1, y: "a") + +## assert +class Foo < Data + def initialize: (x: Integer, y: String) -> void + def x: -> Integer + def y: -> String +end + +## update +class Bar < Data.define(:name) + def greet = "hi, #{name}" +end + +Bar.new(name: "taro").greet + +## assert +class Bar < Data + def initialize: (name: String) -> void + def name: -> String + def greet: -> String +end diff --git a/scenario/known-issues/define-method-with-block.rb b/scenario/known-issues/define-method-with-block.rb new file mode 100644 index 00000000..91b33387 --- /dev/null +++ b/scenario/known-issues/define-method-with-block.rb @@ -0,0 +1,14 @@ +## update +class C + define_method(:hello) { "hi" } + define_method(:double) {|x| x * 2 } +end + +C.new.hello +C.new.double(1) + +## assert +class C + def hello: -> String + def double: (Integer) -> Integer +end diff --git a/scenario/known-issues/eigenclass-attr.rb b/scenario/known-issues/eigenclass-attr.rb new file mode 100644 index 00000000..f6bf51ad --- /dev/null +++ b/scenario/known-issues/eigenclass-attr.rb @@ -0,0 +1,31 @@ +## update +class C + class << self + attr_accessor :age + end +end + +C.age = 1 +C.age + +## assert +class C + def self.age: -> Integer + def self.age=: (Integer) -> Integer +end + +## update +class C + class << self + attr_reader :name + attr_writer :value + end +end + +C.value = "value" + +## assert +class C + def self.name: -> untyped + def self.value=: (String) -> String +end diff --git a/scenario/known-issues/extend-self.rb b/scenario/known-issues/extend-self.rb new file mode 100644 index 00000000..5d59dd2c --- /dev/null +++ b/scenario/known-issues/extend-self.rb @@ -0,0 +1,33 @@ +## update +module M + extend self + + def hello = "hi" +end + +M.hello + +## assert +module M + def hello: -> String + def self.hello: -> String +end + +## update +module Helpers + def shout(s) = s.upcase +end + +module App + extend Helpers +end + +App.shout("hi") + +## assert +module Helpers + def shout: (String) -> String +end +module App + extend Helpers +end diff --git a/scenario/known-issues/module-function.rb b/scenario/known-issues/module-function.rb new file mode 100644 index 00000000..9c26b08c --- /dev/null +++ b/scenario/known-issues/module-function.rb @@ -0,0 +1,55 @@ +## update +module M + def foo = "foo" + def bar = "bar" + module_function :foo +end + +C.foo + +## assert +module M + def self.foo: -> String + def bar: -> String + private + def foo: -> String +end + +## update +module M + def foo = "foo" + def bar = "bar" + module_function :foo, :bar +end + +C.foo +C.bar + +## assert +module M + def self.foo: -> String + def self.bar: -> String + private + def foo: -> String + def bar: -> String +end + +## update +module M + module_function + + def foo = "foo" + def bar = "bar" +end + +C.foo +C.bar + +## assert +module M + def self.foo: -> String + def self.bar: -> String + private + def foo: -> String + def bar: -> String +end diff --git a/scenario/known-issues/pattern-capture-narrowing.rb b/scenario/known-issues/pattern-capture-narrowing.rb new file mode 100644 index 00000000..7812cb25 --- /dev/null +++ b/scenario/known-issues/pattern-capture-narrowing.rb @@ -0,0 +1,32 @@ +## update +def check(a) + case a + in Integer => n + n + 1 + in String => s + s.upcase + end +end + +check(1) +check("foo") + +## assert +class Object + def check: (Integer | String) -> (Integer | String)? +end + +## update +def check(a) + case a + in [Integer => n, String => s] + [n, s] + end +end + +check([42, "foo"]) + +## assert +class Object + def check: ([Integer, String]) -> [Integer, String]? +end diff --git a/scenario/known-issues/super-parent-arg-inference.rb b/scenario/known-issues/super-parent-arg-inference.rb new file mode 100644 index 00000000..a0bbca58 --- /dev/null +++ b/scenario/known-issues/super-parent-arg-inference.rb @@ -0,0 +1,20 @@ +## update +class A + def foo(x) = x + 1 +end + +class B < A + def foo(x) + super + end +end + +B.new.foo(1) + +## assert +class A + def foo: (Integer) -> Integer +end +class B < A + def foo: (Integer) -> Integer +end diff --git a/scenario/known-issues/visibility-modifier.rb b/scenario/known-issues/visibility-modifier.rb new file mode 100644 index 00000000..74214892 --- /dev/null +++ b/scenario/known-issues/visibility-modifier.rb @@ -0,0 +1,54 @@ +## update +class Foo + def public_method = "public_method" + + private + + def private_method = "private_method" +end + +## assert +class Foo + def public_method: -> String + private + def private_method: -> String +end + +## update +class Foo + private def private_method = "private_method" + public def public_method = "public_method" +end + +## assert +class Foo + private def private_method: -> String + public def public_method: -> String +end + +## update +class Foo + private def private_method = "private_method" + public def public_method = "public_method" + def other_method = "other_method" +end + +## assert +class Foo + private def private_method: -> String + public def public_method: -> String + def other_method: -> String +end + +## update +class Foo + def private_method = "private_method" + def public_method = "public_method" + private :private_method +end + +## assert +class Foo + private def private_method: -> String + def public_method: -> String +end