Skip to content
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/vet: cannot convert s (variable of type parameter T constrained by ~string) to string #49186

Closed
wojas opened this issue Oct 27, 2021 · 5 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@wojas
Copy link

wojas commented Oct 27, 2021

What version of Go are you using (go version)?

Latest gotip:

$ go version
go version devel go1.18-cfb532158f Wed Oct 27 13:12:49 2021 +0000 darwin/amd64

Does this issue reproduce with the latest release?

Yes, tried with latest gotip.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/wojas/Library/Caches/go-build"
GOENV="/Users/wojas/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/wojas/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/wojas/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/wojas/sdk/gotip"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/wojas/sdk/gotip/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="devel go1.18-cfb532158f Wed Oct 27 13:12:49 2021 +0000"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/wojas/go/experiments/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/cr/nj9c04_x215dl0wm3z3cdyp00000gs/T/go-build2473934211=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Contents of foo_test.go:

package foo

import "testing"

func foo[T ~string](s T) T {
	return T(string(s))
}

func Test_foo(t *testing.T) {
	foo("bar")
}

This fails on a go vet check:

$ gotip test .
vet: ./foo_test.go:6:18: cannot convert s (variable of type parameter T constrained by ~string) to string
FAIL	experiments.example [build failed]
FAIL

The compiler does accept it, as can be seen when running with -vet=off:

$ gotip test -vet=off .
ok  	experiments.example	0.256s

What did you expect to see?

No vet error.

What did you see instead?

cannot convert s (variable of type parameter T constrained by ~string) to string
@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 27, 2021
@seankhliao
Copy link
Member

cc @matloob

@ianlancetaylor
Copy link
Contributor

CC @findleyr @griesemer

@griesemer
Copy link
Contributor

The necessary fix is pending review (CL 359137).

@griesemer griesemer added this to the Go1.18 milestone Oct 27, 2021
@griesemer griesemer added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Oct 27, 2021
@findleyr
Copy link
Contributor

This should now be resolved with CL 359137. Please re-open if not.

@wojas
Copy link
Author

wojas commented Oct 29, 2021

It works as expected in today's go1.18-2c7cdec2a7, thanks!

@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

6 participants