Source file
src/go/types/context_test.go
1
2
3
4
5
6
7 package types
8
9 import (
10 "testing"
11 )
12
13 func TestContextHashCollisions(t *testing.T) {
14 if debug {
15 t.Skip("hash collisions are expected, and would fail debug assertions")
16 }
17
18
19
20
21
22
23
24
25
26
27
28
29 var nullaryP, nullaryQ, unaryP Type
30 {
31
32 tparam := NewTypeParam(NewTypeName(nopos, nil, "P", nil), &emptyInterface)
33 nullaryP = NewSignatureType(nil, nil, []*TypeParam{tparam}, nil, nil, false)
34 }
35 {
36
37 tparam := NewTypeParam(NewTypeName(nopos, nil, "Q", nil), &emptyInterface)
38 nullaryQ = NewSignatureType(nil, nil, []*TypeParam{tparam}, nil, nil, false)
39 }
40 {
41
42 tparam := NewTypeParam(NewTypeName(nopos, nil, "P", nil), &emptyInterface)
43 params := NewTuple(NewVar(nopos, nil, "_", tparam))
44 unaryP = NewSignatureType(nil, nil, []*TypeParam{tparam}, params, nil, false)
45 }
46
47 ctxt := NewContext()
48
49
50 inst := NewSignatureType(nil, nil, nil, nil, nil, false)
51 if got := ctxt.update("", nullaryP, []Type{Typ[Int]}, inst); got != inst {
52 t.Error("bad")
53 }
54
55
56
57 if got := ctxt.lookup("", unaryP, []Type{Typ[Int]}); got != nil {
58 t.Error("bad")
59 }
60
61
62
63 if got := ctxt.lookup("", nullaryQ, []Type{Typ[Int]}); got != inst {
64 t.Error("bad")
65 }
66
67
68 if got := ctxt.lookup("", nullaryQ, []Type{Typ[String]}); got != nil {
69 t.Error("bad")
70 }
71 }
72
View as plain text