aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2017-01-25 05:12:26 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2017-01-25 05:12:26 +0000
commit98e20758464f5cbfc60bd61a0cadd66ebb900d96 (patch)
treedc33fcfdbc083da77501abbf15d7d40655c1e3a0 /gcc
parent49d4fa438eab8a98541846b0213f5d23752ba2b4 (diff)
downloadgcc-98e20758464f5cbfc60bd61a0cadd66ebb900d96.zip
gcc-98e20758464f5cbfc60bd61a0cadd66ebb900d96.tar.gz
gcc-98e20758464f5cbfc60bd61a0cadd66ebb900d96.tar.bz2
compiler: improvements for type alias handling
Give an error for an attempt to define a method on an imported type. Give an error for each attempt to define a method on a builtin type. Adjust error messages to be closer to gc error messages. With these changes gccgo passes current tests on dev.typealias branch. This changes the errors printed for test/fixedbugs/issue5089.go, but the change is an improvement: Before: fixedbugs/issue5089.go:13:1: error: redefinition of ‘bufio.Buffered’: receiver name changed func (b *bufio.Reader) Buffered() int { // ERROR "non-local|redefinition" ^ fixedbugs/issue5089.go:11:13: note: previous definition of ‘bufio.Buffered’ was here import "bufio" // GCCGO_ERROR "previous" ^ Now: fixedbugs/issue5089.go:13:7: error: may not define methods on non-local type func (b *bufio.Reader) Buffered() int { // ERROR "non-local|redefinition" ^ Reviewed-on: https://go-review.googlesource.com/35642 From-SVN: r244889
Diffstat (limited to 'gcc')
-rw-r--r--gcc/go/gofrontend/MERGE2
-rw-r--r--gcc/go/gofrontend/gogo.cc27
-rw-r--r--gcc/testsuite/go.test/test/fixedbugs/issue5089.go4
3 files changed, 24 insertions, 9 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index f29acdf..582a86b 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-fb609ff6d940768cf4db4ab7deb93b2ab686e45d
+5c6c93f58e2aaae186bac5dcde9df1679d4896b1
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/gogo.cc b/gcc/go/gofrontend/gogo.cc
index ad2541c..c5ce5d9 100644
--- a/gcc/go/gofrontend/gogo.cc
+++ b/gcc/go/gofrontend/gogo.cc
@@ -1779,18 +1779,27 @@ Gogo::start_function(const std::string& name, Function_type* type,
while (rtype->named_type() != NULL
&& rtype->named_type()->is_alias())
- rtype = rtype->named_type()->real_type();
+ rtype = rtype->named_type()->real_type()->forwarded();
if (rtype->is_error_type())
ret = Named_object::make_function(name, NULL, function);
else if (rtype->named_type() != NULL)
{
- ret = rtype->named_type()->add_method(name, function);
- if (!ret->is_function())
+ if (rtype->named_type()->named_object()->package() != NULL)
{
- // Redefinition error.
+ go_error_at(type->receiver()->location(),
+ "may not define methods on non-local type");
ret = Named_object::make_function(name, NULL, function);
}
+ else
+ {
+ ret = rtype->named_type()->add_method(name, function);
+ if (!ret->is_function())
+ {
+ // Redefinition error.
+ ret = Named_object::make_function(name, NULL, function);
+ }
+ }
}
else if (rtype->forward_declaration_type() != NULL)
{
@@ -2247,8 +2256,14 @@ Gogo::define_global_names()
if (global_no->is_type())
{
if (no->type_declaration_value()->has_methods())
- go_error_at(no->location(),
- "may not define methods for global type");
+ {
+ for (std::vector<Named_object*>::const_iterator p =
+ no->type_declaration_value()->methods()->begin();
+ p != no->type_declaration_value()->methods()->end();
+ p++)
+ go_error_at((*p)->location(),
+ "may not define methods on non-local type");
+ }
no->set_type_value(global_no->type_value());
}
else
diff --git a/gcc/testsuite/go.test/test/fixedbugs/issue5089.go b/gcc/testsuite/go.test/test/fixedbugs/issue5089.go
index 81b9f05..dc393e9 100644
--- a/gcc/testsuite/go.test/test/fixedbugs/issue5089.go
+++ b/gcc/testsuite/go.test/test/fixedbugs/issue5089.go
@@ -1,6 +1,6 @@
// errorcheck
-// Copyright 2013 The Go Authors. All rights reserved.
+// Copyright 2013 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
@@ -8,7 +8,7 @@
package p
-import "bufio" // GCCGO_ERROR "previous"
+import "bufio"
func (b *bufio.Reader) Buffered() int { // ERROR "non-local|redefinition"
return -1