forked from angellist/sorbet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcall_with_block_strict.rb
57 lines (45 loc) · 1.35 KB
/
call_with_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
55
56
57
# typed: strict
extend T::Sig
class A
extend T::Sig
sig { params(blk: Proc).void }
def foo(&blk)
end
end
class B < A
extend T::Sig
sig { params(blk: Proc).void }
def foo(&blk)
super(&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)
T.reveal_type(proc(&blk)) # error: Revealed type: `T.proc.returns(T.untyped)`
foo(a, &blk)
foo(a, &nil)
end
sig {params(blk: T.proc.params(arg0: Integer).returns(String)).void}
def int_map(&blk)
a = [1, 2, 3].map(&blk)
T.reveal_type(a) # error: Revealed type: `T::Array[String]`
["a", "b"].map(&blk) # error: Expected `T.proc.params(arg0: String).returns(<top>)` but found `T.proc.params(arg0: Integer).returns(String)` for block argument
end
sig {params(blk: Proc).void}
def unknown_arity(&blk)
a = [1, 2, 3].map(&blk) # error: Cannot use a `Proc` with unknown arity as a `T.proc.params(arg0: Integer).returns(<top>)`
T.reveal_type(a) # error: Revealed type: `T::Array[T.untyped]`
end
a = [1, 2].map(&:to_s)
T.reveal_type(a) # error: Revealed type: `T::Array[String]`