Skip to content

spec: document promotion of methods from embedded aliases of unnamed types #66540

@adonovan

Description

@adonovan

I was surprised to learn yesterday that it is legal to embed an alias type whose underlying type is not a defined type.

type strings = []string
type S struct { strings } // equivalent to 'strings []string'
var _ = new(S).strings

This is legal according to the spec; there is supposed to be no promotion of methods from the alias's underlying type.

And yet promotion does occur:
https://go.dev/play/p/_bJZeiZW-cW

package main

import "io"

type S struct{ A }

var _ = new(S).A

type A = struct{ io.Reader }

func main() {
	if false {
		new(S).Read(nil) // not a legal program
	}
}

I expect go/types has the same issue.

Metadata

Metadata

Labels

DocumentationIssues describing a change to documentation.NeedsFixThe path to resolution is known, but the work has not been done.Proposal-Accepted

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions