name.Func = ir.NewFunc(r.pos())
name.Func.Nname = name
- // TODO(mdempsky): Make sure we're handling //go:nointerface
- // correctly. I don't think this is exercised within the Go repo.
-
r.ext.funcExt(name)
meth := types.NewField(name.Func.Pos(), sym, typ)
meth.Nname = name
+ meth.SetNointerface(name.Func.Pragma&ir.Nointerface != 0)
+
return meth
}
package b
-import "./a"
+import "issue30862.dir/a"
type EmbedImported struct {
a.NoitfStruct
"fmt"
"os"
- "./b"
+ "issue30862.dir/b"
)
// Test case for issue 30862.
-// rundir
+// runindir -goexperiment fieldtrack
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// is set when building it, whereas gccgo has field tracking
// enabled by default (hence the build tag below).
-// +build gccgo
-
package ignored
var g3Failures = setOf(
"writebarrier.go", // correct diagnostics, but different lines (probably irgen's fault)
+ "fixedbugs/issue30862.go", // -G=3 doesn't handle //go:nointerface
+
+ "typeparam/cons.go", // causes an unreachable method
"typeparam/nested.go", // -G=3 doesn't support function-local types with generics
"typeparam/mdempsky/4.go", // -G=3 can't export functions with labeled breaks in loops
"typeparam/mdempsky/13.go", // problem with interface as as a type arg.
-
- "typeparam/cons.go", // causes an unreachable method
+ "typeparam/mdempsky/15.go", // ICE in (*irgen).buildClosure
)
var unifiedFailures = setOf(
--- /dev/null
+// run -goexperiment fieldtrack -gcflags=-G=3
+
+// 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.
+
+// Test that generics, promoted methods, and //go:nointerface
+// interoperate as expected.
+
+package main
+
+import (
+ "reflect"
+)
+
+func TypeString[T any]() string {
+ return reflect.TypeOf(new(T)).Elem().String()
+}
+
+func Test[T, Bad, Good any]() {
+ switch interface{}(new(T)).(type) {
+ case Bad:
+ println("FAIL:", TypeString[T](), "matched", TypeString[Bad]())
+ case Good:
+ // ok
+ default:
+ println("FAIL:", TypeString[T](), "did not match", TypeString[Good]())
+ }
+}
+
+func TestE[T any]() { Test[T, interface{ EBad() }, interface{ EGood() }]() }
+func TestX[T any]() { Test[T, interface{ XBad() }, interface{ XGood() }]() }
+
+type E struct{}
+
+//go:nointerface
+func (E) EBad() {}
+func (E) EGood() {}
+
+type X[T any] struct{ E }
+
+//go:nointerface
+func (X[T]) XBad() {}
+func (X[T]) XGood() {}
+
+type W struct{ X[int] }
+
+func main() {
+ _ = E.EGood
+ _ = E.EBad
+
+ TestE[E]()
+
+ _ = X[int].EGood
+ _ = X[int].EBad
+ _ = X[int].XGood
+ _ = X[int].XBad
+
+ TestE[X[int]]()
+ TestX[X[int]]()
+
+ _ = W.EGood
+ _ = W.EBad
+ _ = W.XGood
+ _ = W.XBad
+
+ TestE[W]()
+ TestX[W]()
+}