Debian Codegraph @

refactor/satisfy/find.go

raw symbols SCIP
1 // Copyright 2014 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 // Package satisfy inspects the type-checked ASTs of Go packages and
6 // reports the set of discovered type constraints of the form (lhs, rhs
7 // Type) where lhs is a non-trivial interface, rhs satisfies this
8 // interface, and this fact is necessary for the package to be
9 // well-typed.
10 //
11 // It requires well-typed inputs, and may panic otherwise.
12 //
13 // This package reimplements parts of the type checker. See
14 // https://go.dev/issue/70638 for a proposal to expose the the work
15 // already done by the type checker, which would make this package
16 // redundant.
17 package satisfy
18
19 // NOTES:
20 //
21 // We don't care about numeric conversions, so we don't descend into
22 // types or constant expressions. This is unsound because
23 // constant expressions can contain arbitrary statements, e.g.
24 // const x = len([1]func(){func() {
25 // ...
26 // }})
27 //
28 // Assignability conversions are possible in the following places:
29 // - in assignments y = x, y := x, var y = x.
30 // - from call argument types to formal parameter types
31 // - in append and delete calls
32 // - from return operands to result parameter types
33 // - in composite literal T{k:v}, from k and v to T's field/element/key type
34 // - in map[key] from key to the map's key type
35 // - in comparisons x==y and switch x { case y: }.
36 // - in explicit conversions T(x)
37 // - in sends ch <- x, from x to the channel element type
38 // - in type assertions x.(T) and switch x.(type) { case T: }
39 //
40 // The results of this pass provide information equivalent to the
41 // ssa.MakeInterface and ssa.ChangeInterface instructions.
42
43 import (
44 "fmt"
45 "go/ast"
46 "go/token"
47 "go/types"
48 "iter"
49
50 "golang.org/x/tools/go/types/typeutil"
51 "golang.org/x/tools/internal/typeparams"
52 )
53
54 // A Constraint records the fact that the RHS type does and must
55 // satisfy the LHS type, which is an interface.
56 // The names are suggestive of an assignment statement LHS = RHS.
57 //
58 // The constraint is implicitly universally quantified over any type
59 // parameters appearing within the two types.
60 type Constraint struct {
61 LHS, RHS types.Type
62 }
63
64 // A Finder inspects the type-checked ASTs of Go packages and
65 // accumulates the set of type constraints (x, y) such that x is
66 // assignable to y, y is an interface, and both x and y have methods.
67 //
68 // In other words, it returns the subset of the "implements" relation
69 // that is checked during compilation of a package. Refactoring tools
70 // will need to preserve at least this part of the relation to ensure
71 // continued compilation.
72 type Finder struct {
73 Result map[Constraint]bool
74 msetcache typeutil.MethodSetCache
75
76 // per-Find state
77 info *types.Info
78 sig *types.Signature
79 }
80
81 // Find inspects a single package, populating Result with its pairs of
82 // constrained types.
83 //
84 // The result is non-canonical and thus may contain duplicates (but this
85 // tends to preserves names of interface types better).
86 //
87 // The package must be free of type errors, and
88 // info.{Defs,Uses,Selections,Types} must have been populated by the
89 // type-checker.
90 func (f *Finder) Find(info *types.Info, files []*ast.File) {
91 if info.Defs == nil || info.Uses == nil || info.Selections == nil || info.Types == nil {
92 panic("Finder.Find: one of info.{Defs,Uses,Selections.Types} is not populated")
93 }
94 if f.Result == nil {
95 f.Result = make(map[Constraint]bool)
96 }
97
98 f.info = info
99 for _, file := range files {
100 for _, d := range file.Decls {
101 switch d := d.(type) {
102 case *ast.GenDecl:
103 if d.Tok == token.VAR { // ignore consts
104 for _, spec := range d.Specs {
105 f.valueSpec(spec.(*ast.ValueSpec))
106 }
107 }
108
109 case *ast.FuncDecl:
110 if d.Body != nil {
111 f.sig = f.info.Defs[d.Name].Type().(*types.Signature)
112 f.stmt(d.Body)
113 f.sig = nil
114 }
115 }
116 }
117 }
118 f.info = nil
119 }
120
121 var (
122 tInvalid = types.Typ[types.Invalid]
123 tUntypedBool = types.Typ[types.UntypedBool]
124 tUntypedNil = types.Typ[types.UntypedNil]
125 )
126
127 // exprN visits an expression in a multi-value context.
128 func (f *Finder) exprN(e ast.Expr) types.Type {
129 typ := f.info.Types[e].Type.(*types.Tuple)
130 switch e := e.(type) {
131 case *ast.ParenExpr:
132 return f.exprN(e.X)
133
134 case *ast.CallExpr:
135 // x, err := f(args)
136 if sig := hasUnderlyingTermOf[*types.Signature](f.expr(e.Fun)); sig != nil {
137 f.call(sig, e.Args)
138 }
139
140 case *ast.IndexExpr:
141 // y, ok := x[i]
142 x := f.expr(e.X)
143 if m := hasUnderlyingTermOf[*types.Map](x); m != nil {
144 f.assign(f.expr(e.Index), m.Key())
145 }
146
147 case *ast.TypeAssertExpr:
148 // y, ok := x.(T)
149 f.typeAssert(f.expr(e.X), typ.At(0).Type())
150
151 case *ast.UnaryExpr: // must be receive <-
152 // y, ok := <-x
153 f.expr(e.X)
154
155 default:
156 panic(e)
157 }
158 return typ
159 }
160
161 func (f *Finder) call(sig *types.Signature, args []ast.Expr) {
162 if len(args) == 0 {
163 return
164 }
165
166 // Ellipsis call? e.g. f(x, y, z...)
167 if _, ok := args[len(args)-1].(*ast.Ellipsis); ok {
168 for i, arg := range args {
169 // The final arg is a slice, and so is the final param.
170 f.assign(sig.Params().At(i).Type(), f.expr(arg))
171 }
172 return
173 }
174
175 var argtypes []types.Type
176
177 // Gather the effective actual parameter types.
178 if tuple, ok := f.info.Types[args[0]].Type.(*types.Tuple); ok {
179 // f(g()) call where g has multiple results?
180 f.expr(args[0])
181 // unpack the tuple
182 for v := range tuple.Variables() {
183 argtypes = append(argtypes, v.Type())
184 }
185 } else {
186 for _, arg := range args {
187 argtypes = append(argtypes, f.expr(arg))
188 }
189 }
190
191 // Assign the actuals to the formals.
192 if !sig.Variadic() {
193 for i, argtype := range argtypes {
194 f.assign(sig.Params().At(i).Type(), argtype)
195 }
196 } else {
197 // The first n-1 parameters are assigned normally.
198 nnormals := sig.Params().Len() - 1
199 for i, argtype := range argtypes[:nnormals] {
200 f.assign(sig.Params().At(i).Type(), argtype)
201 }
202 // Remaining args are assigned to elements of varargs slice.
203 tElem := sig.Params().At(nnormals).Type().(*types.Slice).Elem()
204 for i := nnormals; i < len(argtypes); i++ {
205 f.assign(tElem, argtypes[i])
206 }
207 }
208 }
209
210 // builtin visits the arguments of a builtin type with signature sig.
211 func (f *Finder) builtin(obj *types.Builtin, sig *types.Signature, args []ast.Expr) {
212 switch obj.Name() {
213 case "make", "new":
214 for i, arg := range args {
215 if i == 0 && f.info.Types[arg].IsType() {
216 continue // skip the type operand
217 }
218 f.expr(arg)
219 }
220
221 case "append":
222 s := f.expr(args[0])
223 if _, ok := args[len(args)-1].(*ast.Ellipsis); ok && len(args) == 2 {
224 // append(x, y...) including append([]byte, "foo"...)
225 f.expr(args[1])
226 } else {
227 // append(x, y, z)
228 if s := hasUnderlyingTermOf[*types.Slice](s); s != nil {
229 for _, arg := range args[1:] {
230 f.assign(s.Elem(), f.expr(arg))
231 }
232 }
233 }
234
235 case "delete":
236 m := f.expr(args[0])
237 k := f.expr(args[1])
238 if m := hasUnderlyingTermOf[*types.Map](m); m != nil {
239 f.assign(m.Key(), k)
240 }
241
242 default:
243 // ordinary call
244 f.call(sig, args)
245 }
246 }
247
248 func (f *Finder) extract(tuple types.Type, i int) types.Type {
249 if tuple, ok := tuple.(*types.Tuple); ok && i < tuple.Len() {
250 return tuple.At(i).Type()
251 }
252 return tInvalid
253 }
254
255 func (f *Finder) valueSpec(spec *ast.ValueSpec) {
256 var T types.Type
257 if spec.Type != nil {
258 T = f.info.Types[spec.Type].Type
259 }
260 switch len(spec.Values) {
261 case len(spec.Names): // e.g. var x, y = f(), g()
262 for _, value := range spec.Values {
263 v := f.expr(value)
264 if T != nil {
265 f.assign(T, v)
266 }
267 }
268
269 case 1: // e.g. var x, y = f()
270 tuple := f.exprN(spec.Values[0])
271 for i := range spec.Names {
272 if T != nil {
273 f.assign(T, f.extract(tuple, i))
274 }
275 }
276 }
277 }
278
279 // assign records pairs of distinct types that are related by
280 // assignability, where the left-hand side is an interface and both
281 // sides have methods.
282 //
283 // It should be called for all assignability checks, type assertions,
284 // explicit conversions and comparisons between two types, unless the
285 // types are uninteresting (e.g. lhs is a concrete type, or the empty
286 // interface; rhs has no methods).
287 func (f *Finder) assign(lhs, rhs types.Type) {
288 if types.Identical(lhs, rhs) {
289 return
290 }
291 if !types.IsInterface(lhs) {
292 return
293 }
294
295 if f.msetcache.MethodSet(lhs).Len() == 0 {
296 return
297 }
298 if f.msetcache.MethodSet(rhs).Len() == 0 {
299 return
300 }
301 // record the pair
302 f.Result[Constraint{lhs, rhs}] = true
303 }
304
305 // typeAssert must be called for each type assertion x.(T) where x has
306 // interface type I.
307 func (f *Finder) typeAssert(I, T types.Type) {
308 // Type assertions are slightly subtle, because they are allowed
309 // to be "impossible", e.g.
310 //
311 // var x interface{f()}
312 // _ = x.(interface{f()int}) // legal
313 //
314 // (In hindsight, the language spec should probably not have
315 // allowed this, but it's too late to fix now.)
316 //
317 // This means that a type assert from I to T isn't exactly a
318 // constraint that T is assignable to I, but for a refactoring
319 // tool it is a conditional constraint that, if T is assignable
320 // to I before a refactoring, it should remain so after.
321
322 if types.AssignableTo(T, I) {
323 f.assign(I, T)
324 }
325 }
326
327 // compare must be called for each comparison x==y.
328 func (f *Finder) compare(x, y types.Type) {
329 if types.AssignableTo(x, y) {
330 f.assign(y, x)
331 } else if types.AssignableTo(y, x) {
332 f.assign(x, y)
333 }
334 }
335
336 // expr visits a true expression (not a type or defining ident)
337 // and returns its type.
338 func (f *Finder) expr(e ast.Expr) types.Type {
339 tv := f.info.Types[e]
340 if tv.Value != nil {
341 return tv.Type // prune the descent for constants
342 }
343
344 // tv.Type may be nil for an ast.Ident.
345
346 switch e := e.(type) {
347 case *ast.BadExpr, *ast.BasicLit:
348 // no-op
349
350 case *ast.Ident:
351 // (referring idents only)
352 if obj, ok := f.info.Uses[e]; ok {
353 return obj.Type()
354 }
355 if e.Name == "_" { // e.g. "for _ = range x"
356 return tInvalid
357 }
358 panic("undefined ident: " + e.Name)
359
360 case *ast.Ellipsis:
361 if e.Elt != nil {
362 f.expr(e.Elt)
363 }
364
365 case *ast.FuncLit:
366 saved := f.sig
367 f.sig = tv.Type.(*types.Signature)
368 f.stmt(e.Body)
369 f.sig = saved
370
371 case *ast.CompositeLit:
372 for term := range terms(typeparams.Deref(tv.Type)) {
373 switch T := term.Underlying().(type) {
374 case *types.Struct:
375 for i, elem := range e.Elts {
376 if kv, ok := elem.(*ast.KeyValueExpr); ok {
377 f.assign(f.info.Uses[kv.Key.(*ast.Ident)].Type(), f.expr(kv.Value))
378 } else {
379 f.assign(T.Field(i).Type(), f.expr(elem))
380 }
381 }
382
383 case *types.Map:
384 for _, elem := range e.Elts {
385 elem := elem.(*ast.KeyValueExpr)
386 f.assign(T.Key(), f.expr(elem.Key))
387 f.assign(T.Elem(), f.expr(elem.Value))
388 }
389
390 case *types.Array, *types.Slice:
391 tElem := T.(interface{ Elem() types.Type }).Elem()
392 for _, elem := range e.Elts {
393 if kv, ok := elem.(*ast.KeyValueExpr); ok {
394 // ignore the key
395 f.assign(tElem, f.expr(kv.Value))
396 } else {
397 f.assign(tElem, f.expr(elem))
398 }
399 }
400 default:
401 panic(fmt.Sprintf("unexpected composite literal type %T: %v", tv.Type, tv.Type.String()))
402 }
403 }
404
405 case *ast.ParenExpr:
406 f.expr(e.X)
407
408 case *ast.SelectorExpr:
409 if seln, ok := f.info.Selections[e]; ok {
410 // If e.X is a type (e.g., e is interface{ m() }.m), don't visit it.
411 if seln.Kind() != types.MethodExpr {
412 f.expr(e.X)
413 }
414 } else {
415 return f.info.Uses[e.Sel].Type() // qualified identifier
416 }
417
418 case *ast.IndexExpr:
419 if instance(f.info, e.X) {
420 // f[T] or C[T] -- generic instantiation
421 } else {
422 // x[i] or m[k] -- index or lookup operation
423 x := f.expr(e.X)
424 i := f.expr(e.Index)
425 if m := hasUnderlyingTermOf[*types.Map](x); m != nil {
426 f.assign(m.Key(), i)
427 }
428 }
429
430 case *ast.IndexListExpr:
431 // f[X, Y] -- generic instantiation
432
433 case *ast.SliceExpr:
434 f.expr(e.X)
435 if e.Low != nil {
436 f.expr(e.Low)
437 }
438 if e.High != nil {
439 f.expr(e.High)
440 }
441 if e.Max != nil {
442 f.expr(e.Max)
443 }
444
445 case *ast.TypeAssertExpr:
446 x := f.expr(e.X)
447 f.typeAssert(x, f.info.Types[e.Type].Type)
448
449 case *ast.CallExpr:
450 if tvFun := f.info.Types[e.Fun]; tvFun.IsType() {
451 // conversion
452 arg0 := f.expr(e.Args[0])
453 f.assign(tvFun.Type, arg0)
454 } else {
455 // function call
456
457 // unsafe call. Treat calls to functions in unsafe like ordinary calls,
458 // except that their signature cannot be determined by their func obj.
459 // Without this special handling, f.expr(e.Fun) would fail below.
460 if s, ok := ast.Unparen(e.Fun).(*ast.SelectorExpr); ok {
461 if obj, ok := f.info.Uses[s.Sel].(*types.Builtin); ok && obj.Pkg().Path() == "unsafe" {
462 sig := f.info.Types[e.Fun].Type.(*types.Signature)
463 f.call(sig, e.Args)
464 return tv.Type
465 }
466 }
467
468 // builtin call
469 if id, ok := ast.Unparen(e.Fun).(*ast.Ident); ok {
470 if obj, ok := f.info.Uses[id].(*types.Builtin); ok {
471 sig := f.info.Types[id].Type.(*types.Signature)
472 f.builtin(obj, sig, e.Args)
473 return tv.Type
474 }
475 }
476
477 // ordinary call
478 if sig := hasUnderlyingTermOf[*types.Signature](f.expr(e.Fun)); sig != nil {
479 f.call(sig, e.Args)
480 }
481 }
482
483 case *ast.StarExpr:
484 f.expr(e.X)
485
486 case *ast.UnaryExpr:
487 f.expr(e.X)
488
489 case *ast.BinaryExpr:
490 x := f.expr(e.X)
491 y := f.expr(e.Y)
492 if e.Op == token.EQL || e.Op == token.NEQ {
493 f.compare(x, y)
494 }
495
496 case *ast.KeyValueExpr:
497 f.expr(e.Key)
498 f.expr(e.Value)
499
500 case *ast.ArrayType,
501 *ast.StructType,
502 *ast.FuncType,
503 *ast.InterfaceType,
504 *ast.MapType,
505 *ast.ChanType:
506 panic(e)
507 }
508
509 if tv.Type == nil {
510 panic(fmt.Sprintf("no type for %T", e))
511 }
512
513 return tv.Type
514 }
515
516 func (f *Finder) stmt(s ast.Stmt) {
517 switch s := s.(type) {
518 case *ast.BadStmt,
519 *ast.EmptyStmt,
520 *ast.BranchStmt:
521 // no-op
522
523 case *ast.DeclStmt:
524 d := s.Decl.(*ast.GenDecl)
525 if d.Tok == token.VAR { // ignore consts
526 for _, spec := range d.Specs {
527 f.valueSpec(spec.(*ast.ValueSpec))
528 }
529 }
530
531 case *ast.LabeledStmt:
532 f.stmt(s.Stmt)
533
534 case *ast.ExprStmt:
535 f.expr(s.X)
536
537 case *ast.SendStmt:
538 ch := f.expr(s.Chan)
539 val := f.expr(s.Value)
540 if c := hasUnderlyingTermOf[*types.Chan](ch); c != nil {
541 f.assign(c.Elem(), val)
542 }
543
544 case *ast.IncDecStmt:
545 f.expr(s.X)
546
547 case *ast.AssignStmt:
548 switch s.Tok {
549 case token.ASSIGN, token.DEFINE:
550 // y := x or y = x
551 var rhsTuple types.Type
552 if len(s.Lhs) != len(s.Rhs) {
553 rhsTuple = f.exprN(s.Rhs[0])
554 }
555 for i := range s.Lhs {
556 var lhs, rhs types.Type
557 if rhsTuple == nil {
558 rhs = f.expr(s.Rhs[i]) // 1:1 assignment
559 } else {
560 rhs = f.extract(rhsTuple, i) // n:1 assignment
561 }
562
563 if id, ok := s.Lhs[i].(*ast.Ident); ok {
564 if id.Name != "_" {
565 if obj, ok := f.info.Defs[id]; ok {
566 lhs = obj.Type() // definition
567 }
568 }
569 }
570 if lhs == nil {
571 lhs = f.expr(s.Lhs[i]) // assignment
572 }
573 f.assign(lhs, rhs)
574 }
575
576 default:
577 // y op= x
578 f.expr(s.Lhs[0])
579 f.expr(s.Rhs[0])
580 }
581
582 case *ast.GoStmt:
583 f.expr(s.Call)
584
585 case *ast.DeferStmt:
586 f.expr(s.Call)
587
588 case *ast.ReturnStmt:
589 formals := f.sig.Results()
590 switch len(s.Results) {
591 case formals.Len(): // 1:1
592 for i, result := range s.Results {
593 f.assign(formals.At(i).Type(), f.expr(result))
594 }
595
596 case 1: // n:1
597 tuple := f.exprN(s.Results[0])
598 for i := 0; i < formals.Len(); i++ {
599 f.assign(formals.At(i).Type(), f.extract(tuple, i))
600 }
601 }
602
603 case *ast.SelectStmt:
604 f.stmt(s.Body)
605
606 case *ast.BlockStmt:
607 for _, s := range s.List {
608 f.stmt(s)
609 }
610
611 case *ast.IfStmt:
612 if s.Init != nil {
613 f.stmt(s.Init)
614 }
615 f.expr(s.Cond)
616 f.stmt(s.Body)
617 if s.Else != nil {
618 f.stmt(s.Else)
619 }
620
621 case *ast.SwitchStmt:
622 if s.Init != nil {
623 f.stmt(s.Init)
624 }
625 var tag types.Type = tUntypedBool
626 if s.Tag != nil {
627 tag = f.expr(s.Tag)
628 }
629 for _, cc := range s.Body.List {
630 cc := cc.(*ast.CaseClause)
631 for _, cond := range cc.List {
632 f.compare(tag, f.info.Types[cond].Type)
633 }
634 for _, s := range cc.Body {
635 f.stmt(s)
636 }
637 }
638
639 case *ast.TypeSwitchStmt:
640 if s.Init != nil {
641 f.stmt(s.Init)
642 }
643 var I types.Type
644 switch ass := s.Assign.(type) {
645 case *ast.ExprStmt: // x.(type)
646 I = f.expr(ast.Unparen(ass.X).(*ast.TypeAssertExpr).X)
647 case *ast.AssignStmt: // y := x.(type)
648 I = f.expr(ast.Unparen(ass.Rhs[0]).(*ast.TypeAssertExpr).X)
649 }
650 for _, cc := range s.Body.List {
651 cc := cc.(*ast.CaseClause)
652 for _, cond := range cc.List {
653 tCase := f.info.Types[cond].Type
654 if tCase != tUntypedNil {
655 f.typeAssert(I, tCase)
656 }
657 }
658 for _, s := range cc.Body {
659 f.stmt(s)
660 }
661 }
662
663 case *ast.CommClause:
664 if s.Comm != nil {
665 f.stmt(s.Comm)
666 }
667 for _, s := range s.Body {
668 f.stmt(s)
669 }
670
671 case *ast.ForStmt:
672 if s.Init != nil {
673 f.stmt(s.Init)
674 }
675 if s.Cond != nil {
676 f.expr(s.Cond)
677 }
678 if s.Post != nil {
679 f.stmt(s.Post)
680 }
681 f.stmt(s.Body)
682
683 case *ast.RangeStmt:
684 x := f.expr(s.X)
685 // No conversions are involved when Tok==DEFINE.
686 if s.Tok == token.ASSIGN {
687 if s.Key != nil {
688 k := f.expr(s.Key)
689 // Keys of array, *array, slice, string aren't interesting
690 // since the RHS key type is just an int.
691 for term := range terms(x) {
692 switch term := term.Underlying().(type) {
693 case *types.Chan:
694 f.assign(k, term.Elem())
695 case *types.Map:
696 f.assign(k, term.Key())
697 }
698 }
699 }
700 if s.Value != nil {
701 val := f.expr(s.Value)
702 // Values of type strings aren't interesting because
703 // the RHS value type is just a rune.
704 for term := range terms(x) {
705 switch term := term.Underlying().(type) {
706 case *types.Pointer:
707 for term := range terms(term.Elem()) {
708 if array, ok := term.Underlying().(*types.Array); ok {
709 f.assign(val, array.Elem())
710 }
711 }
712 case *types.Array:
713 f.assign(val, term.Elem())
714 case *types.Map:
715 f.assign(val, term.Elem())
716 case *types.Slice:
717 f.assign(val, term.Elem())
718 }
719 }
720 }
721 }
722 f.stmt(s.Body)
723
724 default:
725 panic(s)
726 }
727 }
728
729 // -- Plundered from golang.org/x/tools/go/ssa -----------------
730
731 func instance(info *types.Info, expr ast.Expr) bool {
732 var id *ast.Ident
733 switch x := expr.(type) {
734 case *ast.Ident:
735 id = x
736 case *ast.SelectorExpr:
737 id = x.Sel
738 default:
739 return false
740 }
741 _, ok := info.Instances[id]
742 return ok
743 }
744
745 // -- type-set helpers --
746
747 // hasUnderlyingTermOf reports whether terms(t) contains a
748 // term whose underlying type has top-level type constructor T
749 // (e.g. *types.Map for a map).
750 // If so, it returns an arbitrary one.
751 // Otherwise it returns the zero value (nil).
752 //
753 // This arbitrariness would be a hazard if this function were
754 // published more widely, but in this package it is used only for
755 // structural operations (indexing, etc) that require the relevant
756 // component types to be identical across all terms in the operand's
757 // type set.
758 func hasUnderlyingTermOf[T types.Type](t types.Type) T {
759 for term := range terms(t) {
760 if under, ok := term.Underlying().(T); ok {
761 return under
762 }
763 }
764 return *new(T) // e.g. (*types.Map)(nil)
765 }
766
767 // terms returns the sequence of terms in the type set of t.
768 // The boolean reports whether the term has a tilde.
769 // TODO(adonovan): replace with solution to go.dev/issue/61013.
770 func terms(t types.Type) iter.Seq2[types.Type, bool] {
771 return func(yield func(types.Type, bool) bool) {
772 if terms, err := typeparams.NormalTerms(t); err == nil {
773 for _, term := range terms {
774 if !yield(term.Type(), term.Tilde()) {
775 break
776 }
777 }
778 }
779 }
780 }