diff options
| author | Robert Griesemer <gri@golang.org> | 2020-02-26 13:17:55 -0800 |
|---|---|---|
| committer | Robert Griesemer <gri@golang.org> | 2020-02-27 19:37:52 +0000 |
| commit | 020fa4deaa55c98b8271c9558766315a1ab9d73a (patch) | |
| tree | 85cef33fa90f02c7308101f733d926648d669870 | |
| parent | d74d825331d9b16ee286ea77c0e4caeaf0efbe30 (diff) | |
| download | go-x-proposal-020fa4deaa55c98b8271c9558766315a1ab9d73a.tar.xz | |
design/go2draft-contracts.md: document struct embedding parsing ambiguity
Change-Id: Iae16bc6735a7e59e7ff06b12ffbd2d137f4d1598
Reviewed-on: https://go-review.googlesource.com/c/proposal/+/221257
Reviewed-by: Ian Lance Taylor <iant@golang.org>
| -rw-r--r-- | design/go2draft-contracts.md | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/design/go2draft-contracts.md b/design/go2draft-contracts.md index 7c43f65..d4dbb0e 100644 --- a/design/go2draft-contracts.md +++ b/design/go2draft-contracts.md @@ -984,7 +984,42 @@ var f1 func(_ x(T)) var f2 func((x(T))) ``` -### Embedding a parameterized interface type +### Embedding a parameterized type in a struct + +There is a parsing ambiguity when embedding a parameterized type +in a struct type. + +```Go +type S1(type T) struct { + f T +} + +type S2 struct { + S1(int) +} +``` + +In this example we don't know whether struct `S2` has a single +field named `S1` of type `(int)`, or whether we +are trying to embed the instantiated type `S1(int)` into `S2`. + +For backward compatibility, we treat this as the former case: `S2` has +a field named `S1`. + +In order to embed an instantiated type in a struct, we could require that +extra parentheses be used. + +```Go +type S2 struct { + (S1(int)) +} +``` + +This is currently not supported by the language, so this would suggest +generally extending the language to permit types embedded in structs to +be parenthesized. + +### Embedding a parameterized interface type in an interface There is a parsing ambiguity when embedding a parameterized interface type in another interface type. |
