From patchwork Tue Aug 31 21:47:14 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: 63320 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 00839B7157 for ; Wed, 1 Sep 2010 07:47:30 +1000 (EST) Received: (qmail 13060 invoked by alias); 31 Aug 2010 21:47:26 -0000 Received: (qmail 13048 invoked by uid 22791); 31 Aug 2010 21:47:26 -0000 X-SWARE-Spam-Status: No, hits=-1.3 required=5.0 tests=AWL, BAYES_05, 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) (74.125.121.35) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 31 Aug 2010 21:47:21 +0000 Received: from hpaq14.eem.corp.google.com (hpaq14.eem.corp.google.com [172.25.149.14]) by smtp-out.google.com with ESMTP id o7VLlIsI019280 for ; Tue, 31 Aug 2010 14:47:18 -0700 Received: from iwn42 (iwn42.prod.google.com [10.241.68.106]) by hpaq14.eem.corp.google.com with ESMTP id o7VLkteq027898 for ; Tue, 31 Aug 2010 14:47:17 -0700 Received: by iwn42 with SMTP id 42so8147883iwn.2 for ; Tue, 31 Aug 2010 14:47:17 -0700 (PDT) Received: by 10.231.151.198 with SMTP id d6mr7785270ibw.86.1283291236924; Tue, 31 Aug 2010 14:47:16 -0700 (PDT) Received: from coign.google.com (dhcp-172-22-124-178.mtv.corp.google.com [172.22.124.178]) by mx.google.com with ESMTPS id r3sm9225038ibk.19.2010.08.31.14.47.15 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 31 Aug 2010 14:47:16 -0700 (PDT) From: Ian Lance Taylor To: gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: [gccgo] Avoid duplicate errors with ellipsis types Date: Tue, 31 Aug 2010 14:47:14 -0700 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 This gccgo patch avoids issuing duplicate errors for ellipsis types. If we've already reported one error, we don't need to report another. Committed to gccgo branch. Ian diff -r 165da9b304ae go/expressions.cc --- a/go/expressions.cc Tue Aug 31 14:13:03 2010 -0700 +++ b/go/expressions.cc Tue Aug 31 14:45:13 2010 -0700 @@ -7736,9 +7736,11 @@ // We have reached the varargs parameter. + bool issued_error = false; if (pa != old_args->end() && pa + 1 == old_args->end() - && this->is_compatible_varargs_argument(function, *pa, varargs_type)) + && this->is_compatible_varargs_argument(function, *pa, varargs_type, + &issued_error)) new_args->push_back(*pa); else if (pa == old_args->end()) push_empty_arg = true; @@ -7766,15 +7768,16 @@ if (element_type != NULL) { if (!this->check_argument_type(i, element_type, patype, - paloc)) + paloc, issued_error)) continue; } else { if (patype->is_nil_type()) { - error_at((*pa)->location(), - "invalid use of % for %<...%> argument"); + if (!issued_error) + error_at((*pa)->location(), + "invalid use of % for %<...%> argument"); continue; } if (patype->is_abstract()) @@ -7835,8 +7838,11 @@ bool Call_expression::is_compatible_varargs_argument(Named_object* function, Expression* arg, - Type* param_type) -{ + Type* param_type, + bool* issued_error) +{ + *issued_error = false; + Type* var_type = NULL; // The simple case is passing the varargs parameter of the caller. @@ -7894,6 +7900,7 @@ if (param_type->interface_type() != NULL) return true; error_at(arg->location(), "... mismatch: passing ... as ...T"); + *issued_error = true; return false; } else @@ -7908,6 +7915,7 @@ param_at->element_type(), NULL)) return true; error_at(arg->location(), "... mismatch: passing ...T as ..."); + *issued_error = true; return false; } } @@ -8027,16 +8035,21 @@ bool Call_expression::check_argument_type(int i, const Type* parameter_type, const Type* argument_type, - source_location argument_location) + source_location argument_location, + bool issued_error) { std::string reason; if (!Type::are_assignable(parameter_type, argument_type, &reason)) { - if (reason.empty()) - error_at(argument_location, "argument %d has incompatible type", i); - else - error_at(argument_location, "argument %d has incompatible type (%s)", - i, reason.c_str()); + if (!issued_error) + { + if (reason.empty()) + error_at(argument_location, "argument %d has incompatible type", i); + else + error_at(argument_location, + "argument %d has incompatible type (%s)", + i, reason.c_str()); + } this->set_is_error(); return false; } @@ -8113,7 +8126,7 @@ return; } this->check_argument_type(i + 1, pt->type(), (*pa)->type(), - (*pa)->location()); + (*pa)->location(), false); } if (pt != parameters->end()) this->report_error(_("not enough arguments")); diff -r 165da9b304ae go/expressions.h --- a/go/expressions.h Tue Aug 31 14:13:03 2010 -0700 +++ b/go/expressions.h Tue Aug 31 14:45:13 2010 -0700 @@ -1231,10 +1231,10 @@ lower_varargs(Gogo*, Named_object*); bool - is_compatible_varargs_argument(Named_object*, Expression*, Type*); + is_compatible_varargs_argument(Named_object*, Expression*, Type*, bool*); bool - check_argument_type(int, const Type*, const Type*, source_location); + check_argument_type(int, const Type*, const Type*, source_location, bool); tree bound_method_function(Translate_context*, Bound_method_expression*, tree*);