mirror of
https://github.com/golang/go
synced 2024-11-23 15:20:03 -07:00
cb6e0639fb
Fixes #8481. Inform the user that init functions cannot be directly invoked in user code, as mandated by the spec at: http://golang.org/ref/spec#Program_initialization_and_execution. Change-Id: Ib12c0c08718ffd48b76b6f9b13c76bb6612d2e7b Reviewed-on: https://go-review.googlesource.com/34790 Reviewed-by: Keith Randall <khr@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
22 lines
481 B
Go
22 lines
481 B
Go
// errorcheck
|
|
|
|
// Copyright 2011 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 erroneous use of init is detected.
|
|
// Does not compile.
|
|
|
|
package main
|
|
|
|
import "runtime"
|
|
|
|
func init() {
|
|
}
|
|
|
|
func main() {
|
|
init() // ERROR "cannot refer to init functions"
|
|
runtime.init() // ERROR "unexported.*runtime\.init"
|
|
var _ = init // ERROR "cannot refer to init functions"
|
|
}
|