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