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