From 8f94383a99eddb3c7c6b94ffaa3528c0e22c68c2 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Sat, 21 Jan 2012 22:21:22 +0000 Subject: compiler: Check for calling value method with dereferenced value. From-SVN: r183379 --- gcc/go/gofrontend/types.cc | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'gcc') diff --git a/gcc/go/gofrontend/types.cc b/gcc/go/gofrontend/types.cc index 29c3cd7..bb06edb 100644 --- a/gcc/go/gofrontend/types.cc +++ b/gcc/go/gofrontend/types.cc @@ -8605,6 +8605,7 @@ Type::bind_field_or_method(Gogo* gogo, const Type* type, Expression* expr, // If this is a pointer to a pointer, then it is possible that the // pointed-to type has methods. + bool dereferenced = false; if (nt == NULL && st == NULL && it == NULL @@ -8617,6 +8618,7 @@ Type::bind_field_or_method(Gogo* gogo, const Type* type, Expression* expr, return Expression::make_error(location); nt = type->points_to()->named_type(); st = type->points_to()->struct_type(); + dereferenced = true; } bool receiver_can_be_pointer = (expr->type()->points_to() != NULL @@ -8656,6 +8658,12 @@ Type::bind_field_or_method(Gogo* gogo, const Type* type, Expression* expr, else go_unreachable(); go_assert(m != NULL); + if (dereferenced && m->is_value_method()) + { + error_at(location, + "calling value method requires explicit dereference"); + return Expression::make_error(location); + } if (!m->is_value_method() && expr->type()->points_to() == NULL) expr = Expression::make_unary(OPERATOR_AND, expr, location); ret = m->bind_method(expr, location); -- cgit v1.1