mirror of
https://github.com/golang/go
synced 2024-11-19 00:44:40 -07:00
go.tools/go/types: add test cases for pending issues
The gc compiler is inconsistent how it handles method "mentions" with respect to initialization cycle detection (see issue 6703 for details). Pending a spec clarification, this CL assumes that for a method to be "mentioned", it must be mentioned as a method expression rather than a method value (closer in intent to "syntactic" mention). R=adonovan CC=golang-dev https://golang.org/cl/22050044
This commit is contained in:
parent
2e7d5a8b6b
commit
eb67edd047
@ -350,9 +350,6 @@ func (check *checker) selector(x *operand, e *ast.SelectorExpr) {
|
||||
isVariadic: sig.isVariadic,
|
||||
}
|
||||
|
||||
// TODO(gri) move this into exprInternal's call of check.selector
|
||||
// since that's the only place where we need to record a dependency
|
||||
// (requires that operands know method objects)
|
||||
check.addDeclDep(m)
|
||||
|
||||
} else {
|
||||
@ -418,9 +415,6 @@ func (check *checker) selector(x *operand, e *ast.SelectorExpr) {
|
||||
sig.recv = nil
|
||||
x.typ = &sig
|
||||
|
||||
// TODO(gri) see comment above for addDeclDep
|
||||
check.addDeclDep(obj)
|
||||
|
||||
default:
|
||||
unreachable()
|
||||
}
|
||||
|
@ -53,6 +53,7 @@ var tests = [][]string{
|
||||
{"testdata/cycles3.src"},
|
||||
{"testdata/cycles4.src"},
|
||||
{"testdata/init0.src"},
|
||||
{"testdata/init1.src"},
|
||||
{"testdata/decls0.src"},
|
||||
{"testdata/decls1.src"},
|
||||
{"testdata/decls2a.src", "testdata/decls2b.src"},
|
||||
|
@ -125,6 +125,7 @@ func TestStdtest(t *testing.T) {
|
||||
func TestStdfixed(t *testing.T) {
|
||||
testTestDir(t, filepath.Join(runtime.GOROOT(), "test", "fixedbugs"),
|
||||
"bug248.go", "bug302.go", "bug369.go", // complex test instructions - ignore
|
||||
"bug459.go", // incorrect test - see issue 6793 (pending spec clarification)
|
||||
"issue3924.go", // incorrect test - see issue 6671
|
||||
"issue4847.go", // TODO(gri) initialization cycle error not found
|
||||
)
|
||||
|
5
go/types/testdata/init0.src
vendored
5
go/types/testdata/init0.src
vendored
@ -68,12 +68,11 @@ func (T1) m() bool { _ = x11; return false }
|
||||
|
||||
var x11 /* ERROR initialization cycle */ = T1.m(T1{})
|
||||
|
||||
// cycles via method values
|
||||
// no cycles via method values
|
||||
|
||||
type T2 struct{}
|
||||
|
||||
func (T2) m() bool { _ = x12; return false }
|
||||
|
||||
var t1 T2
|
||||
var x12 /* ERROR initialization cycle */ = t1.m
|
||||
|
||||
var x12 = t1.m
|
||||
|
73
go/types/testdata/init1.src
vendored
Normal file
73
go/types/testdata/init1.src
vendored
Normal file
@ -0,0 +1,73 @@
|
||||
// Copyright 2013 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.
|
||||
|
||||
// initialization cycles
|
||||
|
||||
package init1
|
||||
|
||||
// issue 6683 (marked as WorkingAsIntended)
|
||||
|
||||
type T0 struct{}
|
||||
|
||||
func (T0) m() int { return y0 }
|
||||
|
||||
var x0 = T0{}
|
||||
|
||||
var y0 = x0.m() // no cycle reported
|
||||
|
||||
type T1 struct{}
|
||||
|
||||
func (T1) m() int { return y1 }
|
||||
|
||||
var x1 interface {
|
||||
m() int
|
||||
} = T1{}
|
||||
|
||||
var y1 = x1.m() // no cycle reported
|
||||
|
||||
// issue 6703 (modified)
|
||||
|
||||
var x2 /* ERROR initialization cycle */ = T2.m
|
||||
|
||||
var y2 = x2
|
||||
|
||||
type T2 struct{}
|
||||
|
||||
func (T2) m() int {
|
||||
_ = y2
|
||||
return 0
|
||||
}
|
||||
|
||||
var x3 /* ERROR initialization cycle */ = T3.m(T3{}) // <<<< added (T3{})
|
||||
|
||||
var y3 = x3
|
||||
|
||||
type T3 struct{}
|
||||
|
||||
func (T3) m() int {
|
||||
_ = y3
|
||||
return 0
|
||||
}
|
||||
|
||||
var x4 = T4{}.m // <<<< added {}
|
||||
|
||||
var y4 = x4
|
||||
|
||||
type T4 struct{}
|
||||
|
||||
func (T4) m() int {
|
||||
_ = y4
|
||||
return 0
|
||||
}
|
||||
|
||||
var x5 = T5{}.m() // <<<< added ()
|
||||
|
||||
var y5 = x5
|
||||
|
||||
type T5 struct{}
|
||||
|
||||
func (T5) m() int {
|
||||
_ = y5
|
||||
return 0
|
||||
}
|
@ -89,9 +89,6 @@ func (check *checker) ident(x *operand, e *ast.Ident, def *Named, cycleOk bool)
|
||||
case *Var:
|
||||
obj.used = true
|
||||
x.mode = variable
|
||||
// TODO(gri) move this into exprInternal's call of check.ident
|
||||
// since that's the only place where we need to record a dependency
|
||||
// (requires that operands know variable objects)
|
||||
if typ != Typ[Invalid] {
|
||||
check.addDeclDep(obj)
|
||||
}
|
||||
@ -99,7 +96,6 @@ func (check *checker) ident(x *operand, e *ast.Ident, def *Named, cycleOk bool)
|
||||
case *Func:
|
||||
obj.used = true
|
||||
x.mode = value
|
||||
// TODO(gri) see comment above for addDeclDep
|
||||
if typ != Typ[Invalid] {
|
||||
check.addDeclDep(obj)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user