From 56b983c112ddca28cf29e4d1b0ab9f590ea69976 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Mon, 3 Mar 2014 19:55:40 -0500 Subject: [PATCH] cmd/gc: fix internal crash TBR=ken2 CC=golang-codereviews https://golang.org/cl/70200053 --- src/cmd/gc/typecheck.c | 2 ++ test/fixedbugs/issue7310.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 test/fixedbugs/issue7310.go diff --git a/src/cmd/gc/typecheck.c b/src/cmd/gc/typecheck.c index 05efab4040..21021def95 100644 --- a/src/cmd/gc/typecheck.c +++ b/src/cmd/gc/typecheck.c @@ -1358,6 +1358,8 @@ reswitch: goto error; defaultlit(&n->left, T); defaultlit(&n->right, T); + if(n->left->type == T || n->right->type == T) + goto error; // copy([]byte, string) if(isslice(n->left->type) && n->right->type->etype == TSTRING) { diff --git a/test/fixedbugs/issue7310.go b/test/fixedbugs/issue7310.go new file mode 100644 index 0000000000..4a535a1fcc --- /dev/null +++ b/test/fixedbugs/issue7310.go @@ -0,0 +1,15 @@ +// errorcheck + +// Copyright 2014 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. + +// Internal compiler crash used to stop errors during second copy. + +package main + +func main() { + _ = copy(nil, []int{}) // ERROR "use of untyped nil" + _ = copy([]int{}, nil) // ERROR "use of untyped nil" + _ = 1+true // ERROR "cannot convert true" "mismatched types int and bool" +} -- 2.48.1