You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"fmt"
)
type A struct {
}
func (a *A) Error() string {
return "A"
}
func t() *A {
return nil
}
func fun1 () {
var a error
a = (*A)(nil)
fmt.Printf("%#v\n", a)
if a == nil {
fmt.Printf("nil#1.1\n")
}
if a == (*A)(nil) {
fmt.Printf("nil#1.2\n")
}
a = t()
fmt.Printf("%#v\n", a)
if a == nil {
fmt.Printf("nil#2.1\n")
}
if a == (*A)(nil) {
fmt.Printf("nil#2.2\n")
}
}
func fun2() {
var a *A
a = (*A)(nil)
fmt.Printf("%#v\n", a)
if a == nil {
fmt.Printf("nil#1.1\n")
}
if a == (*A)(nil) {
fmt.Printf("nil#1.2\n")
}
a = t()
fmt.Printf("%#v\n", a)
if a == nil {
fmt.Printf("nil#2.1\n")
}
if a == (*A)(nil) {
fmt.Printf("nil#2.2\n")
}
}
func main() {
fmt.Printf("* fun1\n")
fun1()
fmt.Printf("* fun2\n")
fun2()
if nil == (*A)(nil) {
fmt.Printf("equal\n")
}
}
t57root
changed the title
implicit conversion without error while assigning nil cross different pointer types
conflict behavior when comparing nil and (*SturctName)(nil)
Nov 7, 2019
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: