Skip to content

cmd/compile: confusing error when trying to instantiate type parameter on other-package constraint with unexported fields #51942

@ALTree

Description

@ALTree

Consider the following 3-files program:

go.mod:

module example.com/mod

go 1.18

a/a.go

package a

type I interface {
	struct{ i int }
}

func F[T I]() {}

test.go

package main

import "example.com/mod/a"

func main() {
	a.F[struct{ i int }]()
}

With go1.18 and tip, the program does not compile:

 $ go build
# example.com/mod
.\test.go:6:6: struct{i int} does not implement a.I

playground link: https://go.dev/play/p/yvRVxYbdkpK

To to me it looks like it should(?). The same constraint and function work fine when they're part of the main package. Am I missing something?

EDIT: I had the wrong mental model, it's correct that this doesn't work but the error message is slightly confusing. See below.

cc @findleyr @griesemer @mdempsky

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsDecisionFeedback is required from experts, contributors, and/or the community before a change can be made.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Status

    Triage Backlog

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions