File tree 2 files changed +11
-1
lines changed
2 files changed +11
-1
lines changed Original file line number Diff line number Diff line change @@ -84,3 +84,8 @@ type foo struct{} // used
84
84
type Bar * Node [foo ] // used
85
85
86
86
func (n Node [T ]) anyMethod () {} // unused
87
+
88
+ func fn11 [T ~ struct { Field int }]() { // unused
89
+ // don't crash because of the composite literal
90
+ _ = T {Field : 42 }
91
+ }
Original file line number Diff line number Diff line change @@ -1630,12 +1630,17 @@ func (g *graph) instructions(fn *ir.Function) {
1630
1630
}
1631
1631
switch instr := instr .(type ) {
1632
1632
case * ir.Field :
1633
+ // Can't access fields via generics, for now.
1634
+
1633
1635
st := instr .X .Type ().Underlying ().(* types.Struct )
1634
1636
field := st .Field (instr .Field )
1635
1637
// (4.7) functions use fields they access
1636
1638
g .seeAndUse (field , fnObj , edgeFieldAccess )
1637
1639
case * ir.FieldAddr :
1638
- st := typeutil .Dereference (instr .X .Type ()).Underlying ().(* types.Struct )
1640
+ // User code can't access fields on type parameters, but composite literals are still possible, which
1641
+ // compile to FieldAddr + Store.
1642
+
1643
+ st := typeutil .CoreType (typeutil .Dereference (instr .X .Type ())).(* types.Struct )
1639
1644
field := st .Field (instr .Field )
1640
1645
// (4.7) functions use fields they access
1641
1646
g .seeAndUse (field , fnObj , edgeFieldAccess )
You can’t perform that action at this time.
0 commit comments