]> Cypherpunks repositories - gostls13.git/commitdiff
reject new of function type
authorRuss Cox <rsc@golang.org>
Wed, 22 Oct 2008 01:03:25 +0000 (18:03 -0700)
committerRuss Cox <rsc@golang.org>
Wed, 22 Oct 2008 01:03:25 +0000 (18:03 -0700)
R=ken
OCL=17598
CL=17598

src/cmd/gc/walk.c
test/newfn.go [new file with mode: 0644]

index f63b2933441f1deeb64a57719fe57e823b4a3969..c78ac1ab7b299847279dbbb389aeafeda9855956 100644 (file)
@@ -1824,6 +1824,10 @@ newcompat(Node *n)
 
        t = t->type;
        switch(t->etype) {
+       case TFUNC:
+               yyerror("cannot make new %T", t);
+               break;
+
        case TMAP:
                r = mapop(n, Erv);
                return r;
diff --git a/test/newfn.go b/test/newfn.go
new file mode 100644 (file)
index 0000000..8aacd84
--- /dev/null
@@ -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
+}