aboutsummaryrefslogtreecommitdiff
path: root/src/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd')
-rw-r--r--src/cmd/compile/internal/noder/decl.go4
-rw-r--r--src/cmd/compile/internal/types/size.go15
-rw-r--r--src/cmd/compile/internal/types2/stdlib_test.go2
3 files changed, 16 insertions, 5 deletions
diff --git a/src/cmd/compile/internal/noder/decl.go b/src/cmd/compile/internal/noder/decl.go
index 027c8598fd..b7fd95e2e8 100644
--- a/src/cmd/compile/internal/noder/decl.go
+++ b/src/cmd/compile/internal/noder/decl.go
@@ -160,6 +160,8 @@ func (g *irgen) funcDecl(out *ir.Nodes, decl *syntax.FuncDecl) {
}
func (g *irgen) typeDecl(out *ir.Nodes, decl *syntax.TypeDecl) {
+ // Set the position for any error messages we might print (e.g. too large types).
+ base.Pos = g.pos(decl)
assert(g.curDecl == "")
// Set g.curDecl to the type name, as context for the type params declared
// during types2-to-types1 translation if this is a generic type.
@@ -244,6 +246,8 @@ func (g *irgen) typeDecl(out *ir.Nodes, decl *syntax.TypeDecl) {
func (g *irgen) varDecl(out *ir.Nodes, decl *syntax.VarDecl) {
pos := g.pos(decl)
+ // Set the position for any error messages we might print (e.g. too large types).
+ base.Pos = pos
names := make([]*ir.Name, len(decl.NameList))
for i, name := range decl.NameList {
names[i], _ = g.def(name)
diff --git a/src/cmd/compile/internal/types/size.go b/src/cmd/compile/internal/types/size.go
index 0f3db06c1d..fb6accdc64 100644
--- a/src/cmd/compile/internal/types/size.go
+++ b/src/cmd/compile/internal/types/size.go
@@ -450,16 +450,21 @@ func CalcSize(t *Type) {
CheckSize(t.Elem())
- // make fake type to check later to
- // trigger channel argument check.
+ // Make fake type to trigger channel element size check after
+ // any top-level recursive type has been completed.
t1 := NewChanArgs(t)
CheckSize(t1)
case TCHANARGS:
t1 := t.ChanArgs()
CalcSize(t1) // just in case
+ // Make sure size of t1.Elem() is calculated at this point. We can
+ // use CalcSize() here rather than CheckSize(), because the top-level
+ // (possibly recursive) type will have been calculated before the fake
+ // chanargs is handled.
+ CalcSize(t1.Elem())
if t1.Elem().width >= 1<<16 {
- base.ErrorfAt(typePos(t1), "channel element type too large (>64kB)")
+ base.Errorf("channel element type too large (>64kB)")
}
w = 1 // anything will do
@@ -492,7 +497,7 @@ func CalcSize(t *Type) {
if t.Elem().width != 0 {
cap := (uint64(MaxWidth) - 1) / uint64(t.Elem().width)
if uint64(t.NumElem()) > cap {
- base.ErrorfAt(typePos(t), "type %L larger than address space", t)
+ base.Errorf("type %L larger than address space", t)
}
}
w = t.NumElem() * t.Elem().width
@@ -539,7 +544,7 @@ func CalcSize(t *Type) {
}
if PtrSize == 4 && w != int64(int32(w)) {
- base.ErrorfAt(typePos(t), "type %v too large", t)
+ base.Errorf("type %v too large", t)
}
t.width = w
diff --git a/src/cmd/compile/internal/types2/stdlib_test.go b/src/cmd/compile/internal/types2/stdlib_test.go
index 9c22f01673..5ac01ac253 100644
--- a/src/cmd/compile/internal/types2/stdlib_test.go
+++ b/src/cmd/compile/internal/types2/stdlib_test.go
@@ -194,6 +194,8 @@ func TestStdFixed(t *testing.T) {
"issue42058b.go", // types2 does not have constraints on channel element size
"issue48097.go", // go/types doesn't check validity of //go:xxx directives, and non-init bodyless function
"issue48230.go", // go/types doesn't check validity of //go:xxx directives
+ "issue49767.go", // go/types does not have constraints on channel element size
+ "issue49814.go", // go/types does not have constraints on array size
)
}