mirror of https://github.com/golang/go.git
cmd/compile: fix error message for &T{} literal mismatch
See the change and comment in typecheck.go for a detailed explanation. Fixes #26855. Change-Id: I7867f948490fc0873b1bd849048cda6acbc36e76 Reviewed-on: https://go-review.googlesource.com/136395 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
9c2e5f2971
commit
ae37f5a397
|
|
@ -2923,6 +2923,14 @@ func typecheckcomplit(n *Node) *Node {
|
||||||
|
|
||||||
// Save original node (including n.Right)
|
// Save original node (including n.Right)
|
||||||
norig := n.copy()
|
norig := n.copy()
|
||||||
|
// If n.Orig points to itself, norig.Orig must point to itself, too.
|
||||||
|
// Otherwise, because n.Op is changed below, n.Orig's Op is changed
|
||||||
|
// as well because it (and the copy norig) still point to the original
|
||||||
|
// node n. This caused the wrong complit Op to be used when printing
|
||||||
|
// error messages (issue #26855).
|
||||||
|
if n.Orig == n {
|
||||||
|
norig.Orig = norig
|
||||||
|
}
|
||||||
|
|
||||||
setlineno(n.Right)
|
setlineno(n.Right)
|
||||||
n.Right = typecheck(n.Right, Etype|Ecomplit)
|
n.Right = typecheck(n.Right, Etype|Ecomplit)
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,28 @@
|
||||||
|
// errorcheck
|
||||||
|
|
||||||
|
// Copyright 2012 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 get the correct (T vs &T) literal specification
|
||||||
|
// in the error message.
|
||||||
|
|
||||||
|
package p
|
||||||
|
|
||||||
|
type S struct {
|
||||||
|
f T
|
||||||
|
}
|
||||||
|
|
||||||
|
type P struct {
|
||||||
|
f *T
|
||||||
|
}
|
||||||
|
|
||||||
|
type T struct{}
|
||||||
|
|
||||||
|
var _ = S{
|
||||||
|
f: &T{}, // ERROR "cannot use &T literal"
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ = P{
|
||||||
|
f: T{}, // ERROR "cannot use T literal"
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue