forked from compleathorseplayer/Neptune.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MethodSignatures.jl
95 lines (87 loc) · 2.28 KB
/
MethodSignatures.jl
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using Test
import Pluto.ExpressionExplorer: SymbolsState, compute_symbolreferences, FunctionNameSignaturePair
@testset "Method signatures" begin
function methods_can_coexist(defs::Expr...)
symstates = compute_symbolreferences.(defs)
funcnamesigs = [first(keys(syms.funcdefs)) for syms in symstates]
length(Set(funcnamesigs)) == length(defs)
end
@testset "Different method signatures across cells" begin
@test methods_can_coexist(
:(f(x, y) = 1),
:(f(x) = 2),
)
@test methods_can_coexist(
:(f(x::A) = 1),
:(f(x::B) = 2),
)
@test methods_can_coexist(
:(f(x, y=1) = 1),
:(f(x, y) = 2),
)
@test methods_can_coexist(
:(f(x::e(f{g})=3) = 1),
:(f(x::h where i) = 2),
)
@test methods_can_coexist(
:(f(x::Tuple{X,T} where T) = 1),
:(f(x::Tuple{X,T}) = 2),
)
@test methods_can_coexist(
:(f(x::A) where A = 1),
:(f(x::A) = 2),
)
@test methods_can_coexist(
:(f(x::String, y) = 1),
:(f(x, y::String) = 2),
)
@test methods_can_coexist(
:(f(x::A) = 1),
:(f(x::B) = 2),
)
@test methods_can_coexist(
:(f(x, y...) = 1),
:(f(x) = 2),
)
@test methods_can_coexist(
:(f(x, y::Z...) = 1),
:(f(x, y::X...) = 2),
)
# what is this called again?
@test methods_can_coexist(
:(f(x::T) where T = 1),
:(f(x) = 2),
)
end
@testset "Identical method signatures across cells" begin
@test !methods_can_coexist(
:(f(x) = 3),
:(f(y) = 3),
)
@test !methods_can_coexist(
:(f(x) = 3),
:(f(y; z) = 3),
)
@test !methods_can_coexist(
:(f(x) = 3),
:(f(y::Any) = 3),
)
# function using build in type synonyms
# like Int and Int64
@assert string(Int) == "Int64" || string(Int) == "Int32"
@test_broken !methods_can_coexist(
:(f(x::Int) = 3),
Meta.parse("f(x::$(string(Int))) = 4"),
)
# multiple methods per cell
@test !methods_can_coexist(
:(f(x::Int) = 1; f(x::String) = 2),
:(f(x::String) = 3; f(x::Vector) = 4),
)
# methods only differing in key word arguments
@test !methods_can_coexist(
:(f() = 1),
:(f(; x) = 3),
)
end
end