// spec: "An embedded type must be specified as a type name T or as a
// pointer to a non-interface type name *T, and T itself may not be a
// pointer type."
- pos := syntax.StartPos(f.Type)
+ pos := syntax.StartPos(f.Type) // position of type, for errors
name := embeddedFieldIdent(f.Type)
if name == nil {
check.errorf(pos, InvalidSyntaxTree, "invalid embedded field type %s", f.Type)
addInvalid(name, pos)
continue
}
- add(name, true, pos)
+ add(name, true, name.Pos()) // struct{p.T} field has position of T
// Because we have a name, typ must be of the form T or *T, where T is the name
// of a (named or alias) type, and t (= deref(typ)) must be the type of T.
// spec: "An embedded type must be specified as a type name T or as a
// pointer to a non-interface type name *T, and T itself may not be a
// pointer type."
- pos := f.Type.Pos()
+ pos := f.Type.Pos() // position of type, for errors
name := embeddedFieldIdent(f.Type)
if name == nil {
check.errorf(f.Type, InvalidSyntaxTree, "embedded field type %s has no name", f.Type)
addInvalid(name, pos)
continue
}
- add(name, true, pos)
+ add(name, true, name.Pos()) // struct{p.T} field has position of T
// Because we have a name, typ must be of the form T or *T, where T is the name
// of a (named or alias) type, and t (= deref(typ)) must be the type of T.
// unsafe.Pointers are treated like regular pointers when embedded
type T2 struct {
unsafe /* ERROR "cannot be unsafe.Pointer" */ .Pointer
- */* ERROR "cannot be unsafe.Pointer" */ /* ERROR "Pointer redeclared" */ unsafe.Pointer
+ */* ERROR "cannot be unsafe.Pointer" */ unsafe.Pointer /* ERROR "Pointer redeclared" */
UP /* ERROR "cannot be unsafe.Pointer" */
- * /* ERROR "cannot be unsafe.Pointer" */ /* ERROR "UP redeclared" */ UP
+ * /* ERROR "cannot be unsafe.Pointer" */ UP /* ERROR "UP redeclared" */
}
}
List[int]
int8 /* ERROR "int8 redeclared" */
- * /* ERROR "int16 redeclared" */ int16
+ *int16 /* ERROR "int16 redeclared" */
List /* ERROR "List redeclared" */ [int]
}
// func _[T interface{ m(); ~int }]() {
// type L T
// var x L
-//
+//
// // m is not defined on L (it is not "inherited" from
// // its underlying type).
// x.m /* ERROR "x.m undefined" */ ()
-//
+//
// // But the properties of T, such that as that it supports
// // the operations of the types given by its type bound,
// // are also the properties of L.
// x++
// _ = x - x
-//
+//
// // On the other hand, if we define a local alias for T,
// // that alias stands for T as expected.
// type A = T