From f2d52519e1fad35566afb46ef521934cf0f5e5fd Mon Sep 17 00:00:00 2001 From: griesemer Date: Wed, 25 Oct 2017 11:26:02 -0700 Subject: [PATCH] spec: match syntax for method expressions with implementations A method expression is of the form T.m where T is a type and m is a method of that type. The spec restricted T essentially to a type name. Both cmd/compile and go/types accepted any type syntactically, and a method expression was really just a form of a selector expression x.f where x denotes a type. This CL removes the spec syntax restriction from MethodExpr to match the actual implementation. It also moves MethodExpr from Operand to PrimaryExpr, because that's what it is. It still keeps the separate notion of MethodExpr even though it looks just like a selector expresion, since a MethodExpr must start with a type rather than a value, and the spec's syntax expresses this bit of semantics via distinct productions (e.g., conversions look like calls but also must start with a type). Fixes #9060. Change-Id: Idd84655b5b4f85d7ee53ebf749f73f0414a05f4a Reviewed-on: https://go-review.googlesource.com/73233 Reviewed-by: Matthew Dempsky Reviewed-by: Russ Cox Reviewed-by: Ian Lance Taylor --- doc/go_spec.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index af82931247..ebf1cefffe 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -2278,7 +2278,6 @@ non-blank identifier denoting a constant, variable, or function, -a method expression yielding a function, or a parenthesized expression.

@@ -2288,7 +2287,7 @@ operand only on the left-hand side of an assignment.

-Operand     = Literal | OperandName | MethodExpr | "(" Expression ")" .
+Operand     = Literal | OperandName | "(" Expression ")" .
 Literal     = BasicLit | CompositeLit | FunctionLit .
 BasicLit    = int_lit | float_lit | imaginary_lit | rune_lit | string_lit .
 OperandName = identifier | QualifiedIdent.
@@ -2554,6 +2553,7 @@ Primary expressions are the operands for unary and binary expressions.
 PrimaryExpr =
 	Operand |
 	Conversion |
+	MethodExpr |
 	PrimaryExpr Selector |
 	PrimaryExpr Index |
 	PrimaryExpr Slice |
@@ -2740,7 +2740,7 @@ argument that is the receiver of the method.
 
 
 MethodExpr    = ReceiverType "." MethodName .
-ReceiverType  = TypeName | "(" "*" TypeName ")" | "(" ReceiverType ")" .
+ReceiverType  = Type .
 

-- 2.48.1