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/go2go: panic in type checker #43526

Open
candlerb opened this issue Jan 5, 2021 · 1 comment
Open

cmd/go2go: panic in type checker #43526

candlerb opened this issue Jan 5, 2021 · 1 comment
Assignees
Milestone

Comments

@candlerb
Copy link

@candlerb candlerb commented Jan 5, 2021

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

go2go playground

Does this issue reproduce with the latest release?

N/A

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

N/A

What did you do?

https://go2goplay.golang.org/p/VH5SLJNxw3X

package main

import (
	"fmt"
)

type MyMap[KT, VT comparable] struct {
    data map[KT]VT
}

func NewMap[KT, VT comparable]() *MyMap[KT, VT] {
    var m MyMap[KT, VT]
    m.data = make(map[KT]VT)
    return &m
}

func (m *MyMap[KT,VT]) set(k KT, v VT) {
    m.data[k] = v
}

func main() {
    m := NewMap[string, int]
    m[int] = 123
    fmt.Println("Got ", m["foo"])
}

What did you expect to see?

An error message about the nonsense line m[int] = 123

What did you see instead?

Panic - from the type checker according to @ianlancetaylor here.

panic: assertion failed [recovered]
	panic: assertion failed [recovered]
	panic: assertion failed

goroutine 1 [running]:
go/types.(*Checker).handleBailout(0xc0000d4280, 0xc000159be0)
	/usr/local/go-faketime/src/go/types/check.go:252 +0x9b
panic(0x645460, 0x6d5ad0)
	/usr/local/go-faketime/src/runtime/panic.go:969 +0x175
go/types.(*Checker).stmt.func1(0xc0000d4280, 0xc00013db80)
	/usr/local/go-faketime/src/go/types/stmt.go:307 +0x85
panic(0x645460, 0x6d5ad0)
	/usr/local/go-faketime/src/runtime/panic.go:975 +0x3e9
go/types.assert(...)
	/usr/local/go-faketime/src/go/types/errors.go:19
go/types.(*Checker).call(0xc0000d4280, 0xc0000af180, 0xc00013def0, 0x6de1e0, 0xc000084fc0, 0x9)
	/usr/local/go-faketime/src/go/types/call.go:188 +0x172d
go/types.(*Checker).exprInternal(0xc0000d4280, 0xc0000af180, 0x6de1e0, 0xc000084fc0, 0x0, 0x0, 0x6462e0)
	/usr/local/go-faketime/src/go/types/expr.go:1359 +0x2b9e
go/types.(*Checker).rawExpr(0xc0000d4280, 0xc0000af180, 0x6de1e0, 0xc000084fc0, 0x0, 0x0, 0x0)
	/usr/local/go-faketime/src/go/types/expr.go:1043 +0xc5
go/types.(*Checker).expr(0xc0000d4280, 0xc0000af180, 0x6de1e0, 0xc000084fc0)
	/usr/local/go-faketime/src/go/types/expr.go:1753 +0x55
go/types.(*Checker).assignVar(0xc0000d4280, 0x6de1e0, 0xc000084fc0, 0xc0000af140, 0xc00013db00, 0xc0000a8328)
	/usr/local/go-faketime/src/go/types/assignments.go:176 +0x29b
go/types.(*Checker).assignVars(0xc0000d4280, 0xc000082820, 0x1, 0x1, 0xc000082830, 0x1, 0x1)
	/usr/local/go-faketime/src/go/types/assignments.go:283 +0x22f
go/types.(*Checker).stmt(0xc0000d4280, 0x0, 0x6ddae0, 0xc0000ae700)
	/usr/local/go-faketime/src/go/types/stmt.go:409 +0x351d
go/types.(*Checker).stmtList(0xc0000d4280, 0x0, 0xc0000ae740, 0x3, 0x4)
	/usr/local/go-faketime/src/go/types/stmt.go:125 +0xd1
go/types.(*Checker).funcBody(0xc0000d4280, 0xc00013e840, 0xc0000a445c, 0x4, 0xc00013ea20, 0xc000085020, 0x0, 0x0)
	/usr/local/go-faketime/src/go/types/stmt.go:42 +0x257
go/types.(*Checker).funcDecl.func1()
	/usr/local/go-faketime/src/go/types/decl.go:813 +0x67
go/types.(*Checker).processDelayed(0xc0000d4280, 0x0)
	/usr/local/go-faketime/src/go/types/check.go:327 +0x3e
go/types.(*Checker).checkFiles(0xc0000d4280, 0xc000105cb8, 0x1, 0x1, 0x0, 0x0)
	/usr/local/go-faketime/src/go/types/check.go:295 +0x205
go/types.(*Checker).Files(...)
	/usr/local/go-faketime/src/go/types/check.go:257
go/types.(*Config).Check(0xc0000ae780, 0xc0000a43a0, 0x4, 0xc0000ae280, 0xc000105cb8, 0x1, 0x1, 0xc0000b1360, 0x0, 0x4b70cf, ...)
	/usr/local/go-faketime/src/go/types/api.go:392 +0x188
go/go2go.RewriteBuffer(0xc0000aa360, 0x7fff446f6dec, 0x1e, 0xc0000fa000, 0x174, 0x374, 0x0, 0xc000084a50, 0xc000084a20, 0xc0000849f0, ...)
	/usr/local/go-faketime/src/go/go2go/go2go.go:139 +0x257
main.translateFile(0xc0000aa360, 0x7fff446f6dec, 0x1e)
	/usr/local/go-faketime/src/cmd/go2go/translate.go:26 +0xa9
main.main()
	/usr/local/go-faketime/src/cmd/go2go/main.go:74 +0x309
@ianlancetaylor ianlancetaylor changed the title go2: panic in type checker cmd/go2go: panic in type checker Jan 5, 2021
@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Jan 5, 2021
@griesemer
Copy link
Contributor

@griesemer griesemer commented Jan 5, 2021

This works fine with cmd/compile/internal/types2 and the compiler (dev.typeparams branch).

@griesemer griesemer modified the milestones: Unreleased, Go1.17 Jan 6, 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
3 participants
You can’t perform that action at this time.