Skip to content

Commit 9a8bf2d

Browse files
JayNakranimdempsky
authored andcommitted
cmd/compile: avoid nil-ing out a node's Type in typecheckcomplit() on error
typecheckcomplit nils out node's type, upon finding new errors. This hides new errors in children's node as well as the type info of current node. This change fixes that. Fixes #17645. Change-Id: Ib473291f31c7e8fa0307cb1d494e0c112ddd3583 Reviewed-on: https://go-review.googlesource.com/32324 Reviewed-by: Matthew Dempsky <[email protected]> Run-TryBot: Matthew Dempsky <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent d35dfd4 commit 9a8bf2d

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/cmd/compile/internal/gc/typecheck.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3113,7 +3113,6 @@ func typecheckcomplit(n *Node) *Node {
31133113
}
31143114

31153115
if nerr != nerrors {
3116-
n.Type = nil
31173116
return n
31183117
}
31193118

test/fixedbugs/issue17645.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// errorcheck
2+
3+
// Copyright 2016 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
package main
8+
9+
type Foo struct {
10+
X int
11+
}
12+
13+
func main() {
14+
var s []int
15+
var _ string = append(s, Foo{""}) // ERROR "cannot use .. \(type string\) as type int in field value" "cannot use Foo literal \(type Foo\) as type int in append" "cannot use append\(s\, Foo literal\) \(type \[\]int\) as type string in assignment"
16+
}
17+

0 commit comments

Comments
 (0)