ssa: improve hasTypeParam coverage
This commit is contained in:
@@ -30,6 +30,11 @@ func TestHasTypeParam(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Instantiate: %v", err)
|
t.Fatalf("Instantiate: %v", err)
|
||||||
}
|
}
|
||||||
|
partialArg := newTypeParam("PartialArg")
|
||||||
|
partialInstance, err := types.Instantiate(types.NewContext(), generic, []types.Type{partialArg}, false)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("Instantiate partial: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
arrayType := func() types.Type {
|
arrayType := func() types.Type {
|
||||||
tp := newTypeParam("ArrayElem")
|
tp := newTypeParam("ArrayElem")
|
||||||
@@ -61,6 +66,16 @@ func TestHasTypeParam(t *testing.T) {
|
|||||||
results := types.NewTuple(types.NewVar(token.NoPos, nil, "res", tp))
|
results := types.NewTuple(types.NewVar(token.NoPos, nil, "res", tp))
|
||||||
return types.NewSignatureType(nil, nil, []*types.TypeParam{tp}, types.NewTuple(), results, false)
|
return types.NewSignatureType(nil, nil, []*types.TypeParam{tp}, types.NewTuple(), results, false)
|
||||||
}()
|
}()
|
||||||
|
signatureParamWithoutDecl := func() types.Type {
|
||||||
|
tp := newTypeParam("SigParamExternal")
|
||||||
|
params := types.NewTuple(types.NewVar(token.NoPos, nil, "x", tp))
|
||||||
|
return types.NewSignatureType(nil, nil, nil, params, types.NewTuple(), false)
|
||||||
|
}()
|
||||||
|
signatureResultWithoutDecl := func() types.Type {
|
||||||
|
tp := newTypeParam("SigResultExternal")
|
||||||
|
results := types.NewTuple(types.NewVar(token.NoPos, nil, "res", tp))
|
||||||
|
return types.NewSignatureType(nil, nil, nil, types.NewTuple(), results, false)
|
||||||
|
}()
|
||||||
|
|
||||||
interfaceWithParam := func() types.Type {
|
interfaceWithParam := func() types.Type {
|
||||||
tp := newTypeParam("IfaceParam")
|
tp := newTypeParam("IfaceParam")
|
||||||
@@ -79,6 +94,12 @@ func TestHasTypeParam(t *testing.T) {
|
|||||||
iface.Complete()
|
iface.Complete()
|
||||||
return iface
|
return iface
|
||||||
}()
|
}()
|
||||||
|
interfaceWithEmbeddedOnly := func() types.Type {
|
||||||
|
embedded := interfaceWithParam
|
||||||
|
iface := types.NewInterfaceType(nil, []types.Type{embedded})
|
||||||
|
iface.Complete()
|
||||||
|
return iface
|
||||||
|
}()
|
||||||
|
|
||||||
selfRecursive := func() types.Type {
|
selfRecursive := func() types.Type {
|
||||||
typeName := types.NewTypeName(token.NoPos, nil, "Node", nil)
|
typeName := types.NewTypeName(token.NoPos, nil, "Node", nil)
|
||||||
@@ -95,6 +116,7 @@ func TestHasTypeParam(t *testing.T) {
|
|||||||
typ types.Type
|
typ types.Type
|
||||||
want bool
|
want bool
|
||||||
}{
|
}{
|
||||||
|
{"nilType", nil, false},
|
||||||
{"basic", types.Typ[types.Int], false},
|
{"basic", types.Typ[types.Int], false},
|
||||||
{"typeParam", newTypeParam("T"), true},
|
{"typeParam", newTypeParam("T"), true},
|
||||||
{"pointerToTypeParam", types.NewPointer(newTypeParam("PtrT")), true},
|
{"pointerToTypeParam", types.NewPointer(newTypeParam("PtrT")), true},
|
||||||
@@ -106,10 +128,14 @@ func TestHasTypeParam(t *testing.T) {
|
|||||||
{"structWithTypeParam", structWithParam, true},
|
{"structWithTypeParam", structWithParam, true},
|
||||||
{"signatureWithTypeParam", signatureWithParam, true},
|
{"signatureWithTypeParam", signatureWithParam, true},
|
||||||
{"signatureWithResultTypeParam", signatureWithResult, true},
|
{"signatureWithResultTypeParam", signatureWithResult, true},
|
||||||
|
{"signatureParamWithoutDecl", signatureParamWithoutDecl, true},
|
||||||
|
{"signatureResultWithoutDecl", signatureResultWithoutDecl, true},
|
||||||
{"interfaceWithTypeParam", interfaceWithParam, true},
|
{"interfaceWithTypeParam", interfaceWithParam, true},
|
||||||
{"interfaceWithEmbeddedTypeParam", interfaceWithEmbed, true},
|
{"interfaceWithEmbeddedTypeParam", interfaceWithEmbed, true},
|
||||||
|
{"interfaceWithEmbeddedOnlyTypeParam", interfaceWithEmbeddedOnly, true},
|
||||||
{"namedGeneric", generic, true},
|
{"namedGeneric", generic, true},
|
||||||
{"pointerToNamedGeneric", types.NewPointer(generic), true},
|
{"pointerToNamedGeneric", types.NewPointer(generic), true},
|
||||||
|
{"namedInstanceWithTypeParamArg", partialInstance, true},
|
||||||
{"namedInstanceNoParam", instantiated, false},
|
{"namedInstanceNoParam", instantiated, false},
|
||||||
{"selfRecursiveStruct", selfRecursive, false},
|
{"selfRecursiveStruct", selfRecursive, false},
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user