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

dev.typeparams, cmd/compile: panic: interface conversion: ir.Ntype is *ir.Ident, not *ir.FuncType #43530

Closed
OneOfOne opened this issue Jan 6, 2021 · 7 comments

Comments

@OneOfOne
Copy link
Contributor

@OneOfOne OneOfOne commented Jan 6, 2021

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

$ git describe --all; git describe --always; go version
heads/dev.typeparams
a8fe098a12
go version devel +a8fe098a12 2021-01-05 10:13:59 -0800 linux/amd64

What did you do?

Source: https://go2goplay.golang.org/p/1qkRFfQNDNz

package main

import (
	"fmt"
	"sort"
)

type Interface interface {
	Len() int
	Less(i, j int) bool
	Swap(i, j int)
}

type comparable interface {
	type int, int8, int16, int32, int64, uint, uint8, uint16, uint32, uint64, float32, float64, string
}

type comparableSlice[T comparable] []T

func (s comparableSlice[T]) Len() int           { return len(s) }
func (s comparableSlice[T]) Less(i, j int) bool { return s[i] < s[j] }
func (s comparableSlice[T]) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }

func main() {
	s := []int{1, 3, 2}
	sort.Sort(comparableSlice[int](s))
	fmt.Println(s)
}

What did you expect to see?

A successful compile or at least no panics since it works on dev.go2go and the go2 playground.

What did you see instead?

● go build -gcflags '-G -G'
# tmp/go-scratch.3BF
panic: interface conversion: ir.Ntype is *ir.Ident, not *ir.FuncType

goroutine 1 [running]:
cmd/compile/internal/noder.(*noder).interfaceType(0xc0001ba360, 0xc0000c5a10, 0xc0000c5a10, 0xe11000000002)
        /usr/src/go2/src/cmd/compile/internal/noder/noder.go:1157 +0x73d
cmd/compile/internal/noder.(*noder).expr(0xc0001ba360, 0xf852e8, 0xc0000c5a10, 0x20000e060, 0xa)
        /usr/src/go2/src/cmd/compile/internal/noder/noder.go:994 +0x2492
cmd/compile/internal/noder.(*noder).typeExpr(0xc0001ba360, 0xf852e8, 0xc0000c5a10, 0xc0003eeee0, 0xc0000c57a0)
        /usr/src/go2/src/cmd/compile/internal/noder/noder.go:1095 +0x45
cmd/compile/internal/noder.(*noder).typeExprOrNil(...)
        /usr/src/go2/src/cmd/compile/internal/noder/noder.go:1107
cmd/compile/internal/noder.(*noder).typeDecl(0xc0001ba360, 0xc0003eade0, 0xc0003eade0, 0xe06000000002)
        /usr/src/go2/src/cmd/compile/internal/noder/noder.go:728 +0x22e
cmd/compile/internal/noder.(*noder).decls(0xc0001ba360, 0xc000038400, 0x9, 0x10, 0x0, 0xc0000bb860, 0xc0000bb810)
        /usr/src/go2/src/cmd/compile/internal/noder/noder.go:524 +0x557
cmd/compile/internal/noder.(*noder).node(0xc0001ba360)
        /usr/src/go2/src/cmd/compile/internal/noder/noder.go:481 +0xea
cmd/compile/internal/noder.ParseFiles(0xc00001e230, 0x1, 0x1, 0x2)
        /usr/src/go2/src/cmd/compile/internal/noder/noder.go:155 +0xacd
cmd/compile/internal/noder.LoadPackage(0xc00001e230, 0x1, 0x1)
        /usr/src/go2/src/cmd/compile/internal/noder/noder.go:33 +0xc5
cmd/compile/internal/gc.Main(0xe615e0)
        /usr/src/go2/src/cmd/compile/internal/gc/main.go:206 +0xafc
main.main()
        /usr/src/go2/src/cmd/compile/main.go:54 +0xb1
@OneOfOne
Copy link
Contributor Author

@OneOfOne OneOfOne commented Jan 6, 2021

@gopherbot, please add labels go2

Loading

@gopherbot gopherbot added the Go2 label Jan 6, 2021
@ALTree
Copy link
Member

@ALTree ALTree commented Jan 6, 2021

I don't think actual, current issues in the dev.typeparams branch need to be labelled as Go2, that's mostly used for broad language changes and stuff like that (for reference: https://github.com/golang/go/issues?q=is%3Aissue+dev.typeparams none of these has the label).

I'm removing it, if you don't mind.

Loading

@ALTree
Copy link
Member

@ALTree ALTree commented Jan 6, 2021

Loading

@griesemer
Copy link
Contributor

@griesemer griesemer commented Jan 6, 2021

This (-G -G or -G=2) is not expected to work at this point; the respective code doesn't exist yet and is work in progress.

Loading

@griesemer griesemer closed this Jan 6, 2021
@OneOfOne
Copy link
Contributor Author

@OneOfOne OneOfOne commented Jan 6, 2021

@griesemer is there any way to compile go2 code with that branch?

Loading

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jan 6, 2021

@OneOfOne It's work in progress. The branch is there to develop the ability to compile code that uses type parameters. Until that work is done, the code on the branch won't work. That's why it's on a branch.

Loading

@griesemer
Copy link
Contributor

@griesemer griesemer commented Jan 6, 2021

@OneOfOne What @ianlancetaylor said. You can type-check go2 code with a single -G option (or -G=1) for now.

Loading

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
5 participants