GoPLS Viewer

Home|gopls/internal/typeparams/typeparams_go117.go
1// Copyright 2021 The Go Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
3// license that can be found in the LICENSE file.
4
5//go:build !go1.18
6// +build !go1.18
7
8package typeparams
9
10import (
11    "go/ast"
12    "go/token"
13    "go/types"
14)
15
16func unsupported() {
17    panic("type parameters are unsupported at this go version")
18}
19
20// IndexListExpr is a placeholder type, as type parameters are not supported at
21// this Go version. Its methods panic on use.
22type IndexListExpr struct {
23    ast.Expr
24    X       ast.Expr   // expression
25    Lbrack  token.Pos  // position of "["
26    Indices []ast.Expr // index expressions
27    Rbrack  token.Pos  // position of "]"
28}
29
30// ForTypeSpec returns an empty field list, as type parameters on not supported
31// at this Go version.
32func ForTypeSpec(*ast.TypeSpec) *ast.FieldList {
33    return nil
34}
35
36// ForFuncType returns an empty field list, as type parameters are not
37// supported at this Go version.
38func ForFuncType(*ast.FuncType) *ast.FieldList {
39    return nil
40}
41
42// TypeParam is a placeholder type, as type parameters are not supported at
43// this Go version. Its methods panic on use.
44type TypeParam struct{ types.Type }
45
46func (*TypeParamIndex() int             { unsupported(); return 0 }
47func (*TypeParamConstraint() types.Type { unsupported(); return nil }
48func (*TypeParamObj() *types.TypeName   { unsupported(); return nil }
49
50// TypeParamList is a placeholder for an empty type parameter list.
51type TypeParamList struct{}
52
53func (*TypeParamListLen() int          { return 0 }
54func (*TypeParamListAt(int) *TypeParam { unsupported(); return nil }
55
56// TypeList is a placeholder for an empty type list.
57type TypeList struct{}
58
59func (*TypeListLen() int          { return 0 }
60func (*TypeListAt(inttypes.Type { unsupported(); return nil }
61
62// NewTypeParam is unsupported at this Go version, and panics.
63func NewTypeParam(name *types.TypeNameconstraint types.Type) *TypeParam {
64    unsupported()
65    return nil
66}
67
68// SetTypeParamConstraint is unsupported at this Go version, and panics.
69func SetTypeParamConstraint(tparam *TypeParamconstraint types.Type) {
70    unsupported()
71}
72
73// NewSignatureType calls types.NewSignature, panicking if recvTypeParams or
74// typeParams is non-empty.
75func NewSignatureType(recv *types.VarrecvTypeParamstypeParams []*TypeParamparamsresults *types.Tuplevariadic bool) *types.Signature {
76    if len(recvTypeParams) != 0 || len(typeParams) != 0 {
77        panic("signatures cannot have type parameters at this Go version")
78    }
79    return types.NewSignature(recvparamsresultsvariadic)
80}
81
82// ForSignature returns an empty slice.
83func ForSignature(*types.Signature) *TypeParamList {
84    return nil
85}
86
87// RecvTypeParams returns a nil slice.
88func RecvTypeParams(sig *types.Signature) *TypeParamList {
89    return nil
90}
91
92// IsComparable returns false, as no interfaces are type-restricted at this Go
93// version.
94func IsComparable(*types.Interfacebool {
95    return false
96}
97
98// IsMethodSet returns true, as no interfaces are type-restricted at this Go
99// version.
100func IsMethodSet(*types.Interfacebool {
101    return true
102}
103
104// IsImplicit returns false, as no interfaces are implicit at this Go version.
105func IsImplicit(*types.Interfacebool {
106    return false
107}
108
109// MarkImplicit does nothing, because this Go version does not have implicit
110// interfaces.
111func MarkImplicit(*types.Interface) {}
112
113// ForNamed returns an empty type parameter list, as type parameters are not
114// supported at this Go version.
115func ForNamed(*types.Named) *TypeParamList {
116    return nil
117}
118
119// SetForNamed panics if tparams is non-empty.
120func SetForNamed(_ *types.Namedtparams []*TypeParam) {
121    if len(tparams) > 0 {
122        unsupported()
123    }
124}
125
126// NamedTypeArgs returns nil.
127func NamedTypeArgs(*types.Named) *TypeList {
128    return nil
129}
130
131// NamedTypeOrigin is the identity method at this Go version.
132func NamedTypeOrigin(named *types.Namedtypes.Type {
133    return named
134}
135
136// Term holds information about a structural type restriction.
137type Term struct {
138    tilde bool
139    typ   types.Type
140}
141
142func (m *TermTilde() bool      { return m.tilde }
143func (m *TermType() types.Type { return m.typ }
144func (m *TermString() string {
145    pre := ""
146    if m.tilde {
147        pre = "~"
148    }
149    return pre + m.typ.String()
150}
151
152// NewTerm is unsupported at this Go version, and panics.
153func NewTerm(tilde booltyp types.Type) *Term {
154    return &Term{tildetyp}
155}
156
157// Union is a placeholder type, as type parameters are not supported at this Go
158// version. Its methods panic on use.
159type Union struct{ types.Type }
160
161func (*UnionLen() int         { return 0 }
162func (*UnionTerm(i int) *Term { unsupported(); return nil }
163
164// NewUnion is unsupported at this Go version, and panics.
165func NewUnion(terms []*Term) *Union {
166    unsupported()
167    return nil
168}
169
170// InitInstanceInfo is a noop at this Go version.
171func InitInstanceInfo(*types.Info) {}
172
173// Instance is a placeholder type, as type parameters are not supported at this
174// Go version.
175type Instance struct {
176    TypeArgs *TypeList
177    Type     types.Type
178}
179
180// GetInstances returns a nil map, as type parameters are not supported at this
181// Go version.
182func GetInstances(info *types.Info) map[*ast.Ident]Instance { return nil }
183
184// Context is a placeholder type, as type parameters are not supported at
185// this Go version.
186type Context struct{}
187
188// NewContext returns a placeholder Context instance.
189func NewContext() *Context {
190    return &Context{}
191}
192
193// Instantiate is unsupported on this Go version, and panics.
194func Instantiate(ctxt *Contexttyp types.Typetargs []types.Typevalidate bool) (types.Typeerror) {
195    unsupported()
196    return nilnil
197}
198
MembersX
TypeParam
Union.Term
IsMethodSet
Instance.TypeArgs
IndexListExpr
MarkImplicit
Term.Tilde
Instantiate.targs
TypeParamList.Len
IsImplicit
Term.Type.m
Term.String
NewContext
Instantiate.ctxt
NewTypeParam.constraint
NewSignatureType
ForSignature
Term.tilde
NewUnion.terms
Instance
InitInstanceInfo
unsupported
IndexListExpr.X
TypeParamList
NamedTypeArgs
Term.Tilde.m
Term.String.m
NewTerm.tilde
GetInstances
TypeParam.Obj
Term
Instantiate.validate
Union.Len
NewSignatureType.params
NewSignatureType.results
ForNamed
SetForNamed
Term.typ
Term.Type
TypeParamList.At
RecvTypeParams.sig
Union.Term.i
Instantiate
IndexListExpr.Rbrack
ForTypeSpec
ForFuncType
NewTypeParam.name
NewSignatureType.recv
Term.String.pre
TypeList.Len
NewTypeParam
SetTypeParamConstraint
SetTypeParamConstraint.constraint
NewSignatureType.variadic
RecvTypeParams
NamedTypeOrigin
NewUnion
Instance.Type
GetInstances.info
Instantiate.typ
IndexListExpr.Lbrack
TypeList.At
SetForNamed.tparams
NewTerm.typ
Context
TypeParam.Constraint
SetTypeParamConstraint.tparam
NewSignatureType.recvTypeParams
NewSignatureType.typeParams
NamedTypeOrigin.named
IndexListExpr.Indices
NewTerm
TypeParam.Index
TypeList
IsComparable
Union
Members
X