Improve errors for invalid use of [...]type.
authorIan Lance Taylor <ian@gcc.gnu.org>
Sat, 17 Sep 2011 00:11:27 +0000 (00:11 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Sat, 17 Sep 2011 00:11:27 +0000 (00:11 +0000)
From-SVN: r178921

gcc/go/gofrontend/expressions.cc
gcc/go/gofrontend/parse.cc
gcc/testsuite/go.test/test/ddd1.go

index 32f0612a1b03261f6e4dfc8f6898d9d2fa9b1f85..70f5f7c4423453261d4d3c9713b6676c09081e5d 100644 (file)
@@ -11789,7 +11789,7 @@ Array_construction_expression::do_check_types(Gogo*)
     }
 
   Expression* length = at->length();
-  if (length != NULL)
+  if (length != NULL && !length->is_error_expression())
     {
       mpz_t val;
       mpz_init(val);
index 059d9646f13c7ffb640d3960baa4f1aab25f5365..b18c9892285acdd432aeecee2bbcd22441fdc9b2 100644 (file)
@@ -2761,8 +2761,21 @@ Parse::primary_expr(bool may_be_sink, bool may_be_composite_lit,
          else
            this->advance_token();
          if (expr->is_error_expression())
-           return expr;
-         ret = Expression::make_cast(ret->type(), expr, loc);
+           ret = expr;
+         else
+           {
+             Type* t = ret->type();
+             if (t->classification() == Type::TYPE_ARRAY
+                 && t->array_type()->length() != NULL
+                 && t->array_type()->length()->is_nil_expression())
+               {
+                 error_at(ret->location(),
+                          "invalid use of %<...%> in type conversion");
+                 ret = Expression::make_error(loc);
+               }
+             else
+               ret = Expression::make_cast(t, expr, loc);
+           }
        }
     }
 
index ff6342843a96ce785bb11f89b53452e4a5d3ea12..83e32de7b6bce94830113427344aee4de164659f 100644 (file)
@@ -15,7 +15,7 @@ var (
        _ = sum()
        _ = sum(1.0, 2.0)
        _ = sum(1.5)      // ERROR "integer"
-       _ = sum("hello")  // ERROR "convert|incompatible"
+       _ = sum("hello")  // ERROR "string.*as type int|incompatible"
        _ = sum([]int{1}) // ERROR "slice literal.*as type int|incompatible"
 )
 
@@ -43,4 +43,7 @@ func bad(args ...int) {
        var x int
        _ = unsafe.Pointer(&x...)       // ERROR "[.][.][.]"
        _ = unsafe.Sizeof(x...) // ERROR "[.][.][.]"
+       _ = [...]byte("foo") // ERROR "[.][.][.]"
+       _ = [...][...]int{{1,2,3},{4,5,6}}      // ERROR "[.][.][.]"
 }
+