Black Lives Matter. Support the Equal Justice Initiative.

Text file src/go/types/testdata/check/errors.src

Documentation: go/types/testdata/check

     1  // Copyright 2013 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 errors
     6  
     7  // Testing precise operand formatting in error messages
     8  // (matching messages are regular expressions, hence the \'s).
     9  func f(x int, m map[string]int) {
    10  	// no values
    11  	_ = f /* ERROR "f\(0, m\) \(no value\) used as value" */ (0, m)
    12  
    13  	// built-ins
    14  	_ = println /* ERROR "println \(built-in\) must be called" */
    15  
    16  	// types
    17  	_ = complex128 /* ERROR "complex128 \(type\) is not an expression" */
    18  
    19  	// constants
    20  	const c1 = 991
    21  	const c2 float32 = 0.5
    22  	0 /* ERROR "0 \(untyped int constant\) is not used" */
    23  	c1 /* ERROR "c1 \(untyped int constant 991\) is not used" */
    24  	c2 /* ERROR "c2 \(constant 0.5 of type float32\) is not used" */
    25  	c1 /* ERROR "c1 \+ c2 \(constant 991.5 of type float32\) is not used" */ + c2
    26  
    27  	// variables
    28  	x /* ERROR "x \(variable of type int\) is not used" */
    29  
    30  	// values
    31  	x /* ERROR "x != x \(untyped bool value\) is not used" */ != x
    32  	x /* ERROR "x \+ x \(value of type int\) is not used" */ + x
    33  
    34  	// value, ok's
    35  	const s = "foo"
    36  	m /* ERROR "m\[s\] \(map index expression of type int\) is not used" */ [s]
    37  }
    38  
    39  // Valid ERROR comments can have a variety of forms.
    40  func _() {
    41  	0 /* ERROR "0 .* is not used" */
    42  	0 /* ERROR 0 .* is not used */
    43  	0 // ERROR "0 .* is not used"
    44  	0 // ERROR 0 .* is not used
    45  }
    46  
    47  // Don't report spurious errors as a consequence of earlier errors.
    48  // Add more tests as needed.
    49  func _() {
    50  	if err := foo /* ERROR undeclared */ (); err != nil /* no error here */ {}
    51  }
    52  
    53  // Use unqualified names for package-local objects.
    54  type T struct{}
    55  var _ int = T /* ERROR value of type T */ {} // use T in error message rather then errors.T
    56  
    57  // Don't report errors containing "invalid type" (issue #24182).
    58  func _(x *missing /* ERROR undeclared name: missing */ ) {
    59  	x.m() // there shouldn't be an error here referring to *invalid type
    60  }
    61  

View as plain text