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

go/types,cmd/compile/internal/types2: pointer to generic type can be used in a type switch without instantiation #48008

Closed
qmuntal opened this issue Aug 27, 2021 · 2 comments
Assignees
Milestone

Comments

@qmuntal
Copy link
Contributor

@qmuntal qmuntal commented Aug 27, 2021

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

go version devel go1.18-67f7e16 Fri Aug 27 08:01:41 2021 +0000 windows/amd64

Does this issue reproduce with the latest release?

Only in tip

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

go env Output
set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\muntal\AppData\Local\go-build
set GOENV=C:\Users\muntal\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\muntal\go\pkg\mod
set GONOPROXY=
set GONOSUMDB=*
set GOOS=windows
set GOPATH=C:\Users\muntal\go
set GOPRIVATE=
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Users\muntal\sdk\gotip
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLDIR=C:\Users\muntal\sdk\gotip\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=devel go1.18-67f7e16 Fri Aug 27 08:01:41 2021 +0000
set GCCGO=gccgo
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=C:\_\funcalias\go.mod
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\muntal\AppData\Local\Temp\go-build1690465182=/tmp/go-build -gno-record-gcc-switches

What did you do?

// main.go

package main

import "fmt"

type Foo[S any] struct {}

func main() {
  var v interface{} = Foo[string]{}
  switch v.(type) {
  case *Foo: // should not compile
    fmt.Println("foo pointer")
  case Foo:  // should not compile
    fmt.Println("foo value")
  case Foo[string]:  // should compile
    fmt.Println("foo value string")
  default:
    fmt.Println("nop")
  }
}

gotip tool compile main.go

What did you expect to see?

A compilation error because case *Foo: is used without instantiation.

main.go:10:7: cannot use generic type *Foo[S interface{}] without instantiation
main.go:12:7: cannot use generic type Foo[S interface{}] without instantiation

What did you see instead?

The compiler only complains about case Foo:

main.go:12:7: cannot use generic type Foo[S interface{}] without instantiation

cc: @griesemer @mdempsky @findleyr

@qmuntal qmuntal changed the title go/types,cmd/compile/internal/types2: pointer to generic type can be used in type switch without instantiation go/types,cmd/compile/internal/types2: pointer to generic type can be used in a type switch without instantiation Aug 27, 2021
@gopherbot
Copy link

@gopherbot gopherbot commented Aug 27, 2021

Change https://golang.org/cl/345669 mentions this issue: go/types,cmd/compile/internal/types2: pointer to generic type can be

Loading

@toothrot toothrot added this to the Backlog milestone Aug 27, 2021
@griesemer griesemer self-assigned this Aug 27, 2021
@griesemer griesemer removed this from the Backlog milestone Aug 27, 2021
@griesemer griesemer added this to the Go1.18 milestone Aug 27, 2021
@gopherbot
Copy link

@gopherbot gopherbot commented Aug 28, 2021

Change https://golang.org/cl/345790 mentions this issue: cmd/compile/internal/types2: types in type switch case must be instantiated

Loading

@gopherbot gopherbot closed this in 5fb1771 Aug 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants