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
What did you expect to see?
Switch error mentions pointer receiver.
What did you see instead?
Switch error states that the method is missing, unlike the type assertion, which gives clear cause.
Result from playground link
Type assertion: Clear error message prog.go:10: impossible type assertion: ast.Ident does not implement ast.Node (End method has pointer receiver)
Type switch: Technically correct error message, but confusing since we have a more descriptive error message in the assertion prog.go:12: impossible type switch case: node (type ast.Node) cannot have dynamic type ast.Ident (missing End method)
It seems that the type switch (swt.go) has less granularity than the type assertion (typecheck.go)
$GOROOT/src/cmd/compile/internal/gc/swt.go:166: (wrong type for %v method)
$GOROOT/src/cmd/compile/internal/gc/swt.go:168: (missing %v method)
$GOROOT/src/cmd/compile/internal/gc/typecheck.go:967: (wrong type for %v method)
$GOROOT/src/cmd/compile/internal/gc/typecheck.go:969: (%v method has pointer receiver)"
$GOROOT/src/cmd/compile/internal/gc/typecheck.go:971: (missing %v method)
$GOROOT/src/cmd/compile/internal/gc/typecheck.go:973: (missing %v method)
The text was updated successfully, but these errors were encountered:
$ go run main.go
# command-line-arguments
./main.go:10: impossible type assertion:
ast.Ident does not implement ast.Node (End method has pointer receiver)
./main.go:12: impossible type switch case: node (type ast.Node) cannot have dynamic type ast.Ident (End method has pointer receiver)
It now mentions that the End method has a pointer receiver as it does with the switch.
Version: go1.7beta1 plan9/amd64
The type assertion currently returns a more-useful error message than the type switch when a method lacks a pointer receiver.
https://play.golang.org/p/GWDP3WG57H
Switch error mentions pointer receiver.
Switch error states that the method is missing, unlike the type assertion, which gives clear cause.
Result from playground link
Type assertion: Clear error message
prog.go:10: impossible type assertion: ast.Ident does not implement ast.Node (End method has pointer receiver)
Type switch: Technically correct error message, but confusing since we have a more descriptive error message in the assertion
prog.go:12: impossible type switch case: node (type ast.Node) cannot have dynamic type ast.Ident (missing End method)
It seems that the type switch (swt.go) has less granularity than the type assertion (typecheck.go)
The text was updated successfully, but these errors were encountered: