Source file test/fixedbugs/issue48558.go

     1  // errorcheck
     2  
     3  // Copyright 2021 The Go Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  package p
     8  
     9  func _(a, b, c int) {
    10  	_ = a
    11  	_ = a, b    // ERROR "assignment mismatch: 1 variable but 2 values"
    12  	_ = a, b, c // ERROR "assignment mismatch: 1 variable but 3 values"
    13  
    14  	_, _ = a // ERROR "assignment mismatch: 2 variables but 1 value"
    15  	_, _ = a, b
    16  	_, _ = a, b, c // ERROR "assignment mismatch: 2 variables but 3 values"
    17  
    18  	_, _, _ = a    // ERROR "assignment mismatch: 3 variables but 1 value"
    19  	_, _, _ = a, b // ERROR "assignment mismatch: 3 variables but 2 values"
    20  	_, _, _ = a, b, c
    21  }
    22  
    23  func f1() int
    24  func f2() (int, int)
    25  func f3() (int, int, int)
    26  
    27  func _() {
    28  	_ = f1()
    29  	_ = f2() // ERROR "assignment mismatch: 1 variable but f2 returns 2 values"
    30  	_ = f3() // ERROR "assignment mismatch: 1 variable but f3 returns 3 values"
    31  
    32  	_, _ = f1() // ERROR "assignment mismatch: 2 variables but f1 returns 1 value"
    33  	_, _ = f2()
    34  	_, _ = f3() // ERROR "assignment mismatch: 2 variables but f3 returns 3 values"
    35  
    36  	_, _, _ = f1() // ERROR "assignment mismatch: 3 variables but f1 returns 1 value"
    37  	_, _, _ = f2() // ERROR "assignment mismatch: 3 variables but f2 returns 2 values"
    38  	_, _, _ = f3()
    39  
    40  	// test just a few := cases as they use the same code as the = case
    41  	a1 := f3()         // ERROR "assignment mismatch: 1 variable but f3 returns 3 values"
    42  	a2, b2 := f1()     // ERROR "assignment mismatch: 2 variables but f1 returns 1 value"
    43  	a3, b3, c3 := f2() // ERROR "assignment mismatch: 3 variables but f2 returns 2 values"
    44  
    45  	_ = a1
    46  	_, _ = a2, b2
    47  	_, _, _ = a3, b3, c3
    48  }
    49  
    50  type T struct{}
    51  
    52  func (T) f1() int
    53  func (T) f2() (int, int)
    54  func (T) f3() (int, int, int)
    55  
    56  func _(x T) {
    57  	_ = x.f1()
    58  	_ = x.f2() // ERROR "assignment mismatch: 1 variable but .\.f2 returns 2 values"
    59  	_ = x.f3() // ERROR "assignment mismatch: 1 variable but .\.f3 returns 3 values"
    60  
    61  	_, _ = x.f1() // ERROR "assignment mismatch: 2 variables but .\.f1 returns 1 value"
    62  	_, _ = x.f2()
    63  	_, _ = x.f3() // ERROR "assignment mismatch: 2 variables but .\.f3 returns 3 values"
    64  
    65  	_, _, _ = x.f1() // ERROR "assignment mismatch: 3 variables but .\.f1 returns 1 value"
    66  	_, _, _ = x.f2() // ERROR "assignment mismatch: 3 variables but .\.f2 returns 2 values"
    67  	_, _, _ = x.f3()
    68  
    69  	// test just a few := cases as they use the same code as the = case
    70  	a1 := x.f3()         // ERROR "assignment mismatch: 1 variable but .\.f3 returns 3 values"
    71  	a2, b2 := x.f1()     // ERROR "assignment mismatch: 2 variables but .\.f1 returns 1 value"
    72  	a3, b3, c3 := x.f2() // ERROR "assignment mismatch: 3 variables but .\.f2 returns 2 values"
    73  
    74  	_ = a1
    75  	_, _ = a2, b2
    76  	_, _, _ = a3, b3, c3
    77  }
    78  
    79  // some one-off cases
    80  func _() {
    81  	_ = (f2)
    82  	_ = f1(), 2         // ERROR "assignment mismatch: 1 variable but 2 values"
    83  	_, _ = (f1()), f2() // ERROR "multiple-value f2\(\) .*in single-value context"
    84  	_, _, _ = f3(), 3   // ERROR "assignment mismatch: 3 variables but 2 values|multiple-value f3\(\) .*in single-value context"
    85  }
    86  

View as plain text