OXIESEC PANEL
- Current Dir:
/
/
opt
/
golang
/
1.19.4
/
src
/
go
/
types
Server IP: 2a02:4780:11:1084:0:327f:3464:10
Upload:
Create Dir:
Name
Size
Modified
Perms
š
..
-
12/01/2022 06:13:56 PM
rwxr-xr-x
š
api.go
17.05 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
api_test.go
81.16 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
array.go
802 bytes
12/01/2022 06:12:58 PM
rw-r--r--
š
assignments.go
12.86 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
basic.go
1.48 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
builtins.go
24.28 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
builtins_test.go
9.7 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
call.go
22.29 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
chan.go
909 bytes
12/01/2022 06:12:58 PM
rw-r--r--
š
check.go
17.32 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
check_test.go
12.11 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
context.go
4.34 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
context_test.go
2.33 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
conversions.go
8.28 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
decl.go
28.77 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
errorcodes.go
31.51 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
errorcodes_test.go
4.95 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
errors.go
9.87 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
errors_test.go
1 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
eval.go
3.05 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
eval_test.go
7.4 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
example_test.go
9.03 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
expr.go
51.97 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
exprstring.go
4.81 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
exprstring_test.go
2.36 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
gccgosizes.go
1.02 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
gotype.go
8.33 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
hilbert_test.go
3.61 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
index.go
11.03 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
infer.go
25.18 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
initorder.go
9.48 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
instantiate.go
9.94 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
instantiate_test.go
6.02 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
interface.go
8.08 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
issues_test.go
17.49 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
labels.go
7.17 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
lookup.go
16.93 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
main_test.go
335 bytes
12/01/2022 06:12:58 PM
rw-r--r--
š
map.go
658 bytes
12/01/2022 06:12:58 PM
rw-r--r--
š
methodset.go
6.75 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
methodset_test.go
5.75 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
mono.go
9.05 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
mono_test.go
2.63 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
named.go
22.37 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
named_test.go
2.69 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
object.go
17.92 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
object_test.go
5.21 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
objset.go
927 bytes
12/01/2022 06:12:58 PM
rw-r--r--
š
operand.go
10 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
package.go
2.38 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
pointer.go
634 bytes
12/01/2022 06:12:58 PM
rw-r--r--
š
predicates.go
14.71 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
resolver.go
24.38 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
resolver_test.go
4.58 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
return.go
4.21 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
scope.go
9.33 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
selection.go
3.99 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
self_test.go
2.57 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
signature.go
12.49 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
sizeof_test.go
1.26 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
sizes.go
7.56 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
sizes_test.go
3.33 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
slice.go
576 bytes
12/01/2022 06:12:58 PM
rw-r--r--
š
stdlib_test.go
9.45 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
stmt.go
26.17 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
struct.go
6.04 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
subst.go
10.76 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
termlist.go
3.68 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
termlist_test.go
7.18 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
testdata
-
12/01/2022 06:13:56 PM
rwxr-xr-x
š
token_test.go
1.21 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
tuple.go
928 bytes
12/01/2022 06:12:58 PM
rw-r--r--
š
type.go
2.92 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
typelists.go
1.84 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
typeparam.go
4.74 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
typeset.go
14.22 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
typeset_test.go
2.34 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
typestring.go
10.64 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
typestring_test.go
4.21 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
typeterm.go
3.52 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
typeterm_test.go
5.1 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
typexpr.go
14.64 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
unify.go
18.35 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
union.go
6.22 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
universe.go
7.66 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
validtype.go
7.77 KB
12/01/2022 06:12:58 PM
rw-r--r--
š
version.go
2.2 KB
12/01/2022 06:12:58 PM
rw-r--r--
Editing: validtype.go
Close
// Copyright 2022 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package types // validType verifies that the given type does not "expand" indefinitely // producing a cycle in the type graph. // (Cycles involving alias types, as in "type A = [10]A" are detected // earlier, via the objDecl cycle detection mechanism.) func (check *Checker) validType(typ *Named) { check.validType0(typ, nil, nil) } // validType0 checks if the given type is valid. If typ is a type parameter // its value is looked up in the type argument list of the instantiated // (enclosing) type, if it exists. Otherwise the type parameter must be from // an enclosing function and can be ignored. // The nest list describes the stack (the "nest in memory") of types which // contain (or embed in the case of interfaces) other types. For instance, a // struct named S which contains a field of named type F contains (the memory // of) F in S, leading to the nest S->F. If a type appears in its own nest // (say S->F->S) we have an invalid recursive type. The path list is the full // path of named types in a cycle, it is only needed for error reporting. func (check *Checker) validType0(typ Type, nest, path []*Named) bool { switch t := typ.(type) { case nil: // We should never see a nil type but be conservative and panic // only in debug mode. if debug { panic("validType0(nil)") } case *Array: return check.validType0(t.elem, nest, path) case *Struct: for _, f := range t.fields { if !check.validType0(f.typ, nest, path) { return false } } case *Union: for _, t := range t.terms { if !check.validType0(t.typ, nest, path) { return false } } case *Interface: for _, etyp := range t.embeddeds { if !check.validType0(etyp, nest, path) { return false } } case *Named: // Exit early if we already know t is valid. // This is purely an optimization but it prevents excessive computation // times in pathological cases such as testdata/fixedbugs/issue6977.go. // (Note: The valids map could also be allocated locally, once for each // validType call.) if check.valids.lookup(t) != nil { break } // Don't report a 2nd error if we already know the type is invalid // (e.g., if a cycle was detected earlier, via under). // Note: ensure that t.orig is fully resolved by calling Underlying(). if t.Underlying() == Typ[Invalid] { return false } // If the current type t is also found in nest, (the memory of) t is // embedded in itself, indicating an invalid recursive type. for _, e := range nest { if Identical(e, t) { // t cannot be in an imported package otherwise that package // would have reported a type cycle and couldn't have been // imported in the first place. assert(t.obj.pkg == check.pkg) t.underlying = Typ[Invalid] // t is in the current package (no race possibility) // Find the starting point of the cycle and report it. // Because each type in nest must also appear in path (see invariant below), // type t must be in path since it was found in nest. But not every type in path // is in nest. Specifically t may appear in path with an earlier index than the // index of t in nest. Search again. for start, p := range path { if Identical(p, t) { check.cycleError(makeObjList(path[start:])) return false } } panic("cycle start not found") } } // No cycle was found. Check the RHS of t. // Every type added to nest is also added to path; thus every type that is in nest // must also be in path (invariant). But not every type in path is in nest, since // nest may be pruned (see below, *TypeParam case). if !check.validType0(t.Origin().fromRHS, append(nest, t), append(path, t)) { return false } check.valids.add(t) // t is valid case *TypeParam: // A type parameter stands for the type (argument) it was instantiated with. // Check the corresponding type argument for validity if we are in an // instantiated type. if len(nest) > 0 { inst := nest[len(nest)-1] // the type instance // Find the corresponding type argument for the type parameter // and proceed with checking that type argument. for i, tparam := range inst.TypeParams().list() { // The type parameter and type argument lists should // match in length but be careful in case of errors. if t == tparam && i < inst.TypeArgs().Len() { targ := inst.TypeArgs().At(i) // The type argument must be valid in the enclosing // type (where inst was instantiated), hence we must // check targ's validity in the type nest excluding // the current (instantiated) type (see the example // at the end of this file). // For error reporting we keep the full path. return check.validType0(targ, nest[:len(nest)-1], path) } } } } return true } // makeObjList returns the list of type name objects for the given // list of named types. func makeObjList(tlist []*Named) []Object { olist := make([]Object, len(tlist)) for i, t := range tlist { olist[i] = t.obj } return olist } // Here is an example illustrating why we need to exclude the // instantiated type from nest when evaluating the validity of // a type parameter. Given the declarations // // var _ A[A[string]] // // type A[P any] struct { _ B[P] } // type B[P any] struct { _ P } // // we want to determine if the type A[A[string]] is valid. // We start evaluating A[A[string]] outside any type nest: // // A[A[string]] // nest = // path = // // The RHS of A is now evaluated in the A[A[string]] nest: // // struct{_ B[Pā]} // nest = A[A[string]] // path = A[A[string]] // // The struct has a single field of type B[Pā] with which // we continue: // // B[Pā] // nest = A[A[string]] // path = A[A[string]] // // struct{_ Pā} // nest = A[A[string]]->B[P] // path = A[A[string]]->B[P] // // Eventutally we reach the type parameter P of type B (Pā): // // Pā // nest = A[A[string]]->B[P] // path = A[A[string]]->B[P] // // The type argument for P of B is the type parameter P of A (Pā). // It must be evaluated in the type nest that existed when B was // instantiated: // // Pā // nest = A[A[string]] <== type nest at B's instantiation time // path = A[A[string]]->B[P] // // If we'd use the current nest it would correspond to the path // which will be wrong as we will see shortly. P's type argument // is A[string], which again must be evaluated in the type nest // that existed when A was instantiated with A[string]. That type // nest is empty: // // A[string] // nest = <== type nest at A's instantiation time // path = A[A[string]]->B[P] // // Evaluation then proceeds as before for A[string]: // // struct{_ B[Pā]} // nest = A[string] // path = A[A[string]]->B[P]->A[string] // // Now we reach B[P] again. If we had not adjusted nest, it would // correspond to path, and we would find B[P] in nest, indicating // a cycle, which would clearly be wrong since there's no cycle in // A[string]: // // B[Pā] // nest = A[string] // path = A[A[string]]->B[P]->A[string] <== path contains B[P]! // // But because we use the correct type nest, evaluation proceeds without // errors and we get the evaluation sequence: // // struct{_ Pā} // nest = A[string]->B[P] // path = A[A[string]]->B[P]->A[string]->B[P] // Pā // nest = A[string]->B[P] // path = A[A[string]]->B[P]->A[string]->B[P] // Pā // nest = A[string] // path = A[A[string]]->B[P]->A[string]->B[P] // string // nest = // path = A[A[string]]->B[P]->A[string]->B[P] // // At this point we're done and A[A[string]] and is valid.