return nil
case variable, mapindex:
// ok
- case nilvalue:
- check.error(&z, "cannot assign to nil") // default would print "untyped nil"
- return nil
default:
if sel, ok := z.expr.(*syntax.SelectorExpr); ok {
var op operand
case nil, Typ[Invalid]:
return "nil (with invalid type)"
case Typ[UntypedNil]:
- return "untyped nil"
+ return "nil"
default:
return fmt.Sprintf("nil (of type %s)", TypeString(x.typ, qf))
}
// test cases for issue 5800
var (
- _ int = nil /* ERROR "untyped nil" */
- _ [10]int = nil /* ERROR "untyped nil" */
+ _ int = nil /* ERROR "nil" */
+ _ [10]int = nil /* ERROR "nil" */
_ []byte = nil
- _ struct{} = nil /* ERROR "untyped nil" */
+ _ struct{} = nil /* ERROR "nil" */
_ func() = nil
_ map[int]string = nil
_ chan int = nil
T1 []int,
T2 ~float64 | ~complex128 | chan int,
]() {
- _ = T0(nil /* ERROR cannot convert untyped nil 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 */ )
}
// "x is the predeclared identifier nil and T is a pointer, function, slice, map, channel, or interface type"
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"
package main
func main() {
- _ = nil // ERROR "use of untyped nil"
- _, _ = nil, 1 // ERROR "use of untyped nil"
- _, _ = 1, nil // ERROR "use of untyped nil"
- _ = append(nil, 1, 2, 3) // ERROR "untyped nil"
+ _ = nil // ERROR "use of untyped nil"
+ _, _ = nil, 1 // ERROR "use of untyped nil"
+ _, _ = 1, nil // ERROR "use of untyped nil"
+ _ = append(nil, 1, 2, 3) // ERROR "untyped nil|nil"
}
-
package p
func f() uintptr {
- return nil // ERROR "cannot use nil as type uintptr in return argument|incompatible type|cannot use untyped nil"
+ return nil // ERROR "cannot use nil as type uintptr in return argument|incompatible type|cannot use nil"
}
package main
var bits1 uint = 10
+
const bits2 uint = 10
func main() {
_ = make([]byte, 1<<bits1)
_ = make([]byte, 1<<bits2)
- _ = make([]byte, nil) // ERROR "non-integer.*len|untyped nil"
- _ = make([]byte, nil, 2) // ERROR "non-integer.*len|untyped nil"
- _ = make([]byte, 1, nil) // ERROR "non-integer.*cap|untyped nil"
- _ = make([]byte, true) // ERROR "non-integer.*len|untyped bool"
- _ = make([]byte, "abc") // ERROR "non-integer.*len|untyped string"
+ _ = make([]byte, nil) // ERROR "non-integer.*len|nil"
+ _ = make([]byte, nil, 2) // ERROR "non-integer.*len|nil"
+ _ = make([]byte, 1, nil) // ERROR "non-integer.*cap|nil"
+ _ = make([]byte, true) // ERROR "non-integer.*len|untyped bool"
+ _ = make([]byte, "abc") // ERROR "non-integer.*len|untyped string"
}