-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: converting to slice of runes fails, from defined type derived from string of non-const instance when inside a function #23298
Comments
Nice catch, thank you for reporting this @guangda-hu! As @ianlancetaylor reported in that issue, that code works alright with gccgo. /cc @griesemer @mdempsky. |
Okay now an interesting permutation of this bug passes when the example is NOT in a function i.e Passing 1package p
type T string
var _ = []rune(T("T")) Passing 2package p
type T string
var t = T("T")
var _ = []rune(t) Passing 3 based off Passing 1package p
type T string
func foo() {
var _ = []rune(T("T"))
} Failing 1 based off Passing 2, but in functionpackage p
type T string
func foo() {
var t = T("T")
var _ = []rune(t)
} $ go tool compile fail.go
fail.go:7:16: cannot use t (type T) as type string in argument to runtime.stringtoslicerune |
My guess was that the problem is only with non-constant (I actually briefly mentioned this at the end of "What did you do?", and the example Edit: Nevermind. Your second example shows it's actually related to whether it's inside a function. Edit again: Your second example will fail if you don't use '_': https://play.golang.org/p/h4ZAslGQ8eN |
Change https://golang.org/cl/87695 mentions this issue: |
@guangda-hu @odeke-em I've tried to fix the issue. Could you take a look at the CL? |
Thank you @namusyaka and Happy New Year! It'll be for Go1.11 :) |
This is the second item in #23297.
What version of Go are you using (
go version
)?go version go1.9.2 linux/amd64
and the compiler used by the Go playground
What did you do?
The string->[]rune conversion does not work for non-constant user defined string type:
See https://play.golang.org/p/gunMmHAxytT. There seems no such problem with constant, []byte, or the other converting direction.
What did you expect to see?
I think this should compile. From https://golang.org/ref/spec#Conversions, Version of June 28, 2017:
Based on the following examples provided in the spec, it seems the phrases "string", "slice of bytes", "slice of runes" include defined types as well as the plane "string", "[]byte", "[]rune" types:
What did you see instead?
Compile error:
cannot use a (type MyString) as type string in argument to runtime.stringtoslicerune
The text was updated successfully, but these errors were encountered: