Also: Remove double "go:" prefix in related error message.
Fixes #18882.
Change-Id: Ifbbd8e2f7529b43f035d3dbf7ca4a91f212bc6b6
Reviewed-on: https://go-review.googlesource.com/36121
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
return s
}
-func pragcgo(text string) string {
+// pragcgo is called concurrently if files are parsed concurrently.
+func (p *noder) pragcgo(pos src.Pos, text string) string {
f := pragmaFields(text)
verb := f[0][3:] // skip "go:"
return fmt.Sprintln(verb, local, remote)
default:
- yyerror(`usage: //go:%s local [remote]`, verb)
+ p.error(syntax.Error{Pos: pos, Msg: fmt.Sprintf(`usage: //go:%s local [remote]`, verb)})
}
case "cgo_import_dynamic":
switch {
return fmt.Sprintln(verb, local, remote, library)
default:
- yyerror(`usage: //go:cgo_import_dynamic local [remote ["library"]]`)
+ p.error(syntax.Error{Pos: pos, Msg: `usage: //go:cgo_import_dynamic local [remote ["library"]]`})
}
case "cgo_import_static":
switch {
return fmt.Sprintln(verb, local)
default:
- yyerror(`usage: //go:cgo_import_static local`)
+ p.error(syntax.Error{Pos: pos, Msg: `usage: //go:cgo_import_static local`})
}
case "cgo_dynamic_linker":
switch {
return fmt.Sprintln(verb, path)
default:
- yyerror(`usage: //go:cgo_dynamic_linker "path"`)
+ p.error(syntax.Error{Pos: pos, Msg: `usage: //go:cgo_dynamic_linker "path"`})
}
case "cgo_ldflag":
switch {
return fmt.Sprintln(verb, arg)
default:
- yyerror(`usage: //go:cgo_ldflag "arg"`)
+ p.error(syntax.Error{Pos: pos, Msg: `usage: //go:cgo_ldflag "arg"`})
}
}
return ""
package gc
-import "testing"
+import (
+ "cmd/internal/src"
+ "testing"
+)
func eq(a, b []string) bool {
if len(a) != len(b) {
{`go:cgo_ldflag "a rg"`, "cgo_ldflag 'a rg'\n"},
}
+ var p noder
for _, tt := range tests {
- got := pragcgo(tt.in)
+ got := p.pragcgo(src.NoPos, tt.in)
if got != tt.want {
t.Errorf("pragcgo(%q) = %q; want %q", tt.in, got, tt.want)
continue
lineno = Ctxt.PosTable.XPos(pos)
}
+// error is called concurrently if files are parsed concurrently.
func (p *noder) error(err error) {
p.err <- err.(syntax.Error)
}
+// pragma is called concurrently if files are parsed concurrently.
func (p *noder) pragma(pos src.Pos, text string) syntax.Pragma {
switch {
case strings.HasPrefix(text, "line "):
p.linknames = append(p.linknames, linkname{pos, f[1], f[2]})
case strings.HasPrefix(text, "go:cgo_"):
- // TODO(gri): lineno = p.baseline + int32(line) - 1 // pragcgo may call yyerror
- p.pragcgobuf += pragcgo(text)
+ p.pragcgobuf += p.pragcgo(pos, text)
fallthrough // because of //go:cgo_unsafe_args
default:
verb := text
prag := pragmaValue(verb)
const runtimePragmas = Systemstack | Nowritebarrier | Nowritebarrierrec | Yeswritebarrierrec
if !compiling_runtime && prag&runtimePragmas != 0 {
- p.error(syntax.Error{Pos: pos, Msg: fmt.Sprintf("//go:%s only allowed in runtime", verb)})
+ p.error(syntax.Error{Pos: pos, Msg: fmt.Sprintf("//%s only allowed in runtime", verb)})
}
return prag
}
"issue15002.go", // uses Mmap; testTestDir should consult build tags
"issue16369.go", // go/types handles this correctly - not an issue
"issue18459.go", // go/types doesn't check validity of //go:xxx directives
+ "issue18882.go", // go/types doesn't check validity of //go:xxx directives
)
}
package main
-//go:nowritebarrier // ERROR "go:nowritebarrier only allowed in runtime"
+//go:nowritebarrier // ERROR "//go:nowritebarrier only allowed in runtime"
func main() {
}
--- /dev/null
+// errorcheck
+
+// Copyright 2017 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.
+
+// Verify that we have a line number for this error.
+
+package main
+
+//go:cgo_ldflag // ERROR "usage: //go:cgo_ldflag"
+func main() {
+}