Skip to content

Commit 020fa4d

Browse files
committed
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 <[email protected]>
1 parent d74d825 commit 020fa4d

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

design/go2draft-contracts.md

+36-1
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,42 @@ var f1 func(_ x(T))
984984
var f2 func((x(T)))
985985
```
986986

987-
### Embedding a parameterized interface type
987+
### Embedding a parameterized type in a struct
988+
989+
There is a parsing ambiguity when embedding a parameterized type
990+
in a struct type.
991+
992+
```Go
993+
type S1(type T) struct {
994+
f T
995+
}
996+
997+
type S2 struct {
998+
S1(int)
999+
}
1000+
```
1001+
1002+
In this example we don't know whether struct `S2` has a single
1003+
field named `S1` of type `(int)`, or whether we
1004+
are trying to embed the instantiated type `S1(int)` into `S2`.
1005+
1006+
For backward compatibility, we treat this as the former case: `S2` has
1007+
a field named `S1`.
1008+
1009+
In order to embed an instantiated type in a struct, we could require that
1010+
extra parentheses be used.
1011+
1012+
```Go
1013+
type S2 struct {
1014+
(S1(int))
1015+
}
1016+
```
1017+
1018+
This is currently not supported by the language, so this would suggest
1019+
generally extending the language to permit types embedded in structs to
1020+
be parenthesized.
1021+
1022+
### Embedding a parameterized interface type in an interface
9881023

9891024
There is a parsing ambiguity when embedding a parameterized interface
9901025
type in another interface type.

0 commit comments

Comments
 (0)