]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: use type position for error message in align.go
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Mon, 19 Oct 2020 11:32:15 +0000 (18:32 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 20 Oct 2020 02:05:01 +0000 (02:05 +0000)
This helps the compiler reports the right place where the type declared,
instead of relying on global lineno, which maybe set to wrong value at
the time the error is reported.

Fixes #42058

Change-Id: I06d34aa9b0236d122f4a0d72e66675ded022baac
Reviewed-on: https://go-review.googlesource.com/c/go/+/263597
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>

src/cmd/compile/internal/gc/align.go
src/go/types/stdlib_test.go
test/fixedbugs/issue42058a.go [new file with mode: 0644]
test/fixedbugs/issue42058b.go [new file with mode: 0644]

index 4bc454df224fab3b3f8d2a692d5a2ba6accdec39..a3a0c8fce822e43226bbaa70a17d5d2e5ee42ccd 100644 (file)
@@ -86,7 +86,7 @@ func expandiface(t *types.Type) {
        sort.Sort(methcmp(methods))
 
        if int64(len(methods)) >= thearch.MAXWIDTH/int64(Widthptr) {
-               yyerror("interface too large")
+               yyerrorl(typePos(t), "interface too large")
        }
        for i, m := range methods {
                m.Offset = int64(i) * int64(Widthptr)
@@ -150,7 +150,7 @@ func widstruct(errtype *types.Type, t *types.Type, o int64, flag int) int64 {
                        maxwidth = 1<<31 - 1
                }
                if o >= maxwidth {
-                       yyerror("type %L too large", errtype)
+                       yyerrorl(typePos(errtype), "type %L too large", errtype)
                        o = 8 // small but nonzero
                }
        }
@@ -381,7 +381,7 @@ func dowidth(t *types.Type) {
                t1 := t.ChanArgs()
                dowidth(t1) // just in case
                if t1.Elem().Width >= 1<<16 {
-                       yyerror("channel element type too large (>64kB)")
+                       yyerrorl(typePos(t1), "channel element type too large (>64kB)")
                }
                w = 1 // anything will do
 
@@ -414,7 +414,7 @@ func dowidth(t *types.Type) {
                if t.Elem().Width != 0 {
                        cap := (uint64(thearch.MAXWIDTH) - 1) / uint64(t.Elem().Width)
                        if uint64(t.NumElem()) > cap {
-                               yyerror("type %L larger than address space", t)
+                               yyerrorl(typePos(t), "type %L larger than address space", t)
                        }
                }
                w = t.NumElem() * t.Elem().Width
@@ -456,7 +456,7 @@ func dowidth(t *types.Type) {
        }
 
        if Widthptr == 4 && w != int64(int32(w)) {
-               yyerror("type %v too large", t)
+               yyerrorl(typePos(t), "type %v too large", t)
        }
 
        t.Width = w
index f5a3273fa1c1d8873c8fa06aa8f6e9a01e144bc9..669e7bec20f8027437af34c5c4a9f87e4a926288 100644 (file)
@@ -183,6 +183,8 @@ func TestStdFixed(t *testing.T) {
                "issue31747.go",  // go/types does not have constraints on language level (-lang=go1.12) (see #31793)
                "issue34329.go",  // go/types does not have constraints on language level (-lang=go1.13) (see #31793)
                "bug251.go",      // issue #34333 which was exposed with fix for #34151
+               "issue42058a.go", // go/types does not have constraints on channel element size
+               "issue42058b.go", // go/types does not have constraints on channel element size
        )
 }
 
diff --git a/test/fixedbugs/issue42058a.go b/test/fixedbugs/issue42058a.go
new file mode 100644 (file)
index 0000000..67751a1
--- /dev/null
@@ -0,0 +1,13 @@
+// errorcheck
+
+// Copyright 2020 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.
+
+package p
+
+var c chan [2 << 16]byte // ERROR "channel element type too large"
+
+type T [1 << 17]byte
+
+var x chan T // ERROR "channel element type too large"
diff --git a/test/fixedbugs/issue42058b.go b/test/fixedbugs/issue42058b.go
new file mode 100644 (file)
index 0000000..03f86ee
--- /dev/null
@@ -0,0 +1,13 @@
+// errorcheck
+
+// Copyright 2020 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.
+
+package p
+
+var c chan [2 << 16]byte // ERROR "channel element type too large"
+
+func f() {
+       _ = 42
+}