Source file
src/go/types/call.go
1
2
3
4
5
6
7 package types
8
9 import (
10 "go/ast"
11 "go/internal/typeparams"
12 "go/token"
13 . "internal/types/errors"
14 "strings"
15 )
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 func (check *Checker) funcInst(T *target, pos token.Pos, x *operand, ix *typeparams.IndexExpr, infer bool) ([]Type, []ast.Expr) {
37 assert(T != nil || ix != nil)
38
39 var instErrPos positioner
40 if ix != nil {
41 instErrPos = inNode(ix.Orig, ix.Lbrack)
42 x.expr = ix.Orig
43 } else {
44 instErrPos = atPos(pos)
45 }
46 versionErr := !check.verifyVersionf(instErrPos, go1_18, "function instantiation")
47
48
49 var targs []Type
50 var xlist []ast.Expr
51 if ix != nil {
52 xlist = ix.Indices
53 targs = check.typeList(xlist)
54 if targs == nil {
55 x.mode = invalid
56 return nil, nil
57 }
58 assert(len(targs) == len(xlist))
59 }
60
61
62
63
64 sig := x.typ.(*Signature)
65 got, want := len(targs), sig.TypeParams().Len()
66 if got > want {
67
68 check.errorf(ix.Indices[got-1], WrongTypeArgCount, "got %d type arguments but want %d", got, want)
69 x.mode = invalid
70 return nil, nil
71 }
72
73 if got < want {
74 if !infer {
75 return targs, xlist
76 }
77
78
79
80
81
82
83
84
85
86
87
88 var args []*operand
89 var params []*Var
90 var reverse bool
91 if T != nil && sig.tparams != nil {
92 if !versionErr && !check.allowVersion(instErrPos, go1_21) {
93 if ix != nil {
94 check.versionErrorf(instErrPos, go1_21, "partially instantiated function in assignment")
95 } else {
96 check.versionErrorf(instErrPos, go1_21, "implicitly instantiated function in assignment")
97 }
98 }
99 gsig := NewSignatureType(nil, nil, nil, sig.params, sig.results, sig.variadic)
100 params = []*Var{NewVar(x.Pos(), check.pkg, "", gsig)}
101
102
103
104 expr := ast.NewIdent(T.desc)
105 expr.NamePos = x.Pos()
106 args = []*operand{{mode: value, expr: expr, typ: T.sig}}
107 reverse = true
108 }
109
110
111
112 tparams, params2 := check.renameTParams(pos, sig.TypeParams().list(), NewTuple(params...))
113
114 err := check.newError(CannotInferTypeArgs)
115 targs = check.infer(atPos(pos), tparams, targs, params2.(*Tuple), args, reverse, err)
116 if targs == nil {
117 if !err.empty() {
118 err.report()
119 }
120 x.mode = invalid
121 return nil, nil
122 }
123 got = len(targs)
124 }
125 assert(got == want)
126
127
128 sig = check.instantiateSignature(x.Pos(), x.expr, sig, targs, xlist)
129 x.typ = sig
130 x.mode = value
131 return nil, nil
132 }
133
134 func (check *Checker) instantiateSignature(pos token.Pos, expr ast.Expr, typ *Signature, targs []Type, xlist []ast.Expr) (res *Signature) {
135 assert(check != nil)
136 assert(len(targs) == typ.TypeParams().Len())
137
138 if check.conf._Trace {
139 check.trace(pos, "-- instantiating signature %s with %s", typ, targs)
140 check.indent++
141 defer func() {
142 check.indent--
143 check.trace(pos, "=> %s (under = %s)", res, res.Underlying())
144 }()
145 }
146
147 inst := check.instance(pos, typ, targs, nil, check.context()).(*Signature)
148 assert(inst.TypeParams().Len() == 0)
149 check.recordInstance(expr, targs, inst)
150 assert(len(xlist) <= len(targs))
151
152
153 check.later(func() {
154 tparams := typ.TypeParams().list()
155 if i, err := check.verify(pos, tparams, targs, check.context()); err != nil {
156
157 pos := pos
158 if i < len(xlist) {
159 pos = xlist[i].Pos()
160 }
161 check.softErrorf(atPos(pos), InvalidTypeArg, "%s", err)
162 } else {
163 check.mono.recordInstance(check.pkg, pos, tparams, targs, xlist)
164 }
165 }).describef(atPos(pos), "verify instantiation")
166
167 return inst
168 }
169
170 func (check *Checker) callExpr(x *operand, call *ast.CallExpr) exprKind {
171 ix := typeparams.UnpackIndexExpr(call.Fun)
172 if ix != nil {
173 if check.indexExpr(x, ix) {
174
175
176
177 assert(x.mode == value)
178 } else {
179 ix = nil
180 }
181 x.expr = call.Fun
182 check.record(x)
183 } else {
184 check.exprOrType(x, call.Fun, true)
185 }
186
187
188 switch x.mode {
189 case invalid:
190 check.use(call.Args...)
191 x.expr = call
192 return statement
193
194 case typexpr:
195
196 check.nonGeneric(nil, x)
197 if x.mode == invalid {
198 return conversion
199 }
200 T := x.typ
201 x.mode = invalid
202 switch n := len(call.Args); n {
203 case 0:
204 check.errorf(inNode(call, call.Rparen), WrongArgCount, "missing argument in conversion to %s", T)
205 case 1:
206 check.expr(nil, x, call.Args[0])
207 if x.mode != invalid {
208 if hasDots(call) {
209 check.errorf(call.Args[0], BadDotDotDotSyntax, "invalid use of ... in conversion to %s", T)
210 break
211 }
212 if t, _ := under(T).(*Interface); t != nil && !isTypeParam(T) {
213 if !t.IsMethodSet() {
214 check.errorf(call, MisplacedConstraintIface, "cannot use interface %s in conversion (contains specific type constraints or is comparable)", T)
215 break
216 }
217 }
218 check.conversion(x, T)
219 }
220 default:
221 check.use(call.Args...)
222 check.errorf(call.Args[n-1], WrongArgCount, "too many arguments in conversion to %s", T)
223 }
224 x.expr = call
225 return conversion
226
227 case builtin:
228
229 id := x.id
230 if !check.builtin(x, call, id) {
231 x.mode = invalid
232 }
233 x.expr = call
234
235 if x.mode != invalid && x.mode != constant_ {
236 check.hasCallOrRecv = true
237 }
238 return predeclaredFuncs[id].kind
239 }
240
241
242
243 cgocall := x.mode == cgofunc
244
245
246 sig, _ := coreType(x.typ).(*Signature)
247 if sig == nil {
248 check.errorf(x, InvalidCall, invalidOp+"cannot call non-function %s", x)
249 x.mode = invalid
250 x.expr = call
251 return statement
252 }
253
254
255 wasGeneric := sig.TypeParams().Len() > 0
256
257
258 var xlist []ast.Expr
259 var targs []Type
260 if ix != nil {
261 xlist = ix.Indices
262 targs = check.typeList(xlist)
263 if targs == nil {
264 check.use(call.Args...)
265 x.mode = invalid
266 x.expr = call
267 return statement
268 }
269 assert(len(targs) == len(xlist))
270
271
272 got, want := len(targs), sig.TypeParams().Len()
273 if got > want {
274 check.errorf(xlist[want], WrongTypeArgCount, "got %d type arguments but want %d", got, want)
275 check.use(call.Args...)
276 x.mode = invalid
277 x.expr = call
278 return statement
279 }
280
281
282
283
284
285
286 if got == want && want > 0 {
287 check.verifyVersionf(atPos(ix.Lbrack), go1_18, "function instantiation")
288 sig = check.instantiateSignature(ix.Pos(), ix.Orig, sig, targs, xlist)
289
290
291 targs = nil
292 xlist = nil
293 }
294 }
295
296
297 args, atargs, atxlist := check.genericExprList(call.Args)
298 sig = check.arguments(call, sig, targs, xlist, args, atargs, atxlist)
299
300 if wasGeneric && sig.TypeParams().Len() == 0 {
301
302 check.recordTypeAndValue(call.Fun, value, sig, nil)
303 }
304
305
306 switch sig.results.Len() {
307 case 0:
308 x.mode = novalue
309 case 1:
310 if cgocall {
311 x.mode = commaerr
312 } else {
313 x.mode = value
314 }
315 x.typ = sig.results.vars[0].typ
316 default:
317 x.mode = value
318 x.typ = sig.results
319 }
320 x.expr = call
321 check.hasCallOrRecv = true
322
323
324
325 if x.mode == value && sig.TypeParams().Len() > 0 && isParameterized(sig.TypeParams().list(), x.typ) {
326 x.mode = invalid
327 }
328
329 return statement
330 }
331
332
333
334 func (check *Checker) exprList(elist []ast.Expr) (xlist []*operand) {
335 if n := len(elist); n == 1 {
336 xlist, _ = check.multiExpr(elist[0], false)
337 } else if n > 1 {
338
339 xlist = make([]*operand, n)
340 for i, e := range elist {
341 var x operand
342 check.expr(nil, &x, e)
343 xlist[i] = &x
344 }
345 }
346 return
347 }
348
349
350
351
352
353
354
355
356 func (check *Checker) genericExprList(elist []ast.Expr) (resList []*operand, targsList [][]Type, xlistList [][]ast.Expr) {
357 if debug {
358 defer func() {
359
360 assert(len(targsList) == len(xlistList))
361
362 for i, x := range resList {
363 if i < len(targsList) {
364 if n := len(targsList[i]); n > 0 {
365
366 assert(n < x.typ.(*Signature).TypeParams().Len())
367 }
368 }
369 }
370 }()
371 }
372
373
374
375 infer := true
376 n := len(elist)
377 if n > 0 && check.allowVersion(elist[0], go1_21) {
378 infer = false
379 }
380
381 if n == 1 {
382
383 e := elist[0]
384 var x operand
385 if ix := typeparams.UnpackIndexExpr(e); ix != nil && check.indexExpr(&x, ix) {
386
387 targs, xlist := check.funcInst(nil, x.Pos(), &x, ix, infer)
388 if targs != nil {
389
390 targsList = [][]Type{targs}
391 xlistList = [][]ast.Expr{xlist}
392
393 x.expr = ix.Orig
394 } else {
395
396
397 check.record(&x)
398 }
399 resList = []*operand{&x}
400 } else {
401
402 check.rawExpr(nil, &x, e, nil, true)
403 check.exclude(&x, 1<<novalue|1<<builtin|1<<typexpr)
404 if t, ok := x.typ.(*Tuple); ok && x.mode != invalid {
405
406 resList = make([]*operand, t.Len())
407 for i, v := range t.vars {
408 resList[i] = &operand{mode: value, expr: e, typ: v.typ}
409 }
410 } else {
411
412 resList = []*operand{&x}
413 }
414 }
415 } else if n > 1 {
416
417 resList = make([]*operand, n)
418 targsList = make([][]Type, n)
419 xlistList = make([][]ast.Expr, n)
420 for i, e := range elist {
421 var x operand
422 if ix := typeparams.UnpackIndexExpr(e); ix != nil && check.indexExpr(&x, ix) {
423
424 targs, xlist := check.funcInst(nil, x.Pos(), &x, ix, infer)
425 if targs != nil {
426
427 targsList[i] = targs
428 xlistList[i] = xlist
429
430 x.expr = ix.Orig
431 } else {
432
433
434 check.record(&x)
435 }
436 } else {
437
438 check.genericExpr(&x, e)
439 }
440 resList[i] = &x
441 }
442 }
443
444 return
445 }
446
447
448
449
450
451
452
453
454
455
456
457
458
459 func (check *Checker) arguments(call *ast.CallExpr, sig *Signature, targs []Type, xlist []ast.Expr, args []*operand, atargs [][]Type, atxlist [][]ast.Expr) (rsig *Signature) {
460 rsig = sig
461
462
463
464
465
466
467
468
469
470
471 nargs := len(args)
472 npars := sig.params.Len()
473 ddd := hasDots(call)
474
475
476 sigParams := sig.params
477 adjusted := false
478 if sig.variadic {
479 if ddd {
480
481 if len(call.Args) == 1 && nargs > 1 {
482
483 check.errorf(inNode(call, call.Ellipsis), InvalidDotDotDot, "cannot use ... with %d-valued %s", nargs, call.Args[0])
484 return
485 }
486 } else {
487
488 if nargs >= npars-1 {
489
490
491
492 vars := make([]*Var, npars-1)
493 copy(vars, sig.params.vars)
494 last := sig.params.vars[npars-1]
495 typ := last.typ.(*Slice).elem
496 for len(vars) < nargs {
497 vars = append(vars, NewParam(last.pos, last.pkg, last.name, typ))
498 }
499 sigParams = NewTuple(vars...)
500 adjusted = true
501 npars = nargs
502 } else {
503
504 npars--
505 }
506 }
507 } else {
508 if ddd {
509
510 check.errorf(inNode(call, call.Ellipsis), NonVariadicDotDotDot, "cannot use ... in call to non-variadic %s", call.Fun)
511 return
512 }
513
514 }
515
516
517 if nargs != npars {
518 var at positioner = call
519 qualifier := "not enough"
520 if nargs > npars {
521 at = args[npars].expr
522 qualifier = "too many"
523 } else {
524 at = atPos(call.Rparen)
525 }
526
527 var params []*Var
528 if sig.params != nil {
529 params = sig.params.vars
530 }
531 err := check.newError(WrongArgCount)
532 err.addf(at, "%s arguments in call to %s", qualifier, call.Fun)
533 err.addf(noposn, "have %s", check.typesSummary(operandTypes(args), false))
534 err.addf(noposn, "want %s", check.typesSummary(varTypes(params), sig.variadic))
535 err.report()
536 return
537 }
538
539
540 var tparams []*TypeParam
541
542
543 n := sig.TypeParams().Len()
544 if n > 0 {
545 if !check.allowVersion(call, go1_18) {
546 switch call.Fun.(type) {
547 case *ast.IndexExpr, *ast.IndexListExpr:
548 ix := typeparams.UnpackIndexExpr(call.Fun)
549 check.versionErrorf(inNode(call.Fun, ix.Lbrack), go1_18, "function instantiation")
550 default:
551 check.versionErrorf(inNode(call, call.Lparen), go1_18, "implicit function instantiation")
552 }
553 }
554
555 var tmp Type
556 tparams, tmp = check.renameTParams(call.Pos(), sig.TypeParams().list(), sigParams)
557 sigParams = tmp.(*Tuple)
558
559 for len(targs) < len(tparams) {
560 targs = append(targs, nil)
561 }
562 }
563 assert(len(tparams) == len(targs))
564
565
566 var genericArgs []int
567 if enableReverseTypeInference {
568 for i, arg := range args {
569
570 if asig, _ := arg.typ.(*Signature); asig != nil && asig.TypeParams().Len() > 0 {
571
572
573
574
575
576
577 asig = clone(asig)
578
579
580
581
582 atparams, tmp := check.renameTParams(call.Pos(), asig.TypeParams().list(), asig)
583 asig = tmp.(*Signature)
584 asig.tparams = &TypeParamList{atparams}
585 arg.typ = asig
586 tparams = append(tparams, atparams...)
587
588 if i < len(atargs) {
589 targs = append(targs, atargs[i]...)
590 }
591
592 for len(targs) < len(tparams) {
593 targs = append(targs, nil)
594 }
595 genericArgs = append(genericArgs, i)
596 }
597 }
598 }
599 assert(len(tparams) == len(targs))
600
601
602 _ = len(genericArgs) > 0 && check.verifyVersionf(args[genericArgs[0]], go1_21, "implicitly instantiated function as argument")
603
604
605
606
607
608
609 if len(tparams) > 0 {
610 err := check.newError(CannotInferTypeArgs)
611 targs = check.infer(call, tparams, targs, sigParams, args, false, err)
612 if targs == nil {
613
614
615
616
617 if !err.empty() {
618 check.errorf(err.posn(), CannotInferTypeArgs, "in call to %s, %s", call.Fun, err.msg())
619 }
620 return
621 }
622
623
624 if n > 0 {
625 rsig = check.instantiateSignature(call.Pos(), call.Fun, sig, targs[:n], xlist)
626
627
628
629 if adjusted {
630 sigParams = check.subst(call.Pos(), sigParams, makeSubstMap(tparams[:n], targs[:n]), nil, check.context()).(*Tuple)
631 } else {
632 sigParams = rsig.params
633 }
634 }
635
636
637 j := n
638 for _, i := range genericArgs {
639 arg := args[i]
640 asig := arg.typ.(*Signature)
641 k := j + asig.TypeParams().Len()
642
643 arg.typ = check.instantiateSignature(call.Pos(), arg.expr, asig, targs[j:k], nil)
644 check.record(arg)
645 j = k
646 }
647 }
648
649
650 if len(args) > 0 {
651 context := check.sprintf("argument to %s", call.Fun)
652 for i, a := range args {
653 check.assignment(a, sigParams.vars[i].typ, context)
654 }
655 }
656
657 return
658 }
659
660 var cgoPrefixes = [...]string{
661 "_Ciconst_",
662 "_Cfconst_",
663 "_Csconst_",
664 "_Ctype_",
665 "_Cvar_",
666 "_Cfpvar_fp_",
667 "_Cfunc_",
668 "_Cmacro_",
669 }
670
671 func (check *Checker) selector(x *operand, e *ast.SelectorExpr, def *TypeName, wantType bool) {
672
673 var (
674 obj Object
675 index []int
676 indirect bool
677 )
678
679 sel := e.Sel.Name
680
681
682
683
684 if ident, ok := e.X.(*ast.Ident); ok {
685 obj := check.lookup(ident.Name)
686 if pname, _ := obj.(*PkgName); pname != nil {
687 assert(pname.pkg == check.pkg)
688 check.recordUse(ident, pname)
689 pname.used = true
690 pkg := pname.imported
691
692 var exp Object
693 funcMode := value
694 if pkg.cgo {
695
696
697
698 if sel == "malloc" {
699 sel = "_CMalloc"
700 } else {
701 funcMode = cgofunc
702 }
703 for _, prefix := range cgoPrefixes {
704
705
706 _, exp = check.scope.LookupParent(prefix+sel, check.pos)
707 if exp != nil {
708 break
709 }
710 }
711 if exp == nil {
712 check.errorf(e.Sel, UndeclaredImportedName, "undefined: %s", ast.Expr(e))
713 goto Error
714 }
715 check.objDecl(exp, nil)
716 } else {
717 exp = pkg.scope.Lookup(sel)
718 if exp == nil {
719 if !pkg.fake {
720 check.errorf(e.Sel, UndeclaredImportedName, "undefined: %s", ast.Expr(e))
721 }
722 goto Error
723 }
724 if !exp.Exported() {
725 check.errorf(e.Sel, UnexportedName, "name %s not exported by package %s", sel, pkg.name)
726
727 }
728 }
729 check.recordUse(e.Sel, exp)
730
731
732
733 switch exp := exp.(type) {
734 case *Const:
735 assert(exp.Val() != nil)
736 x.mode = constant_
737 x.typ = exp.typ
738 x.val = exp.val
739 case *TypeName:
740 x.mode = typexpr
741 x.typ = exp.typ
742 case *Var:
743 x.mode = variable
744 x.typ = exp.typ
745 if pkg.cgo && strings.HasPrefix(exp.name, "_Cvar_") {
746 x.typ = x.typ.(*Pointer).base
747 }
748 case *Func:
749 x.mode = funcMode
750 x.typ = exp.typ
751 if pkg.cgo && strings.HasPrefix(exp.name, "_Cmacro_") {
752 x.mode = value
753 x.typ = x.typ.(*Signature).results.vars[0].typ
754 }
755 case *Builtin:
756 x.mode = builtin
757 x.typ = exp.typ
758 x.id = exp.id
759 default:
760 check.dump("%v: unexpected object %v", e.Sel.Pos(), exp)
761 panic("unreachable")
762 }
763 x.expr = e
764 return
765 }
766 }
767
768 check.exprOrType(x, e.X, false)
769 switch x.mode {
770 case typexpr:
771
772 if def != nil && def.typ == x.typ {
773 check.cycleError([]Object{def}, 0)
774 goto Error
775 }
776 case builtin:
777
778 check.errorf(e.Sel, UncalledBuiltin, "cannot select on %s", x)
779 goto Error
780 case invalid:
781 goto Error
782 }
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798 if wantType {
799 check.errorf(e.Sel, NotAType, "%s is not a type", ast.Expr(e))
800 goto Error
801 }
802
803 obj, index, indirect = lookupFieldOrMethod(x.typ, x.mode == variable, check.pkg, sel, false)
804 if obj == nil {
805
806 if !isValid(under(x.typ)) {
807 goto Error
808 }
809
810 if index != nil {
811
812 check.errorf(e.Sel, AmbiguousSelector, "ambiguous selector %s.%s", x.expr, sel)
813 goto Error
814 }
815
816 if indirect {
817 if x.mode == typexpr {
818 check.errorf(e.Sel, InvalidMethodExpr, "invalid method expression %s.%s (needs pointer receiver (*%s).%s)", x.typ, sel, x.typ, sel)
819 } else {
820 check.errorf(e.Sel, InvalidMethodExpr, "cannot call pointer method %s on %s", sel, x.typ)
821 }
822 goto Error
823 }
824
825 var why string
826 if isInterfacePtr(x.typ) {
827 why = check.interfacePtrError(x.typ)
828 } else {
829 alt, _, _ := lookupFieldOrMethod(x.typ, x.mode == variable, check.pkg, sel, true)
830 why = check.lookupError(x.typ, sel, alt, false)
831 }
832 check.errorf(e.Sel, MissingFieldOrMethod, "%s.%s undefined (%s)", x.expr, sel, why)
833 goto Error
834 }
835
836
837 if m, _ := obj.(*Func); m != nil {
838 check.objDecl(m, nil)
839 }
840
841 if x.mode == typexpr {
842
843 m, _ := obj.(*Func)
844 if m == nil {
845 check.errorf(e.Sel, MissingFieldOrMethod, "%s.%s undefined (type %s has no method %s)", x.expr, sel, x.typ, sel)
846 goto Error
847 }
848
849 check.recordSelection(e, MethodExpr, x.typ, m, index, indirect)
850
851 sig := m.typ.(*Signature)
852 if sig.recv == nil {
853 check.error(e, InvalidDeclCycle, "illegal cycle in method declaration")
854 goto Error
855 }
856
857
858
859 var params []*Var
860 if sig.params != nil {
861 params = sig.params.vars
862 }
863
864
865
866
867
868
869 name := ""
870 if len(params) > 0 && params[0].name != "" {
871
872 name = sig.recv.name
873 if name == "" {
874 name = "_"
875 }
876 }
877 params = append([]*Var{NewVar(sig.recv.pos, sig.recv.pkg, name, x.typ)}, params...)
878 x.mode = value
879 x.typ = &Signature{
880 tparams: sig.tparams,
881 params: NewTuple(params...),
882 results: sig.results,
883 variadic: sig.variadic,
884 }
885
886 check.addDeclDep(m)
887
888 } else {
889
890 switch obj := obj.(type) {
891 case *Var:
892 check.recordSelection(e, FieldVal, x.typ, obj, index, indirect)
893 if x.mode == variable || indirect {
894 x.mode = variable
895 } else {
896 x.mode = value
897 }
898 x.typ = obj.typ
899
900 case *Func:
901
902
903 check.recordSelection(e, MethodVal, x.typ, obj, index, indirect)
904
905
906
907
908
909
910
911 disabled := true
912 if !disabled && debug {
913
914
915
916
917
918 typ := x.typ
919 if x.mode == variable {
920
921
922
923
924
925 if _, ok := typ.(*Pointer); !ok && !IsInterface(typ) {
926 typ = &Pointer{base: typ}
927 }
928 }
929
930
931
932
933
934
935
936
937 mset := NewMethodSet(typ)
938 if m := mset.Lookup(check.pkg, sel); m == nil || m.obj != obj {
939 check.dump("%v: (%s).%v -> %s", e.Pos(), typ, obj.name, m)
940 check.dump("%s\n", mset)
941
942
943
944
945
946 panic("method sets and lookup don't agree")
947 }
948 }
949
950 x.mode = value
951
952
953 sig := *obj.typ.(*Signature)
954 sig.recv = nil
955 x.typ = &sig
956
957 check.addDeclDep(obj)
958
959 default:
960 panic("unreachable")
961 }
962 }
963
964
965 x.expr = e
966 return
967
968 Error:
969 x.mode = invalid
970 x.expr = e
971 }
972
973
974
975
976
977
978 func (check *Checker) use(args ...ast.Expr) bool { return check.useN(args, false) }
979
980
981
982
983 func (check *Checker) useLHS(args ...ast.Expr) bool { return check.useN(args, true) }
984
985 func (check *Checker) useN(args []ast.Expr, lhs bool) bool {
986 ok := true
987 for _, e := range args {
988 if !check.use1(e, lhs) {
989 ok = false
990 }
991 }
992 return ok
993 }
994
995 func (check *Checker) use1(e ast.Expr, lhs bool) bool {
996 var x operand
997 x.mode = value
998 switch n := ast.Unparen(e).(type) {
999 case nil:
1000
1001 case *ast.Ident:
1002
1003 if n.Name == "_" {
1004 break
1005 }
1006
1007
1008
1009 var v *Var
1010 var v_used bool
1011 if lhs {
1012 if _, obj := check.scope.LookupParent(n.Name, nopos); obj != nil {
1013
1014
1015
1016 if w, _ := obj.(*Var); w != nil && w.pkg == check.pkg {
1017 v = w
1018 v_used = v.used
1019 }
1020 }
1021 }
1022 check.exprOrType(&x, n, true)
1023 if v != nil {
1024 v.used = v_used
1025 }
1026 default:
1027 check.rawExpr(nil, &x, e, nil, true)
1028 }
1029 return x.mode != invalid
1030 }
1031
View as plain text