Adjust the respective API test accordingly.
Change-Id: I7ecc8899b40ae3b5aeb2c1e032935c672b41e0b6
Reviewed-on: https://go-review.googlesource.com/c/go/+/592675
Reviewed-by: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
// Each /*name=kind:line*/ comment makes the test look up the
// name at that point and checks that it resolves to a decl of
// the specified kind and line number. "undef" means undefined.
+ // Note that type switch case clauses with an empty body (but for
+ // comments) need the ";" to ensure that the recorded scope extends
+ // past the comments.
mainSrc := `
/*lib=pkgname:5*/ /*X=var:1*/ /*Pi=const:8*/ /*T=typename:9*/ /*Y=var:10*/ /*F=func:12*/
package main
var i interface{}
switch y := i.(type) { /*y=undef*/
- case /*y=undef*/ int /*y=var:23*/ :
- case float32, /*y=undef*/ float64 /*y=var:23*/ :
- default /*y=var:23*/:
+ case /*y=undef*/ int /*y=undef*/ : /*y=var:23*/ ;
+ case float32, /*y=undef*/ float64 /*y=undef*/ : /*y=var:23*/ ;
+ default /*y=undef*/ : /*y=var:23*/
println(y)
}
/*y=undef*/
switch int := i.(type) {
- case /*int=typename:0*/ int /*int=var:31*/ :
+ case /*int=typename:0*/ int /*int=typename:0*/ : /*int=var:31*/
println(int)
- default /*int=var:31*/ :
+ default /*int=typename:0*/ : /*int=var:31*/ ;
}
_ = param1
// If lhs exists, declare a corresponding variable in the case-local scope.
if lhs != nil {
obj := NewVar(lhs.Pos(), check.pkg, lhs.Value, T)
- // TODO(mdempsky): Just use clause.Colon? Why did I even suggest
- // "at the end of the TypeSwitchCase" in go.dev/issue/16794 instead?
- scopePos := clause.Pos() // for default clause (len(List) == 0)
- if n := len(cases); n > 0 {
- scopePos = syntax.EndPos(cases[n-1])
- }
- check.declare(check.scope, nil, obj, scopePos)
+ check.declare(check.scope, nil, obj, clause.Colon)
check.recordImplicit(clause, obj)
// For the "declared and not used" error, all lhs variables act as
// one; i.e., if any one of them is 'used', all of them are 'used'.
// Each /*name=kind:line*/ comment makes the test look up the
// name at that point and checks that it resolves to a decl of
// the specified kind and line number. "undef" means undefined.
+ // Note that type switch case clauses with an empty body (but for
+ // comments) need the ";" to ensure that the recorded scope extends
+ // past the comments.
mainSrc := `
/*lib=pkgname:5*/ /*X=var:1*/ /*Pi=const:8*/ /*T=typename:9*/ /*Y=var:10*/ /*F=func:12*/
package main
var i interface{}
switch y := i.(type) { /*y=undef*/
- case /*y=undef*/ int /*y=var:23*/ :
- case float32, /*y=undef*/ float64 /*y=var:23*/ :
- default /*y=var:23*/:
+ case /*y=undef*/ int /*y=undef*/ : /*y=var:23*/ ;
+ case float32, /*y=undef*/ float64 /*y=undef*/ : /*y=var:23*/ ;
+ default /*y=undef*/ : /*y=var:23*/
println(y)
}
/*y=undef*/
switch int := i.(type) {
- case /*int=typename:0*/ int /*int=var:31*/ :
+ case /*int=typename:0*/ int /*int=typename:0*/ : /*int=var:31*/
println(int)
- default /*int=var:31*/ :
+ default /*int=typename:0*/ : /*int=var:31*/ ;
}
_ = param1
// If lhs exists, declare a corresponding variable in the case-local scope.
if lhs != nil {
obj := NewVar(lhs.Pos(), check.pkg, lhs.Name, T)
- // TODO(mdempsky): Just use clause.Colon? Why did I even suggest
- // "at the end of the TypeSwitchCase" in go.dev/issue/16794 instead?
- scopePos := clause.Pos() + token.Pos(len("default")) // for default clause (len(List) == 0)
- if n := len(clause.List); n > 0 {
- scopePos = clause.List[n-1].End()
- }
- check.declare(check.scope, nil, obj, scopePos)
+ check.declare(check.scope, nil, obj, clause.Colon)
check.recordImplicit(clause, obj)
// For the "declared and not used" error, all lhs variables act as
// one; i.e., if any one of them is 'used', all of them are 'used'.