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