]> Cypherpunks.ru repositories - gostls13.git/commitdiff
go/types: don't declare 'comparable' when typeparams are disabled
authorRob Findley <rfindley@google.com>
Sun, 30 May 2021 02:14:12 +0000 (22:14 -0400)
committerRobert Findley <rfindley@google.com>
Sun, 30 May 2021 17:47:50 +0000 (17:47 +0000)
Fixes #46453

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

index 9c71277264b85200daf308896e7a60735f848788..6c3b630a1b6ef54b075caec94d1595185534ec1d 100644 (file)
@@ -330,6 +330,14 @@ func TestIndexRepresentability(t *testing.T) {
        checkFiles(t, &StdSizes{4, 4}, "", []string{"index.go"}, [][]byte{[]byte(src)}, false)
 }
 
+func TestIssue46453(t *testing.T) {
+       if typeparams.Enabled {
+               t.Skip("type params are enabled")
+       }
+       const src = "package p\ntype _ comparable // ERROR \"undeclared name: comparable\""
+       checkFiles(t, nil, "", []string{"issue46453.go"}, [][]byte{[]byte(src)}, false)
+}
+
 func TestCheck(t *testing.T)     { DefPredeclaredTestFuncs(); testDir(t, "check") }
 func TestExamples(t *testing.T)  { testDir(t, "examples") }
 func TestFixedbugs(t *testing.T) { testDir(t, "fixedbugs") }
index 7c211fa6f7e4add4026f29dc454f7d2f72331f4d..d7feb2c609efa93829bc90bd9176d1d9a423bf94 100644 (file)
@@ -8,6 +8,7 @@ package types
 
 import (
        "go/constant"
+       "go/internal/typeparams"
        "go/token"
        "strings"
 )
@@ -237,7 +238,9 @@ func init() {
        defPredeclaredConsts()
        defPredeclaredNil()
        defPredeclaredFuncs()
-       defPredeclaredComparable()
+       if typeparams.Enabled {
+               defPredeclaredComparable()
+       }
 
        universeIota = Universe.Lookup("iota").(*Const)
        universeByte = Universe.Lookup("byte").(*TypeName).typ.(*Basic)