compiler: Type check params in sink function decl.
authorIan Lance Taylor <ian@gcc.gnu.org>
Tue, 25 Aug 2015 03:48:35 +0000 (03:48 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Tue, 25 Aug 2015 03:48:35 +0000 (03:48 +0000)
    When a function is declared and named with the blank identifier, only
    the syntax is checked.  This patch modifies the parser to add a dummy
    node for each function declaration with a blank identifier name that
    will be type checked like any function declaration.

    Fixes golang/go#11535.

    Reviewed-on: https://go-review.googlesource.com/13792

From-SVN: r227160

gcc/go/gofrontend/MERGE
gcc/go/gofrontend/parse.cc

index 853cb4acc0051083a33ac0881ed330e1f5f58e52..e499d7f3c01109861f974a4d98a2cfe6c68e9a51 100644 (file)
@@ -1,4 +1,4 @@
-cc7303c97b232ea979cab950d95aaf76c4e0f5b5
+81810917af7ba19e1f9f8efc8b1989f7d6419d30
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
index 211fd73b3c59c3de5fcf7c5c0633aa089dec9aff..922473ac810358b45442be07c6632e13489c0477 100644 (file)
@@ -2305,8 +2305,20 @@ Parse::function_decl(bool saw_nointerface)
 
   if (!this->peek_token()->is_op(OPERATOR_LCURLY))
     {
-      if (named_object == NULL && !Gogo::is_sink_name(name))
+      if (named_object == NULL)
        {
+          // Function declarations with the blank identifier as a name are
+          // mostly ignored since they cannot be called.  We make an object
+          // for this declaration for type-checking purposes.
+          if (Gogo::is_sink_name(name))
+            {
+              static int count;
+              char buf[30];
+              snprintf(buf, sizeof buf, ".$sinkfndecl%d", count);
+              ++count;
+              name = std::string(buf);
+            }
+
          if (fntype == NULL
               || (expected_receiver && rec == NULL))
            this->gogo_->add_erroneous_name(name);