From patchwork Wed Sep 25 03:28:18 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 277666 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]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E3CEF2C00C6 for ; Wed, 25 Sep 2013 13:28:30 +1000 (EST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; q=dns; s= default; b=bSV9ZcHGwEFFm0JU+j3eI9Va55EDYD7lsrDAAlL6m3a0e8/3u7B4O /ZA8K7u5dNOqp16KMRR++716jwsoElhDr/1FJH4Xni0PEyNaCZSPYMzUempcgN7D 8DFBHEnnvZhMnDODQiqK/6dp6QlBKVEfH3LkW0uWQKRIZzsKJ8mSEw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type; s= default; bh=7iJNPLVg1GhdWxiXvrJEoZoS5RE=; b=G5B5cqEWSuxKygLIQxnD QrPc1jrz/aOSPgTG2+N7SfCJZiedOxVB5VFVjGxkgBbYNjtTdVxYtkHshhHBY8gw R/8RlP2BXUYWQbhSQzLt4yerOebDw7IqHkHGCtzoacXR47y7MgHp1YUdzjyuHT44 KhBRdLn5t95cUQ72Dx6L/44= Received: (qmail 30205 invoked by alias); 25 Sep 2013 03:28:23 -0000 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 Received: (qmail 30196 invoked by uid 89); 25 Sep 2013 03:28:23 -0000 Received: from mail-pd0-f177.google.com (HELO mail-pd0-f177.google.com) (209.85.192.177) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Wed, 25 Sep 2013 03:28:23 +0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.1 required=5.0 tests=ALL_TRUSTED, AWL, BAYES_00, T_TVD_MIME_NO_HEADERS autolearn=ham version=3.3.2 X-HELO: mail-pd0-f177.google.com Received: by mail-pd0-f177.google.com with SMTP id y10so5472493pdj.22 for ; Tue, 24 Sep 2013 20:28:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:user-agent :mime-version:content-type; bh=/hf0TiNEJgYQQ43en5M4G+n7v2jeB/zS/zyqmpaHtHg=; b=enT2qvd0iplH3ur9pMjGps9aR4TbHbF3sBN2SPNH7chhSfSjR/YyI1cj42lcLqoP6g DXf3dLLFo9134S/8kic8sRD/EEF2P9DE2lgr6Q/OPiueNFC+641+V1XcHttTe/dk7PTu upgjedi/yuwhcBLBqguCbN0yFZYYwOqf0ELB5S1SKNv06ZHhI33225dFnsbUc85Htm99 WaNtQ/fQleZR93p/tw2OVvH5XpIwOTN4CyK1VmjVPMT5eVmZTGKtP9Gr46xDJBI4fivX KkQutfyZPAiUWHrkqqPyPtlwDVzphvmFyOD6npq6Bb7+VivzuR+S1qh2XpAYBrYE+ZJP 7xOw== X-Gm-Message-State: ALoCoQlr9Nx9dCZN1sYkRMx0ewx6DUJg/sT09D116DSZf4RJwI8StJzLh0e41f83vyOynHQs9lVZmUk29hjYW/qth3f3zF8DgxzTG7oiMGSATwy5y2chCPZG/VxbLhpgPanfPJimdcPkZmVrGFmCGHA7Rzmf9eEyo41grQ7Or4SR2fnO2wXqV1h/qjMK5sLJb7A/hZ6nPVAVM6PcjN7JV73YRjnCTBWqDw== X-Received: by 10.68.217.225 with SMTP id pb1mr30603180pbc.61.1380079700961; Tue, 24 Sep 2013 20:28:20 -0700 (PDT) Received: from iant-glaptop.roam.corp.google.com.google.com ([172.19.240.202]) by mx.google.com with ESMTPSA id yh1sm44303168pbc.21.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 24 Sep 2013 20:28:20 -0700 (PDT) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Go patch committed: Don't permit assigning nil to _ Date: Tue, 24 Sep 2013 20:28:18 -0700 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes This patch from Chris Manghane corrects the Go frontend to not permit assigning nil to the sink variable _. Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu. Committed to mainline and 4.8 branch. Ian diff -r 869985e4ef63 go/parse.cc --- a/go/parse.cc Thu Sep 19 10:30:42 2013 -0700 +++ b/go/parse.cc Tue Sep 24 20:17:51 2013 -0700 @@ -1940,12 +1940,9 @@ { if (this->gogo_->in_global_scope()) return this->create_dummy_global(type, init, location); - else if (type == NULL) - this->gogo_->add_statement(Statement::make_statement(init, true)); else { - // With both a type and an initializer, create a dummy - // variable so that we will check whether the + // Create a dummy variable so that we will check whether the // initializer can be assigned to the type. Variable* var = new Variable(type, init, false, false, false, location); diff -r 869985e4ef63 go/statements.cc --- a/go/statements.cc Thu Sep 19 10:30:42 2013 -0700 +++ b/go/statements.cc Tue Sep 24 20:17:51 2013 -0700 @@ -594,6 +594,15 @@ Type* lhs_type = this->lhs_->type(); Type* rhs_type = this->rhs_->type(); + + // Invalid assignment of nil to the blank identifier. + if (lhs_type->is_sink_type() + && rhs_type->is_nil_type()) + { + this->report_error(_("use of untyped nil")); + return; + } + std::string reason; bool ok; if (this->are_hidden_fields_ok_) @@ -975,7 +984,10 @@ if ((*plhs)->is_sink_expression()) { - b->add_statement(Statement::make_statement(*prhs, true)); + if ((*prhs)->type()->is_nil_type()) + this->report_error(_("use of untyped nil")); + else + b->add_statement(Statement::make_statement(*prhs, true)); continue; }