Skip to content

Commit 0db4da5

Browse files
committed
[dev.go2go] go/types: don't crash in assignment due to prior errors
Addresses crash #12 of 39634. Updates #39634. Change-Id: Ie67545d21b6a1e80fcdec1b2eb101b69c25e2952 Reviewed-on: https://go-review.googlesource.com/c/go/+/245738 Reviewed-by: Robert Griesemer <[email protected]>
1 parent d118bf7 commit 0db4da5

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/go/types/assignments.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ func (check *Checker) assignment(x *operand, T Type, context string) {
2525
case constant_, variable, mapindex, value, commaok, commaerr:
2626
// ok
2727
default:
28-
unreachable()
28+
// we may get here because of other problems (issue #39634, crash 12)
29+
check.errorf(x.pos(), "cannot assign %s to %s in %s", x, T, context)
30+
return
2931
}
3032

3133
if isUntyped(x.typ) {

src/go/types/fixedbugs/issue39634.go2

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ type foo8(type A) interface { type A }
3030
func bar8(type A foo8(A))(a A) {}
3131
func main8() {}
3232

33+
// crash 12
34+
var u /* ERROR cycle */ , i [func /* ERROR used as value */ /* ERROR used as value */ (u, c /* ERROR undeclared */ /* ERROR undeclared */ ) {}(0, len)]c /* ERROR undeclared */ /* ERROR undeclared */
35+
3336
// crash 15
3437
func y15() { var a /* ERROR declared but not used */ interface{ p() } = G15(string){} }
3538
type G15(type X) s /* ERROR undeclared name */

0 commit comments

Comments
 (0)