* Go patch committed: Better errors for invalid [...]type
@ 2011-09-17 7:18 Ian Lance Taylor
0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2011-09-17 7:18 UTC (permalink / raw)
To: gcc-patches, gofrontend-dev
[-- Attachment #1: Type: text/plain, Size: 229 bytes --]
This patch to the Go frontend improves the error handling for invalid
use of [...]type, which may be only used with a composite literal.
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.
Ian
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch --]
[-- Type: text/x-diff, Size: 2061 bytes --]
Index: gcc/go/gofrontend/parse.cc
===================================================================
--- gcc/go/gofrontend/parse.cc (revision 178784)
+++ gcc/go/gofrontend/parse.cc (working copy)
@@ -2761,8 +2761,21 @@ Parse::primary_expr(bool may_be_sink, bo
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: gcc/go/gofrontend/expressions.cc
===================================================================
--- gcc/go/gofrontend/expressions.cc (revision 178870)
+++ gcc/go/gofrontend/expressions.cc (working copy)
@@ -11789,7 +11789,7 @@ Array_construction_expression::do_check_
}
Expression* length = at->length();
- if (length != NULL)
+ if (length != NULL && !length->is_error_expression())
{
mpz_t val;
mpz_init(val);
Index: gcc/testsuite/go.test/test/ddd1.go
===================================================================
--- gcc/testsuite/go.test/test/ddd1.go (revision 178784)
+++ gcc/testsuite/go.test/test/ddd1.go (working copy)
@@ -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 "[.][.][.]"
}
+
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2011-09-17 0:12 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-09-17 7:18 Go patch committed: Better errors for invalid [...]type Ian Lance Taylor
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).