1
0
mirror of https://github.com/golang/go synced 2024-11-24 19:50:18 -07:00
go/test/typeparam/struct.go
Alan Donovan b24ec88bb9 cmd/compile: export/import materialized aliases
This CL changes the compiler's type import/export logic
to create and preserve materialized Alias types
when GODEBUG=gotypesaliases=1.

In conjunction with CL 574717, it allows the x/tools
tests to pass with GODEBUG=gotypesaliases=1.

Updates #65294
Updates #64581
Fixes #66550

Change-Id: I70b9279f4e0ae7a1f95ad153c4e6909a878915a4
Reviewed-on: https://go-review.googlesource.com/c/go/+/574737
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2024-04-05 16:29:58 +00:00

51 lines
801 B
Go

// run
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"fmt"
)
type E[T any] struct {
v T
}
type S1 struct {
E[int]
v string
}
type Eint = E[int]
type Ebool = E[bool]
type Eint2 = Eint
type S2 struct {
Eint
Ebool
v string
}
type S3 struct {
*E[int]
}
func main() {
s1 := S1{Eint{2}, "foo"}
if got, want := s1.E.v, 2; got != want {
panic(fmt.Sprintf("got %d, want %d", got, want))
}
s2 := S2{Eint{3}, Ebool{true}, "foo"}
if got, want := s2.Eint.v, 3; got != want {
panic(fmt.Sprintf("got %d, want %d", got, want))
}
var s3 S3
s3.E = &Eint{4}
if got, want := s3.E.v, 4; got != want {
panic(fmt.Sprintf("got %d, want %d", got, want))
}
}