goexp := goExperiment
godebug := goDebug
+ gomodvers := ""
// collect flags
for len(args) > 0 && strings.HasPrefix(args[0], "-") {
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])
}
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)
}
--- /dev/null
+// 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]{}
+}
--- /dev/null
+// 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)
+// }
+// }
--- /dev/null
+// 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