]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile: report mismatch between types because of //go:notinheap
authorDan Scales <danscales@google.com>
Thu, 8 Jul 2021 19:07:01 +0000 (12:07 -0700)
committerDan Scales <danscales@google.com>
Fri, 9 Jul 2021 16:14:34 +0000 (16:14 +0000)
types2 currently ignores pragmas, so it does not catch a conversion
error when converting a pointer to a type which is NOT marked notinheap
to a pointer to a convertible type, but which is marked notinheap.

So, we specifically check for this error in transformConv() and report
it during noder2.

Change-Id: I6e9c9ee29f53fa5e490c1ac8306e2191db59eeb4
Reviewed-on: https://go-review.googlesource.com/c/go/+/333369
Run-TryBot: Dan Scales <danscales@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
Trust: Robert Griesemer <gri@golang.org>
Trust: Dan Scales <danscales@google.com>

src/cmd/compile/internal/noder/irgen.go
src/cmd/compile/internal/noder/transform.go
test/run.go

index 64c29435b5ec92191bc6ebc320e825370e90909f..880073a89ec19558d4afa42447f93603d9aebd84 100644 (file)
@@ -219,6 +219,10 @@ Outer:
                }
        }
 
+       // Check for unusual case where noder2 encounters a type error that types2
+       // doesn't check for (e.g. notinheap incompatibility).
+       base.ExitIfErrors()
+
        typecheck.DeclareUniverse()
 
        for _, p := range noders {
index e02b7e758dbe4a2becb44fd9a49a8f2fbf10e098..efbc8f68ceee79b6c0cf2768f9f939d8c2811061 100644 (file)
@@ -85,7 +85,15 @@ func stringtoruneslit(n *ir.ConvExpr) ir.Node {
 // etc.  Corresponds to typecheck.tcConv.
 func transformConv(n *ir.ConvExpr) ir.Node {
        t := n.X.Type()
-       op, _ := typecheck.Convertop(n.X.Op() == ir.OLITERAL, t, n.Type())
+       op, why := typecheck.Convertop(n.X.Op() == ir.OLITERAL, t, n.Type())
+       if op == ir.OXXX {
+               // types2 currently ignores pragmas, so a 'notinheap' mismatch is the
+               // one type-related error that it does not catch. This error will be
+               // caught here by Convertop (see two checks near beginning of
+               // Convertop) and reported at the end of noding.
+               base.ErrorfAt(n.Pos(), "cannot convert %L to type %v%s", n.X, n.Type(), why)
+               return n
+       }
        n.SetOp(op)
        switch n.Op() {
        case ir.OCONVNOP:
index 90861786df93943ef2c776fa749b693f4265aeda..d6209c259154c2fa34b3c774bb6c25ac9086707f 100644 (file)
@@ -2204,8 +2204,7 @@ var g3Failures = setOf(
 
        "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/11.go", // types2/noder2 should give conversion error, because of "notinheap" mismatch
+       "typeparam/mdempsky/4.go", // -G=3 can't export functions with labeled breaks in loops
 )
 
 var unifiedFailures = setOf(