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
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. release-blocker
Milestone

Comments

@qmuntal
Copy link
Contributor

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

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

@toothrot toothrot added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Aug 27, 2021
@toothrot toothrot added this to the Backlog milestone Aug 27, 2021
@griesemer griesemer self-assigned this Aug 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 Aug 27, 2021
@griesemer griesemer modified the milestones: Backlog, Go1.18 Aug 27, 2021
@gopherbot
Copy link

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

@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. release-blocker
Projects
None yet
Development

No branches or pull requests

4 participants