File tree Expand file tree Collapse file tree 4 files changed +10
-10
lines changed
cmd/compile/internal/types2 Expand file tree Collapse file tree 4 files changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -127,15 +127,15 @@ func (check *Checker) structType(styp *Struct, e *syntax.StructType) {
127
127
// spec: "An embedded type must be specified as a type name T or as a
128
128
// pointer to a non-interface type name *T, and T itself may not be a
129
129
// pointer type."
130
- pos := syntax .StartPos (f .Type )
130
+ pos := syntax .StartPos (f .Type ) // position of type, for errors
131
131
name := embeddedFieldIdent (f .Type )
132
132
if name == nil {
133
133
check .errorf (pos , InvalidSyntaxTree , "invalid embedded field type %s" , f .Type )
134
134
name = & syntax.Name {Value : "_" } // TODO(gri) need to set position to pos
135
135
addInvalid (name , pos )
136
136
continue
137
137
}
138
- add (name , true , pos )
138
+ add (name , true , name . Pos ()) // struct{p.T} field has position of T
139
139
140
140
// Because we have a name, typ must be of the form T or *T, where T is the name
141
141
// of a (named or alias) type, and t (= deref(typ)) must be the type of T.
Original file line number Diff line number Diff line change @@ -122,7 +122,7 @@ func (check *Checker) structType(styp *Struct, e *ast.StructType) {
122
122
// spec: "An embedded type must be specified as a type name T or as a
123
123
// pointer to a non-interface type name *T, and T itself may not be a
124
124
// pointer type."
125
- pos := f .Type .Pos ()
125
+ pos := f .Type .Pos () // position of type, for errors
126
126
name := embeddedFieldIdent (f .Type )
127
127
if name == nil {
128
128
check .errorf (f .Type , InvalidSyntaxTree , "embedded field type %s has no name" , f .Type )
@@ -131,7 +131,7 @@ func (check *Checker) structType(styp *Struct, e *ast.StructType) {
131
131
addInvalid (name , pos )
132
132
continue
133
133
}
134
- add (name , true , pos )
134
+ add (name , true , name . Pos ()) // struct{p.T} field has position of T
135
135
136
136
// Because we have a name, typ must be of the form T or *T, where T is the name
137
137
// of a (named or alias) type, and t (= deref(typ)) must be the type of T.
Original file line number Diff line number Diff line change @@ -99,9 +99,9 @@ func _() {
99
99
// unsafe.Pointers are treated like regular pointers when embedded
100
100
type T2 struct {
101
101
unsafe /* ERROR "cannot be unsafe.Pointer" */ .Pointer
102
- * /* ERROR "cannot be unsafe.Pointer" */ /* ERROR "Pointer redeclared" */ unsafe. Pointer
102
+ * /* ERROR "cannot be unsafe.Pointer" */ unsafe. Pointer /* ERROR "Pointer redeclared" */
103
103
UP /* ERROR "cannot be unsafe.Pointer" */
104
- * /* ERROR "cannot be unsafe.Pointer" */ /* ERROR "UP redeclared" */ UP
104
+ * /* ERROR "cannot be unsafe.Pointer" */ UP /* ERROR "UP redeclared" */
105
105
}
106
106
}
107
107
Original file line number Diff line number Diff line change @@ -152,7 +152,7 @@ type _ struct {
152
152
List [int ]
153
153
154
154
int8 /* ERROR "int8 redeclared" */
155
- * /* ERROR "int16 redeclared" */ int16
155
+ * int16 /* ERROR "int16 redeclared" */
156
156
List /* ERROR "List redeclared" */ [int ]
157
157
}
158
158
@@ -166,17 +166,17 @@ type _ struct {
166
166
// func _[T interface{ m(); ~int }]() {
167
167
// type L T
168
168
// var x L
169
- //
169
+ //
170
170
// // m is not defined on L (it is not "inherited" from
171
171
// // its underlying type).
172
172
// x.m /* ERROR "x.m undefined" */ ()
173
- //
173
+ //
174
174
// // But the properties of T, such that as that it supports
175
175
// // the operations of the types given by its type bound,
176
176
// // are also the properties of L.
177
177
// x++
178
178
// _ = x - x
179
- //
179
+ //
180
180
// // On the other hand, if we define a local alias for T,
181
181
// // that alias stands for T as expected.
182
182
// type A = T
You can’t perform that action at this time.
0 commit comments