New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/compile: comma-ok form with interface{} seems to read garbage #16870
Comments
Nice! /Cc @randall77 |
@tv42 re: what it means:
is just a short form of
This latter version was always present in the spec. Note that we only talk about the syntactic form here - the usual rules for types etc. must be followed independently. But nice error indeed! |
@griesemer Yeah, I understand the syntax, I was trying to see what possible use would that form ever have, considering that |
Related: https://play.golang.org/p/G3dH79rD_Y also doesn't work right. At tip:
produces
Looks like a compiler frontend issue. |
Same for channel ops:
produces
(the ok should be printed as false rather than 0x0). And finally:
produces
Looks like nobody has ever used the comma-ok form outside a short variable declaration (or perhaps with a non-bool ok). |
The issues all appear to be in walk.go's handling of various OAS2xxx nodes. In particular, they all assume ok to be of boolean type. OAS2RECV generates a call to runtime.chanrecv2 and pretends its return type is ok's, which is problematic if ok is interface{}. OAS2MAPR does something similar, rewriting mapaccess2*'s second result parameter type to match ok's. OAS2DOTTYPE for conversions to a concrete type generates an expression to assign to ok. The assignment succeeds by creating an implicit conversion. But the ok variable is used in an OIF node as the condition later, which fails. |
Looks like this is also broken on Go 1.6 (but with different results? or different luck) so this doesn't seem to be a Go 1.7.1 candidate. Others agree? |
Agreed. The usage is so unusual and the failure mode is so spectacular (nice find!) that I doubt this is on the critical path for 1.7.1. |
CL https://golang.org/cl/27910 mentions this issue. |
Please answer these questions before submitting your issue. Thanks!
go version
)?go version go1.7 linux/amd64
go version devel +35f5517 2016-08-16 01:04:17 +0000 linux/amd64
go env
)?playground and
Inspired by #15782 (comment) I decided to explore what giving types to the comma-ok form even means. It seems I got things to break:
A) https://play.golang.org/p/rogSaQq7Hf panics on playground, 1.7 and tip say
ok=<invalid reflect.Value>
. I was curious howfmt
ends up with invalidreflect.Value
s, and explored further.B) echlebek on IRC came up with https://play.golang.org/p/LOXGni0AH9 which results in
ok
being acomplex
on playground! Behavior seen on Go1.7:ok=(1.3109511e-38+0i)
,ok=1.3109511e-38
,The text was updated successfully, but these errors were encountered: