forked from sorbet/sorbet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcall_with_splat_and_block_strict.rb
54 lines (42 loc) · 1.15 KB
/
call_with_splat_and_block_strict.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# typed: strict
extend T::Sig
class A
extend T::Sig
sig { params(a: Integer, blk: Proc).void }
def foo(a, &blk)
end
end
class B < A
extend T::Sig
sig { params(blk: Proc).void }
def foo(&blk)
super(*[1], &blk)
end
end
def no_sig(&blk) # error: This function does not have a `sig`
foo(*[1], &blk)
end
sig {params(a: Integer, blk: T.nilable(T.proc.returns(String))).void}
def foo(a, &blk)
bar(*[a], &blk)
bar(*[a], &nil)
end
sig {params(a: Integer, blk: T.nilable(T.proc.returns(String))).void}
def bar(a, &blk)
end
sig {params(a: Integer, blk: T.proc.returns(String)).void}
def baz(a, &blk)
foo(*[a], &blk)
foo(*[a], &nil)
end
sig { params(a: Integer, b: String, blk: T.proc.params(arg0: Integer).returns(String)).void }
def foo_splat(a, b, &blk)
end
sig { params(blk: T.proc.params(arg0: Integer).returns(String)).void }
def bar_splat(&blk)
foo_splat(*[1, "a"], &blk)
end
sig { params(blk: T.proc.params(arg0: Integer).returns(Integer)).void }
def baz_splat(&blk)
foo_splat(*[1, "a"], &blk) # error: Expected `T.proc.params(arg0: Integer).returns(String)` but found `T.proc.params(arg0: Integer).returns(Integer)` for block argument
end