]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: check for missing function body earlier
authorJosh Bleecher Snyder <josharian@gmail.com>
Mon, 20 Mar 2017 20:16:07 +0000 (13:16 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Tue, 21 Mar 2017 04:04:46 +0000 (04:04 +0000)
Tested by fixedbugs/issue3705.go.

This removes a dependency on lineno
from near the backend.

Change-Id: I228bd0ad7295cf881b9bdeb0df9d18483fb96821
Reviewed-on: https://go-review.googlesource.com/38382
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/gc/noder.go
src/cmd/compile/internal/gc/pgen.go

index a7f0ba54f04259b0ac9c714c155a89718cf8493e..41c05c648022ddae4a5fcf6cdf46ecb6a0bbcd86 100644 (file)
@@ -319,6 +319,10 @@ func (p *noder) funcDecl(fun *syntax.FuncDecl) *Node {
 
        funcbody(f)
 
+       if f.Nbody.Len() == 0 && (pure_go || strings.HasPrefix(f.Func.Nname.Sym.Name, "init.")) {
+               yyerrorl(f.Pos, "missing function body for %q", f.Func.Nname.Sym.Name)
+       }
+
        return f
 }
 
index e588ab210c247cd8f279f49ce37d48153e2cd57a..6294c125c78f226f9ae858a896302fa38b19dddf 100644 (file)
@@ -12,7 +12,6 @@ import (
        "cmd/internal/sys"
        "fmt"
        "sort"
-       "strings"
 )
 
 // "Portable" code generation.
@@ -278,11 +277,6 @@ func compile(fn *Node) {
        dowidth(fn.Type)
 
        if fn.Nbody.Len() == 0 {
-               if pure_go || strings.HasPrefix(fn.Func.Nname.Sym.Name, "init.") {
-                       yyerror("missing function body for %q", fn.Func.Nname.Sym.Name)
-                       return
-               }
-
                emitptrargsmap()
                return
        }