diff --git a/src/cmd/internal/testdir/testdir_test.go b/src/cmd/internal/testdir/testdir_test.go index 0810cef257da9cd7a6de32bf107c51c4b84ffee9..86ebf7ded619558638e79cd25e8ee66613a38e50 100644 --- a/src/cmd/internal/testdir/testdir_test.go +++ b/src/cmd/internal/testdir/testdir_test.go @@ -543,6 +543,7 @@ func (t test) run() error { goexp := goExperiment godebug := goDebug + gomodvers := "" // collect flags for len(args) > 0 && strings.HasPrefix(args[0], "-") { @@ -583,6 +584,10 @@ func (t test) run() error { godebug += args[0] runenv = append(runenv, "GODEBUG="+godebug) + case "-gomodversion": // set the GoVersion in generated go.mod files (just runindir ATM) + args = args[1:] + gomodvers = args[0] + default: flags = append(flags, args[0]) } @@ -900,7 +905,11 @@ func (t test) run() error { t.Fatal(err) } - modFile := fmt.Sprintf("module %s\ngo 1.14\n", modName) + modVersion := gomodvers + if modVersion == "" { + modVersion = "1.14" + } + modFile := fmt.Sprintf("module %s\ngo %s\n", modName, modVersion) if err := os.WriteFile(filepath.Join(gopathSrcDir, "go.mod"), []byte(modFile), 0666); err != nil { t.Fatal(err) } diff --git a/test/fixedbugs/issue68526.dir/a/a.go b/test/fixedbugs/issue68526.dir/a/a.go new file mode 100644 index 0000000000000000000000000000000000000000..7c2961c28f08010bdf5d5dbc533443f5c4f3977a --- /dev/null +++ b/test/fixedbugs/issue68526.dir/a/a.go @@ -0,0 +1,17 @@ +// Copyright 2024 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. + +//go:build goexperiment.aliastypeparams + +package a + +// TODO(#68778): enable once type parameterized aliases are allowed in exportdata. +// type A[T any] = struct{ F T } + +type B = struct{ F int } + +func F() B { + type a[T any] = struct{ F T } + return a[int]{} +} diff --git a/test/fixedbugs/issue68526.dir/main.go b/test/fixedbugs/issue68526.dir/main.go new file mode 100644 index 0000000000000000000000000000000000000000..0353ca5daaa181df429dd76787b06cc6681684f8 --- /dev/null +++ b/test/fixedbugs/issue68526.dir/main.go @@ -0,0 +1,45 @@ +// Copyright 2024 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. + +//go:build goexperiment.aliastypeparams + +package main + +import ( + "issue68526.dir/a" +) + +func main() { + unexported() + // exported() +} + +func unexported() { + var want struct{ F int } + + if any(want) != any(a.B{}) || any(want) != any(a.F()) { + panic("zero value of alias and concrete type not identical") + } +} + +// TODO(#68778): enable once type parameterized aliases are allowed in exportdata. + +// func exported() { +// var ( +// astr a.A[string] +// aint a.A[int] +// ) + +// if any(astr) != any(struct{ F string }{}) || any(aint) != any(struct{ F int }{}) { +// panic("zero value of alias and concrete type not identical") +// } + +// if any(astr) == any(aint) { +// panic("zero value of struct{ F string } and struct{ F int } are not distinct") +// } + +// if got := fmt.Sprintf("%T", astr); got != "struct { F string }" { +// panic(got) +// } +// } diff --git a/test/fixedbugs/issue68526.go b/test/fixedbugs/issue68526.go new file mode 100644 index 0000000000000000000000000000000000000000..3067aa76222941b0c17099e8fd9d3b5597287e86 --- /dev/null +++ b/test/fixedbugs/issue68526.go @@ -0,0 +1,7 @@ +// runindir -goexperiment aliastypeparams -gomodversion "1.23" + +// Copyright 2024 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 ignored