0
1
mirror of https://github.com/golang/go synced 2024-11-11 12:49:30 +00:00
go/test/fixedbugs/issue27557.go
Matthew Dempsky adedf54288 [dev.typeparams] test: rename blank functions
This CL renames blank functions in the test/ directory so that they
don't rely on the compiler doing anything more than typechecking them.

In particular, I ran this search to find files that used blank
functions and methods:

$ git grep -l '^func.*\b_(' | xargs grep -n '^' | grep '\.go:1:' | grep -v '// errorcheck$'

I then skipped updating a few files:

* blank.go
* fixedbugs/issue11699.go
* fixedbugs/issue29870.go

  These tests specifically check that blank functions/methods work.

* interface/fail.go

  Not sure the motivation for the blank method here, but it's empty
  anyway.

* typeparam/tparam1.go

  Type-checking test, but uses "-G" (to use types2 instead of typecheck).

Updates #47446.

Change-Id: I9ec1714f499808768bd0dcd7ae6016fb2b078e5e
Reviewed-on: https://go-review.googlesource.com/c/go/+/338094
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
2021-07-28 21:41:07 +00:00

42 lines
949 B
Go

// errorcheck -0 -l -m
// Copyright 2019 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.
package p
var sink interface{}
func f1() {
var t T
f := t.noescape // ERROR "t.noescape does not escape"
f()
}
func f2() {
var t T // ERROR "moved to heap"
f := t.escape // ERROR "t.escape does not escape"
f()
}
func f3() {
var t T // ERROR "moved to heap"
f := t.returns // ERROR "t.returns does not escape"
sink = f()
}
type T struct{}
func (t *T) noescape() {} // ERROR "t does not escape"
func (t *T) escape() { sink = t } // ERROR "leaking param: t$"
func (t *T) returns() *T { return t } // ERROR "leaking param: t to result ~r0 level=0"
func (t *T) recursive() { // ERROR "leaking param: t$"
sink = t
var t2 T // ERROR "moved to heap"
f := t2.recursive // ERROR "t2.recursive does not escape"
f()
}