From patchwork Sat Nov 28 14:57:14 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 1407536 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=ANgj8nGO; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Cjvjp6kfNz9s1l for ; Sun, 29 Nov 2020 01:57:34 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EA209385480E; Sat, 28 Nov 2020 14:57:30 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EA209385480E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1606575451; bh=qBB1G925HsB2tfChFGbiH6h9KWQ8bKu0iCFSU47jLpE=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ANgj8nGOOwHe+rcj31i1NcjJYv+pIJbGU7YAokdIqZJIbbuFp2sRng6EM3MUj/9kw XxHk98qxLgEslmMzNVzG7cnwWmED4bMLQ8LugVvn+OMe0tbbTzS5tPsrRurlaYq83J QMY5u/4oxdkhs2jtoKIb36JITMrIPoAntxn44+t8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by sourceware.org (Postfix) with ESMTPS id ECFCD3858C27 for ; Sat, 28 Nov 2020 14:57:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org ECFCD3858C27 Received: by mail-ej1-x633.google.com with SMTP id o9so11804056ejg.1 for ; Sat, 28 Nov 2020 06:57:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=qBB1G925HsB2tfChFGbiH6h9KWQ8bKu0iCFSU47jLpE=; b=WpoCudvfv6YnwsWl8dis12+kXz8N9yszLXHZh3SwvjN7tLmv8hrOBI2nnmNczzNLoz O3WjO2ie28oHm78q9lZ5O0mhaavK00OzMmB2H+/TTWo5ksigyU3eTMNT1NPgRYDGXBTs xPoNJXheovOZGMLb5E/2Ns0ZQScODMOljdQinsJeWgc0HBz9WIPnX99ddtZaQvSRco5t 4/7KhUMtX+w3R0zh6zxwCCRjHrCZ24TwoMe3ZdfX6C533BoGTEgSDeXNkLlUSxKTcdRw LTDlOht2YtPtqnUX2/iG5hcLMuRSTXm/KLmeq1t1CRzzek+jvgIeoYNFS+H9akt++8Sn fnjw== X-Gm-Message-State: AOAM5324p44VO94Xac6/EOog1uLoScs85hvSiivh4DG/MsJkOEb4c52y jVne7R/Wfv1foqncX5UKKJMbBxs+GUnP4YQJkoLBy8bJ/Q6z2Q== X-Google-Smtp-Source: ABdhPJxu8NAO8OvjrvQPKe3Osd31ylq2ZrtpAtI7lldUewYZfBXCIdOFbIteq1hL4hWqvFpW2NTOX59uaPY8/+WROtM= X-Received: by 2002:a17:906:3608:: with SMTP id q8mr12920310ejb.39.1606575445790; Sat, 28 Nov 2020 06:57:25 -0800 (PST) MIME-Version: 1.0 Date: Sat, 28 Nov 2020 06:57:14 -0800 Message-ID: Subject: Go patch committed: Better error for x, x := 1, 2 To: gcc-patches , gofrontend-dev X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ian Lance Taylor via Gcc-patches From: Ian Lance Taylor Reply-To: Ian Lance Taylor Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This patch to the Go frontend gives a better error message when the same variable is declared multiple times on the left hand side of a := statement. Was assign.go:59:28: error: multiple assignments to x Now assign.go:59:28: error: ‘x’ repeated on left side of := Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline. Ian 3e1ee797694007edb621061b1034262297fe767d diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index c14ee7e7b14..59648326fcc 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -8cbe18aff99dbf79bd1adb9c025418e84505ffd5 +66669bb6cae475eda6666a94f6ff4f616ffa77d7 The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/gcc/go/gofrontend/parse.cc b/gcc/go/gofrontend/parse.cc index ef5941522cf..aa157e86cb2 100644 --- a/gcc/go/gofrontend/parse.cc +++ b/gcc/go/gofrontend/parse.cc @@ -2165,8 +2165,12 @@ Parse::simple_var_decl_or_assignment(const std::string& name, id = this->gogo_->pack_hidden_name(id, is_id_exported); ins = uniq_idents.insert(id); if (!ins.second && !Gogo::is_sink_name(id)) - go_error_at(id_location, "multiple assignments to %s", - Gogo::message_name(id).c_str()); + { + // Use %s to print := to avoid -Wformat-diag warning. + go_error_at(id_location, + "%qs repeated on left side of %s", + Gogo::message_name(id).c_str(), ":="); + } til.push_back(Typed_identifier(id, NULL, location)); } else @@ -2219,7 +2223,11 @@ Parse::simple_var_decl_or_assignment(const std::string& name, const Token* token = this->advance_token(); if (!dup_name.empty()) - go_error_at(dup_loc, "multiple assignments to %s", dup_name.c_str()); + { + // Use %s to print := to avoid -Wformat-diag warning. + go_error_at(dup_loc, "%qs repeated on left side of %s", + dup_name.c_str(), ":="); + } if (p_range_clause != NULL && token->is_keyword(KEYWORD_RANGE)) {