diff --git a/lib/typeprof/core/graph/vertex.rb b/lib/typeprof/core/graph/vertex.rb index b39d8f8f..e2fa29ba 100644 --- a/lib/typeprof/core/graph/vertex.rb +++ b/lib/typeprof/core/graph/vertex.rb @@ -28,14 +28,17 @@ def check_match(genv, changes, vtx) end end + return true if @types.empty? return true if vtx.types.empty? each_type do |ty| - next if vtx.types.include?(ty) # fast path - return false unless ty.check_match(genv, changes, vtx) + return true if vtx.types.include?(ty) # fast path + if ty.check_match(genv, changes, vtx) + return true + end end - return true + return false end def show diff --git a/scenario/known-issues/check-return-type.rb b/scenario/known-issues/check-return-type.rb new file mode 100644 index 00000000..c3848f0a --- /dev/null +++ b/scenario/known-issues/check-return-type.rb @@ -0,0 +1,17 @@ +## update: test.rbs +class Foo + def foo: -> Foo + def foo=: (Foo) -> Foo +end + +## update: test.rb +class Foo + def initialize + @foo = 1 + end + + attr_accessor :foo +end + +## diagnostics: test.rb +(6,2)-(6,20): expected: Foo; actual: (Foo | Integer) diff --git a/scenario/known-issues/unsupported-arg.rb b/scenario/known-issues/unsupported-arg.rb new file mode 100644 index 00000000..16ee20d6 --- /dev/null +++ b/scenario/known-issues/unsupported-arg.rb @@ -0,0 +1,14 @@ +## update: test.rbs +class Object + def foo: (String) -> String + | (Integer) -> Integer + def get1: -> (String | Integer) + def get2: -> (String | Integer | nil) +end + +## update: test.rb +def check1 = foo(get1) +def check2 = foo(get2) + +## diagnostics +(2,13)-(2,16): expected: (String | Integer); actual: (String | Integer)? diff --git a/scenario/rbs/check-return-type5.rb b/scenario/rbs/check-return-type5.rb index 57b20529..90a3670c 100644 --- a/scenario/rbs/check-return-type5.rb +++ b/scenario/rbs/check-return-type5.rb @@ -14,21 +14,3 @@ def initialize ## diagnostics: test.rb (6,2)-(6,18): expected: Foo; actual: Integer - -## update: test.rbs -class Foo - def foo: -> Foo - def foo=: (Foo) -> Foo -end - -## update: test.rb -class Foo - def initialize - @foo = 1 - end - - attr_accessor :foo -end - -## diagnostics: test.rb -(6,2)-(6,20): expected: Foo; actual: (Foo | Integer) diff --git a/scenario/regressions/avoid-infinte-loop-2.rb b/scenario/regressions/avoid-infinte-loop-2.rb new file mode 100644 index 00000000..42caba84 --- /dev/null +++ b/scenario/regressions/avoid-infinte-loop-2.rb @@ -0,0 +1,26 @@ +## update: test.rbs +class Foo + def foo: -> Foo? + def self.bar: (Foo) -> Foo +end + +## update: test.rb +def check + # The old infinite-loop scenario + # 1. both @a and @b are untyped + # 2. @b is now Foo because `@b = Foo.bar(@a)` and `Foo.bar: (Foo) -> Foo` and @a is untyped + # 3. @a is now Foo? because of `@a = @b.foo` and @b is Foo + # 4. @b is now untyped because `@b = Foo.bar(@a)` and `Foo.bar: (Foo) -> Foo` and @a is Foo | nil + # 5. go to 2 + # + # How did I fixed: + # `Foo.bar: (Foo) -> Foo` should match against `Foo | nil` + # (TODO: add a diagnostics for this) + @a = @b.foo + @b = Foo.bar(@a) +end + +def check2 + @a = @b[0] + @b = '/' + @a +end