Skip to content

cmd/compile: incorrect invalid field error in generic code #50148

@randall77

Description

@randall77

a.go:

package a

type S[T any] struct {
}

func (b *S[T]) build() *X[T] {
	return &X[T]{f:0}
}
type X[T any] struct {
	f int
}

b.go:

package b

import "./a"

func B() {
	var x a.S[int]
	_ = x
}

main.go:

package main

import "./b"

func main() {
	b.B()
}

This should compile successfully. Instead we get the error:

a.go:7:16: invalid field name a.f in struct initializer

This is an error from the old typechecker when importing code (from b into main, I think). The error occurs in the phase where we're building more instantiations after inlining.

This example is reduced from an example generated by my generifier. It was originally package html_test importing package html importing a generified version of package string.

@danscales

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgegenericsIssue is related to genericsokay-after-beta1Used by release team to mark a release-blocker issue as okay to resolve either before or after beta1

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions