-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
60 lines (48 loc) · 1.24 KB
/
utils.go
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
package intertype
import "go/types"
func isIncluded(hay string, stack []string) bool {
for i := range stack {
if hay == stack[i] {
return true
}
}
return false
}
func checkImpossibleTypes(badTypes []string, dynamicTypes []types.Type) (extraTypes []string) {
var dynTyps []string
for i := range dynamicTypes {
dynTyps = append(dynTyps, dynamicTypes[i].String())
}
for i := range dynTyps {
if isIncluded(dynTyps[i], badTypes) {
extraTypes = append(extraTypes, dynTyps[i])
}
}
return extraTypes
}
func checkPossibleTypes(possibleTyps []string, dynamicTypes []types.Type) (missingTypes, impossibleTypes []string) {
var dynTyps []string
nilIncluded := false
for i := range possibleTyps {
if possibleTyps[i] == "untyped nil" {
nilIncluded = true
}
}
if !nilIncluded {
possibleTyps = append(possibleTyps, "untyped nil")
}
for i := range dynamicTypes {
dynTyps = append(dynTyps, dynamicTypes[i].String())
}
for i := range possibleTyps {
if !isIncluded(possibleTyps[i], dynTyps) {
missingTypes = append(missingTypes, possibleTyps[i])
}
}
for i := range dynTyps {
if !isIncluded(dynTyps[i], possibleTyps) {
impossibleTypes = append(impossibleTypes, dynTyps[i])
}
}
return missingTypes, impossibleTypes
}