From patchwork Wed Nov 10 22:57:29 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 70714 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 82A38B712B for ; Thu, 11 Nov 2010 09:57:45 +1100 (EST) Received: (qmail 27719 invoked by alias); 10 Nov 2010 22:57:41 -0000 Received: (qmail 27710 invoked by uid 22791); 10 Nov 2010 22:57:40 -0000 X-SWARE-Spam-Status: No, hits=-2.2 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_PASS, TW_CC, T_RP_MATCHES_RCVD, T_TVD_MIME_NO_HEADERS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 10 Nov 2010 22:57:35 +0000 Received: from kpbe14.cbf.corp.google.com (kpbe14.cbf.corp.google.com [172.25.105.78]) by smtp-out.google.com with ESMTP id oAAMvXHm013726 for ; Wed, 10 Nov 2010 14:57:33 -0800 Received: from pxi20 (pxi20.prod.google.com [10.243.27.20]) by kpbe14.cbf.corp.google.com with ESMTP id oAAMvVFb000314 for ; Wed, 10 Nov 2010 14:57:32 -0800 Received: by pxi20 with SMTP id 20so403284pxi.24 for ; Wed, 10 Nov 2010 14:57:31 -0800 (PST) Received: by 10.142.164.19 with SMTP id m19mr7219891wfe.425.1289429851783; Wed, 10 Nov 2010 14:57:31 -0800 (PST) Received: from coign.google.com (dhcp-172-22-127-239.mtv.corp.google.com [172.22.127.239]) by mx.google.com with ESMTPS id q13sm1439567wfc.17.2010.11.10.14.57.30 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 10 Nov 2010 14:57:31 -0800 (PST) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: [gccgo] Permit omitting type in composite literal with key Date: Wed, 10 Nov 2010 14:57:29 -0800 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Go recently changed to permit omitting the type in a composite literal, and I fixed gccgo to support that. However, I missed the case where the composite literal uses a key, as in type S struct { i int } var M = map[int]S{ 0 : { 0 }, 1 : { 1 }} Previously this had to be var M = map[int]S{ 0 : S{ 0 }, 1 : S{ 1 }} This patch permits omitting the type when using a key. Committed to gccgo branch. Ian diff -r 4cabf36880e8 go/parse.cc --- a/go/parse.cc Wed Nov 10 14:43:00 2010 -0800 +++ b/go/parse.cc Wed Nov 10 14:54:23 2010 -0800 @@ -2395,7 +2395,15 @@ vals->push_back(val); - val = this->expression(PRECEDENCE_NORMAL, false, true, NULL); + if (!token->is_op(OPERATOR_LCURLY)) + val = this->expression(PRECEDENCE_NORMAL, false, true, NULL); + else + { + // This must be a composite literal inside another + // composite literal, with the type omitted for the + // inner one. + val = this->composite_lit(type, depth + 1, token->location()); + } token = this->peek_token(); }