]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/compile/internal/types2: add test for imported constraints pre-1.18
authorRobert Griesemer <gri@golang.org>
Sun, 14 Nov 2021 00:16:53 +0000 (16:16 -0800)
committerRobert Griesemer <gri@golang.org>
Mon, 15 Nov 2021 23:01:05 +0000 (23:01 +0000)
But exclude the test when running unified build for now
(the unified builder's importers are not yet updated to
handle extended interfaces).
Also, fix respective error position.

Fixes #47967.

Change-Id: I4e3d829b5c12001c024b9eefcc27f97b10c1d1e5
Reviewed-on: https://go-review.googlesource.com/c/go/+/363834
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

src/cmd/compile/internal/types2/check_test.go
src/cmd/compile/internal/types2/decl.go
src/cmd/compile/internal/types2/testdata/fixedbugs/issue47818.go2

index ddaacd2443633a9dba059ab5b2d20a0cf2b020fc..a5ecdf8b8118ff430d72fee727d4ceff018c04ea 100644 (file)
@@ -25,6 +25,7 @@ package types2_test
 import (
        "cmd/compile/internal/syntax"
        "flag"
+       "internal/buildcfg"
        "internal/testenv"
        "os"
        "path/filepath"
@@ -93,11 +94,27 @@ func asGoVersion(s string) string {
        return ""
 }
 
+// excludedForUnifiedBuild lists files that cannot be tested
+// when using the unified build's export data.
+// TODO(gri) enable as soon as the unified build supports this.
+var excludedForUnifiedBuild = map[string]bool{
+       "issue47818.go2": true,
+}
+
 func testFiles(t *testing.T, filenames []string, colDelta uint, manual bool) {
        if len(filenames) == 0 {
                t.Fatal("no source files")
        }
 
+       if buildcfg.Experiment.Unified {
+               for _, f := range filenames {
+                       if excludedForUnifiedBuild[filepath.Base(f)] {
+                               t.Logf("%s cannot be tested with unified build - skipped", f)
+                               return
+                       }
+               }
+       }
+
        var mode syntax.Mode
        if strings.HasSuffix(filenames[0], ".go2") || manual {
                mode |= syntax.AllowGenerics
index 739fc163de42a34e234edfb898952876e0f33bf7..91503f1fcd33ab0457854ee46093057c91f28313 100644 (file)
@@ -570,7 +570,7 @@ func (check *Checker) typeDecl(obj *TypeName, tdecl *syntax.TypeDecl, def *Named
                check.validType(obj.typ, nil)
                // If typ is local, an error was already reported where typ is specified/defined.
                if check.isImportedConstraint(rhs) && !check.allowVersion(check.pkg, 1, 18) {
-                       check.versionErrorf(tdecl.Type.Pos(), "go1.18", "using type constraint %s", rhs)
+                       check.versionErrorf(tdecl.Type, "go1.18", "using type constraint %s", rhs)
                }
        }).describef(obj, "validType(%s)", obj.Name())
 
index 166cc680dbcc57e120a6c0dc0837d2de7d723d24..2631118baed94a7f8163693a3f928c95c080a778 100644 (file)
@@ -8,6 +8,8 @@
 
 package go1_17
 
+import "constraints"
+
 type T[P /* ERROR type parameters require go1\.18 or later */ any /* ERROR undeclared name: any \(requires version go1\.18 or later\) */ ] struct{}
 
 // for init (and main, but we're not in package main) we should only get one error
@@ -56,4 +58,4 @@ type (
        _ = C2
 )
 
-// TODO(gri) need test cases for imported constraint types (see also issue #47967)
\ No newline at end of file
+type Ordered constraints /* ERROR using type constraint constraints\.Ordered requires go1\.18 or later */ .Ordered