// test cases for issue 5800
var (
- _ int = nil /* ERROR "nil" */
- _ [10]int = nil /* ERROR "nil" */
+ _ int = nil /* ERROR "cannot use nil as int value in variable declaration" */
+ _ [10]int = nil /* ERROR "cannot use nil as \[10\]int value in variable declaration" */
_ []byte = nil
- _ struct{} = nil /* ERROR "nil" */
+ _ struct{} = nil /* ERROR "cannot use nil as struct{} value in variable declaration" */
_ func() = nil
_ map[int]string = nil
_ chan int = nil
// cgofunc <expr> ( <mode> of type <typ>)
//
func operandString(x *operand, qf Qualifier) string {
+ // special-case nil
+ if x.mode == value && x.typ == Typ[UntypedNil] {
+ return "nil"
+ }
+
var buf bytes.Buffer
var expr string
// test cases for issue 5800
var (
- _ int = nil /* ERROR "untyped nil value" */
- _ [10]int = nil /* ERROR "untyped nil value" */
+ _ int = nil /* ERROR "cannot use nil as int value in variable declaration" */
+ _ [10]int = nil /* ERROR "cannot use nil as \[10\]int value in variable declaration" */
_ []byte = nil
- _ struct{} = nil /* ERROR "untyped nil value" */
+ _ struct{} = nil /* ERROR "cannot use nil as struct{} value in variable declaration" */
_ func() = nil
_ map[int]string = nil
_ chan int = nil
T2 ~float64 | ~complex128 | chan int,
]() {
// TODO(rfindley): the types2 error here is clearer.
- _ = T0(nil /* ERROR cannot convert nil \(untyped nil value\) to T0 */ )
+ _ = T0(nil /* ERROR cannot convert nil to T0 */ )
_ = T1(1 /* ERROR cannot convert 1 .* to T1 */ )
_ = T2(2 /* ERROR cannot convert 2 .* to T2 */ )
}
// TODO(rfindley) error messages about untyped nil diverge from types2 here.
// Consider aligning them.
func _[TP Interface](X TP) {
- b = nil // ERROR cannot use.*untyped nil
- a = nil // ERROR cannot use.*untyped nil
+ b = nil // ERROR cannot use nil
+ a = nil // ERROR cannot use nil
l = nil
- s = nil // ERROR cannot use.*untyped nil
+ s = nil // ERROR cannot use nil
p = nil
f = nil
i = nil
m = nil
c = nil
- d = nil // ERROR cannot use.*untyped nil
+ d = nil // ERROR cannot use nil
- B = nil // ERROR cannot use.*untyped nil
- A = nil // ERROR cannot use.*untyped nil
+ B = nil // ERROR cannot use nil
+ A = nil // ERROR cannot use nil
L = nil
- S = nil // ERROR cannot use.*untyped nil
+ S = nil // ERROR cannot use nil
P = nil
F = nil
I = nil
M = nil
C = nil
- D = nil // ERROR cannot use.*untyped nil
- X = nil // ERROR cannot use.*untyped nil
+ D = nil // ERROR cannot use nil
+ X = nil // ERROR cannot use nil
}
// "x is an untyped constant representable by a value of type T"