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/compile: type assertion on generic type fails incorrectly #53309

Closed
heschi opened this issue Jun 9, 2022 · 5 comments
Closed

cmd/compile: type assertion on generic type fails incorrectly #53309

heschi opened this issue Jun 9, 2022 · 5 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@heschi
Copy link
Contributor

heschi commented Jun 9, 2022

The following program panics for no reason I can discern:

package workflow

import (
	"fmt"
	"testing"
)

type TaskInput interface {
	deps() []*taskDefinition
}

type Value[T any] interface {
	metaValue
}

type metaValue interface {
	TaskInput
}

type taskDefinition struct {
}

type taskResult struct {
	task *taskDefinition
}

func (tr *taskResult) deps() []*taskDefinition {
	return nil
}

func TestTrivial(t *testing.T) {
	tr := &taskResult{&taskDefinition{}}
	use(Value[string](tr))
}


func use[T any](v Value[T]) {
	_, ok := v.(*taskResult)
	if !ok {
		panic(fmt.Errorf("output must be a task result, is %T", v))
	}
}

cc @golang/runtime

@heschi heschi added the NeedsFix The path to resolution is known, but the work has not been done. label Jun 9, 2022
@heschi heschi added this to the Backlog milestone Jun 9, 2022
@prattmic
Copy link
Member

prattmic commented Jun 9, 2022

I notice that the caller at use(Value[string](tr)) is using:

go.itab.*example%2ecom.taskResult,example%2ecom.Value[string], but use itself is checking against
go.itab.*example%2ecom.taskResult,example%2ecom.Value[go.shape.string_0].

Based on the register flow, these pointers are compared in use for the type assertion, so the difference here is the immediate cause of the failure.

@gopherbot
Copy link

Change https://go.dev/cl/411617 mentions this issue: cmd/compile: fix missing dict pass for type assertions

@cuonglm
Copy link
Member

cuonglm commented Jun 11, 2022

@randall77 @mdempsky should we backport this?

@randall77
Copy link
Contributor

@gopherbot please open a backport issue to 1.18.

@gopherbot
Copy link

Backport issue(s) opened: #53357 (for 1.18).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@golang golang locked and limited conversation to collaborators Jun 13, 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

5 participants