From: Robert Griesemer Date: Mon, 29 Oct 2018 19:35:59 +0000 (-0700) Subject: cmd/compile: revert "typecheck types and funcs before consts" X-Git-Tag: go1.12beta1~597 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=70dd90c4a93d26215a3514d975c2692724d05ac6;p=gostls13.git cmd/compile: revert "typecheck types and funcs before consts" This reverts commit 9ce87a63b9f440b452ada1ff89ccb1c4f3ca919f. The fix addresses the specific test case, but not the general problem. Updates #24755. Change-Id: I0ba8463b41b099b1ebf49759f88a423b40f70d58 Reviewed-on: https://go-review.googlesource.com/c/145617 Run-TryBot: Robert Griesemer Reviewed-by: Matthew Dempsky TryBot-Result: Gobot Gobot --- diff --git a/src/cmd/compile/internal/gc/main.go b/src/cmd/compile/internal/gc/main.go index 09378bab6e..339e8e08cd 100644 --- a/src/cmd/compile/internal/gc/main.go +++ b/src/cmd/compile/internal/gc/main.go @@ -480,7 +480,7 @@ func Main(archInit func(*Arch)) { // Process top-level declarations in phases. - // Phase 1: type, and names and types of funcs. + // Phase 1: const, type, and names and types of funcs. // This will gather all the information about types // and methods but doesn't depend on any of it. defercheckwidth() @@ -489,29 +489,16 @@ func Main(archInit func(*Arch)) { timings.Start("fe", "typecheck", "top1") for i := 0; i < len(xtop); i++ { n := xtop[i] - if op := n.Op; op != ODCL && op != OAS && op != OAS2 && op != ODCLCONST { + if op := n.Op; op != ODCL && op != OAS && op != OAS2 { xtop[i] = typecheck(n, Etop) } } - // Phase 2: Constant declarations. - // To have named types fully type checked, depends on phase 1. - - // Don't use range--typecheck can add closures to xtop. - timings.Start("fe", "typecheck", "top2") - for i := 0; i < len(xtop); i++ { - n := xtop[i] - if op := n.Op; op == ODCLCONST { - xtop[i] = typecheck(n, Etop) - } - } - - // Phase 3: Variable assignments. + // Phase 2: Variable assignments. // To check interface assignments, depends on phase 1. - // To use constants, depends on phase 2. // Don't use range--typecheck can add closures to xtop. - timings.Start("fe", "typecheck", "top3") + timings.Start("fe", "typecheck", "top2") for i := 0; i < len(xtop); i++ { n := xtop[i] if op := n.Op; op == ODCL || op == OAS || op == OAS2 { diff --git a/test/fixedbugs/issue24755.go b/test/fixedbugs/issue24755.go deleted file mode 100644 index 07c9d5a418..0000000000 --- a/test/fixedbugs/issue24755.go +++ /dev/null @@ -1,16 +0,0 @@ -// errorcheck - -// Copyright 2018 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. - -// Tests that all types and functions are type-checked before any constant -// declaration is. Issue #24755. -package p - -type I interface{ F() } -type T struct{} - -const _ = I(T{}) // ERROR "const initializer I\(T literal\) is not a constant" - -func (T) F() {}