Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: unexported interface method declared in body of exported inlined function causes import error #14164

Closed
albertjin opened this issue Jan 30, 2016 · 4 comments
Milestone

Comments

@albertjin
Copy link

Version: go1.6rc1/darwin

Note that go1.5.x does not have this issue. Maybe this is a new feature by design that I don't know, but the error message does not tell the point of problem.

Let's have a package with the following contents,

// file: a.go
package a

func Hello() {
}

func IsInternalErr(err error) (ok bool) {
    _, ok = err.(interface{internal()})
    return
}

// file: a_test.go
package a

import "testing"

func TestHello(t *testing.T) {
    Hello()
}

Then test it,

$ go test a
# testmain
/var/folders/c3/vzt2kvj51f14fs5nsr992z_w0000gn/T/go-build849241500/a/_test/_testmain.go:12: syntax error: unexpected @
FAIL a [build failed]

Note that the problem is not about testing. If this package is used by a program, it reports the problem at the line of import.

In the function IsInternalErr(), change this line,

  _, ok = err.(interface{internal()})

to the following with capitalized interface method name Internal,

  _, ok = err.(interface{Internal()})

the problem is gone.

@griesemer griesemer self-assigned this Jan 30, 2016
@griesemer
Copy link
Contributor

Haven't investigated yet but if real it's related to the new parser. Will look into this later this weekend.

@griesemer
Copy link
Contributor

Definitively an error with the rewritten parser. Given a 3rd file, main.go:

package main
import "./a"
func main() {}

The error is due to a bug in the parser:

$ go tool compile a.go a_test.go
$ go tool compile -h main.go 
main.go:2: syntax error: unexpected @
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x1fded0]

goroutine 1 [running]:
cmd/compile/internal/gc.hcrash()
    /Users/gri/go/src/cmd/compile/internal/gc/subr.go:96 +0x50
cmd/compile/internal/gc.yyerrorl(0x2, 0x442ee0, 0x2, 0xc8200aee98, 0x1, 0x1)
    /Users/gri/go/src/cmd/compile/internal/gc/subr.go:103 +0x76
cmd/compile/internal/gc.Yyerror(0x484780, 0x1b, 0xc8200af008, 0x1, 0x1)
    /Users/gri/go/src/cmd/compile/internal/gc/subr.go:137 +0x464
cmd/compile/internal/gc.(*parser).syntax_error(0x974b80, 0x0, 0x0)
    /Users/gri/go/src/cmd/compile/internal/gc/parser.go:158 +0x1af
cmd/compile/internal/gc.(*parser).interfacedcl(0x974b80, 0x0)
    /Users/gri/go/src/cmd/compile/internal/gc/parser.go:2513 +0x25f
cmd/compile/internal/gc.(*parser).interfacetype(0x974b80, 0x0)
    /Users/gri/go/src/cmd/compile/internal/gc/parser.go:2008 +0x71
cmd/compile/internal/gc.(*parser).try_ntype(0x974b80, 0x0)
    /Users/gri/go/src/cmd/compile/internal/gc/parser.go:1914 +0x3b7
cmd/compile/internal/gc.(*parser).ntype(0x974b80, 0x0)
    /Users/gri/go/src/cmd/compile/internal/gc/parser.go:1831 +0x2e
cmd/compile/internal/gc.(*parser).operand(0x974b80, 0x0, 0x0)
    /Users/gri/go/src/cmd/compile/internal/gc/parser.go:1496 +0x1a7
cmd/compile/internal/gc.(*parser).pexpr(0x974b80, 0x0, 0x0)
    /Users/gri/go/src/cmd/compile/internal/gc/parser.go:1537 +0x48
cmd/compile/internal/gc.(*parser).uexpr(0x974b80, 0x0)
    /Users/gri/go/src/cmd/compile/internal/gc/parser.go:1399 +0x19f
cmd/compile/internal/gc.(*parser).bexpr(0x974b80, 0x1, 0x974b88)
    /Users/gri/go/src/cmd/compile/internal/gc/parser.go:1278 +0x25
cmd/compile/internal/gc.(*parser).expr(0x974b80, 0x0)
    /Users/gri/go/src/cmd/compile/internal/gc/parser.go:1297 +0x33
cmd/compile/internal/gc.(*parser).pexpr(0x974b80, 0xc800000000, 0x0)
    /Users/gri/go/src/cmd/compile/internal/gc/parser.go:1554 +0x66d
cmd/compile/internal/gc.(*parser).uexpr(0x974b80, 0x0)
    /Users/gri/go/src/cmd/compile/internal/gc/parser.go:1399 +0x19f
cmd/compile/internal/gc.(*parser).bexpr(0x974b80, 0x1, 0x117a8)
    /Users/gri/go/src/cmd/compile/internal/gc/parser.go:1278 +0x25
cmd/compile/internal/gc.(*parser).expr(0x974b80, 0x0)
    /Users/gri/go/src/cmd/compile/internal/gc/parser.go:1297 +0x33
cmd/compile/internal/gc.(*parser).expr_list(0x974b80, 0x0)
    /Users/gri/go/src/cmd/compile/internal/gc/parser.go:2769 +0x2e
cmd/compile/internal/gc.(*parser).simple_stmt(0x974b80, 0x1, 0x0)
    /Users/gri/go/src/cmd/compile/internal/gc/parser.go:712 +0x4c2
cmd/compile/internal/gc.(*parser).stmt(0x974b80, 0x0)
    /Users/gri/go/src/cmd/compile/internal/gc/parser.go:2631 +0x6f
cmd/compile/internal/gc.(*parser).stmt_list(0x974b80, 0x0)
    /Users/gri/go/src/cmd/compile/internal/gc/parser.go:2714 +0x59
cmd/compile/internal/gc.(*parser).fnbody(0x974b80, 0x0)
    /Users/gri/go/src/cmd/compile/internal/gc/parser.go:2215 +0x5d
cmd/compile/internal/gc.(*parser).hidden_import(0x974b80)
    /Users/gri/go/src/cmd/compile/internal/gc/parser.go:3000 +0x178
cmd/compile/internal/gc.(*parser).hidden_import_list(0x974b80)
    /Users/gri/go/src/cmd/compile/internal/gc/parser.go:3444 +0x28
cmd/compile/internal/gc.(*parser).import_there(0x974b80)
    /Users/gri/go/src/cmd/compile/internal/gc/parser.go:503 +0x26
cmd/compile/internal/gc.(*parser).import_stmt(0x974b80)
    /Users/gri/go/src/cmd/compile/internal/gc/parser.go:369 +0x6b
cmd/compile/internal/gc.(*parser).import_(0x974b80)
    /Users/gri/go/src/cmd/compile/internal/gc/parser.go:357 +0xb5
cmd/compile/internal/gc.(*parser).file(0x974b80)
    /Users/gri/go/src/cmd/compile/internal/gc/parser.go:316 +0x53
cmd/compile/internal/gc.parse_file()
    /Users/gri/go/src/cmd/compile/internal/gc/parser.go:56 +0x5a
cmd/compile/internal/gc.Main()
    /Users/gri/go/src/cmd/compile/internal/gc/lex.go:345 +0x1d44
cmd/compile/internal/amd64.Main()
    /Users/gri/go/src/cmd/compile/internal/amd64/galign.go:127 +0x58d
main.main()
    /Users/gri/go/src/cmd/compile/main.go:32 +0x395

parser.interfacedcl needs to accept also '@', not just LNAME.

Will fix.

@griesemer griesemer added this to the Go1.6 milestone Jan 30, 2016
@bradfitz bradfitz changed the title Using lower case interface method name causes error message at import: "syntax error: unexpected @" cmd/compile: using lower case interface method name causes error message at import: "syntax error: unexpected @" Jan 31, 2016
@griesemer griesemer changed the title cmd/compile: using lower case interface method name causes error message at import: "syntax error: unexpected @" cmd/compile: unexported interface method in declared in body of exported inlined function causes error message at import: "syntax error: unexpected @" Feb 1, 2016
@griesemer griesemer changed the title cmd/compile: unexported interface method in declared in body of exported inlined function causes error message at import: "syntax error: unexpected @" cmd/compile: unexported interface method declared in body of exported inlined function causes error message at import: "syntax error: unexpected @" Feb 1, 2016
@griesemer griesemer changed the title cmd/compile: unexported interface method declared in body of exported inlined function causes error message at import: "syntax error: unexpected @" cmd/compile: unexported interface method declared in body of exported inlined function causes import error Feb 1, 2016
@griesemer
Copy link
Contributor

@gopherbot
Copy link

CL https://golang.org/cl/19087 mentions this issue.

@golang golang locked and limited conversation to collaborators Feb 3, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants