Skip to content

Commit 96efab8

Browse files
committed
Add scenarios for the splat fallback on union types
Cover the cases the union fallback has to get right: nil must not be wrapped (`[*nil]` is `[]`), `to_ary` must not stand in for `to_a`, and adding or removing `to_a` must flip the result, which exercises the dependency edge that the fallback relies on.
1 parent 734a5ce commit 96efab8

2 files changed

Lines changed: 88 additions & 0 deletions

File tree

scenario/array/splat.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,37 @@ def foo(x)
2424
class Object
2525
def foo: (:sym | [:int]) -> Array[:int | :sym]
2626
end
27+
28+
## update
29+
def foo(x)
30+
[*x]
31+
end
32+
33+
foo([1])
34+
foo(nil)
35+
36+
## assert
37+
class Object
38+
def foo: ([Integer]?) -> Array[Integer]
39+
end
40+
41+
## update
42+
class C
43+
def to_ary
44+
[1]
45+
end
46+
end
47+
48+
def foo(x)
49+
[*x]
50+
end
51+
52+
foo(C.new)
53+
54+
## assert
55+
class C
56+
def to_ary: -> [Integer]
57+
end
58+
class Object
59+
def foo: (C) -> Array[C]
60+
end

scenario/incremental/splat-to-a.rb

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
## update
2+
class C
3+
end
4+
5+
def foo(x)
6+
[*x]
7+
end
8+
9+
foo(C.new)
10+
11+
## assert
12+
class C
13+
end
14+
class Object
15+
def foo: (C) -> Array[C]
16+
end
17+
18+
## update
19+
class C
20+
def to_a
21+
[1]
22+
end
23+
end
24+
25+
def foo(x)
26+
[*x]
27+
end
28+
29+
foo(C.new)
30+
31+
## assert
32+
class C
33+
def to_a: -> [Integer]
34+
end
35+
class Object
36+
def foo: (C) -> Array[Integer]
37+
end
38+
39+
## update
40+
class C
41+
end
42+
43+
def foo(x)
44+
[*x]
45+
end
46+
47+
foo(C.new)
48+
49+
## assert
50+
class C
51+
end
52+
class Object
53+
def foo: (C) -> Array[C]
54+
end

0 commit comments

Comments
 (0)