Removed a case in transformCall() where we were setting a type on n,
which isn't needed, since noder2 already set the type of n. More
importantly, we are losing information, since the type of the results
may be a shape type, but the actual type of call is the known type
from types2, which may be a concrete type (in this case Zero[MyInt]).
That concrete type will then be used correctly if the concrete result is
converted to an interface.
If we are inlining the call to Zero[MyInt], we need to add an implicit
CONVNOP operation, since we are going to use the result variable
directly, which has a shape type. So, add an implicit CONVNOP to
remember that the known type is the concrete type.
Also cleaned up 14.go a bit, so it is more understandable. Renamed type
T to AnyInt, since T is used elsewhere as a type parameter. Reformatted
Zero function and added a comment.
Change-Id: Id917a2e054e0bbae9bd302232853fa8741d49b64
Reviewed-on: https://go-review.googlesource.com/c/go/+/336430
Trust: Dan Scales <danscales@google.com>
Reviewed-by: Keith Randall <khr@golang.org>
if have := len(n.ReturnVars); have != 1 {
base.FatalfAt(n.Pos(), "inlined call has %v results, expected 1", have)
}
+ if !n.Type().HasShape() && n.ReturnVars[0].Type().HasShape() {
+ // If the type of the call is not a shape, but the type of the return value
+ // is a shape, we need to do an implicit conversion, so the real type
+ // of n is maintained.
+ r := NewConvExpr(n.Pos(), OCONVNOP, n.Type(), n.ReturnVars[0])
+ r.SetTypecheck(1)
+ return r
+ }
return n.ReturnVars[0]
}
typecheck.FixMethodCall(n)
}
if t.NumResults() == 1 {
- n.SetType(l.Type().Results().Field(0).Type)
-
if n.Op() == ir.OCALLFUNC && n.X.Op() == ir.ONAME {
if sym := n.X.(*ir.Name).Sym(); types.IsRuntimePkg(sym.Pkg) && sym.Name == "getg" {
// Emit code for runtime.getg() directly instead of calling function.
"typeparam/mdempsky/4.go", // -G=3 can't export functions with labeled breaks in loops
- "typeparam/cons.go", // causes an unreachable method
- "typeparam/issue44688.go", // interface conversion fails due to missing method
- "typeparam/mdempsky/14.go", // interface comparison failure
+ "typeparam/cons.go", // causes an unreachable method
+ "typeparam/issue44688.go", // interface conversion fails due to missing method
)
var unifiedFailures = setOf(
package main
-func Zero[T any]() (_ T) { return }
+// Zero returns the zero value of T
+func Zero[T any]() (_ T) {
+ return
+}
-type T[X any] int
+type AnyInt[X any] int
-func (T[X]) M() {
+func (AnyInt[X]) M() {
var have interface{} = Zero[X]()
var want interface{} = Zero[MyInt]()
type I interface{ M() }
type MyInt int
-type U = T[MyInt]
+type U = AnyInt[MyInt]
var x = U(0)
var i I = x