From bbe1be5c19f04816f5f9162c2be75351480c92a0 Mon Sep 17 00:00:00 2001 From: Dan Scales Date: Mon, 29 Nov 2021 11:45:17 -0800 Subject: cmd/compile: report channel size errors correctly for -G=3 First, we need to set base.Pos in varDecl() and typeDecl(), so it will be correct if we need to report type size errors while converting types. Changed error calls in types/sizes.go to use Errorf, not ErrorfAt, since we want to use base.Pos (which will set from t.Pos(), if that is available). Second, we need to add an extra call CalcSize(t1.Elem()) in the TCHANARGS case of CalcSize(). We can use CalcSize() rather than CheckSize(), since we know the top-level recursive type will have been calculated by the time we process the fake TCHANARGS type. In -G=0 mode, the size of the channel element has often been calculated because of some other processing (but not in the case of #49767). But in -G=3 mode, we just calculate sizes during the single noder2 pass, so we are more likely to have not gotten to calculating the size of the element yet, depending on the order of processing of the deferredTypeStack. Fixes the tests fixedbugs/issue{42058a,42058b}.go that were disabled for -G=3 mode. Had to add exceptions in stdlib_test.go for go/types and types2, because the types2 typechecker does not know about type size limits. Fixes #49814 Fixes #49771 Updates #49767 Change-Id: I77d058e8ceff68a58c4c386a8cf46799c54b04c3 Reviewed-on: https://go-review.googlesource.com/c/go/+/367955 Trust: Dan Scales Run-TryBot: Dan Scales TryBot-Result: Gopher Robot Reviewed-by: Keith Randall --- src/cmd/compile/internal/noder/decl.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/cmd/compile/internal/noder') 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) -- cgit v1.3