reject new of function type

R=ken
OCL=17598
CL=17598
This commit is contained in:
Russ Cox 2008-10-21 18:03:25 -07:00
parent f0e93e8cc5
commit dbabeb1d7a
2 changed files with 18 additions and 0 deletions

View File

@ -1824,6 +1824,10 @@ newcompat(Node *n)
t = t->type; t = t->type;
switch(t->etype) { switch(t->etype) {
case TFUNC:
yyerror("cannot make new %T", t);
break;
case TMAP: case TMAP:
r = mapop(n, Erv); r = mapop(n, Erv);
return r; return r;

14
test/newfn.go Normal file
View File

@ -0,0 +1,14 @@
// Copyright 2009 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.
// errchk $G $D/$F.go
package main
func main()
{
f := new(()); // ERROR "new"
g := new((x int, f float) string); // ERROR "new"
h := new(*()); // ok
}