@@ -429,12 +429,12 @@ func (b *builder) addr(fn *Function, e ast.Expr, escaping bool) lvalue {
429
429
return & address {addr : v , pos : e .Pos (), expr : e }
430
430
431
431
case * ast.CompositeLit :
432
- t , _ := deptr (fn .typeOf (e ))
432
+ typ , _ := deref (fn .typeOf (e ))
433
433
var v * Alloc
434
434
if escaping {
435
- v = emitNew (fn , t , e .Lbrace )
435
+ v = emitNew (fn , typ , e .Lbrace )
436
436
} else {
437
- v = fn .addLocal (t , e .Lbrace )
437
+ v = fn .addLocal (typ , e .Lbrace )
438
438
}
439
439
v .Comment = "complit"
440
440
var sb storebuf
@@ -457,8 +457,7 @@ func (b *builder) addr(fn *Function, e ast.Expr, escaping bool) lvalue {
457
457
wantAddr := true
458
458
v := b .receiver (fn , e .X , wantAddr , escaping , sel )
459
459
index := sel .index [len (sel .index )- 1 ]
460
- dt , _ := deptr (v .Type ())
461
- fld := typeparams .CoreType (dt ).(* types.Struct ).Field (index )
460
+ fld := fieldOf (mustDeref (v .Type ()), index ) // v is an addr.
462
461
463
462
// Due to the two phases of resolving AssignStmt, a panic from x.f = p()
464
463
// when x is nil is required to come after the side-effects of
@@ -553,7 +552,7 @@ func (b *builder) assign(fn *Function, loc lvalue, e ast.Expr, isZero bool, sb *
553
552
// so if the type of the location is a pointer,
554
553
// an &-operation is implied.
555
554
if _ , ok := loc .(blank ); ! ok { // avoid calling blank.typ()
556
- if _ , ok := deptr (loc .typ ()); ok {
555
+ if _ , ok := deref (loc .typ ()); ok {
557
556
ptr := b .addr (fn , e , true ).address (fn )
558
557
// copy address
559
558
if sb != nil {
@@ -583,7 +582,7 @@ func (b *builder) assign(fn *Function, loc lvalue, e ast.Expr, isZero bool, sb *
583
582
584
583
// Subtle: emit debug ref for aggregate types only;
585
584
// slice and map are handled by store ops in compLit.
586
- switch loc .typ (). Underlying ( ).(type ) { // TODO(taking): check if Underlying() appropriate.
585
+ switch typeparams . CoreType ( loc .typ ()).(type ) {
587
586
case * types.Struct , * types.Array :
588
587
emitDebugRef (fn , e , addr , true )
589
588
}
@@ -1253,39 +1252,13 @@ func (b *builder) arrayLen(fn *Function, elts []ast.Expr) int64 {
1253
1252
// literal has type *T behaves like &T{}.
1254
1253
// In that case, addr must hold a T, not a *T.
1255
1254
func (b * builder ) compLit (fn * Function , addr Value , e * ast.CompositeLit , isZero bool , sb * storebuf ) {
1256
- typ , _ := deptr (fn .typeOf (e )) // type with name [may be type param]
1257
- t , _ := deptr (typeparams .CoreType (typ )) // core type for comp lit case
1258
- t = t .Underlying ()
1259
-
1260
- // Computing typ and t is subtle as these handle pointer types.
1261
- // For example, &T{...} is valid even for maps and slices.
1262
- // Also typ should refer to T (not *T) while t should be the core type of T.
1263
- //
1264
- // To show the ordering to take into account, consider the composite literal
1265
- // expressions `&T{f: 1}` and `{f: 1}` within the expression `[]S{{f: 1}}` here:
1266
- // type N struct{f int}
1267
- // func _[T N, S *N]() {
1268
- // _ = &T{f: 1}
1269
- // _ = []S{{f: 1}}
1270
- // }
1271
- // For `&T{f: 1}`, we compute `typ` and `t` as:
1272
- // typeOf(&T{f: 1}) == *T
1273
- // deref(*T) == T (typ)
1274
- // CoreType(T) == N
1275
- // deref(N) == N
1276
- // N.Underlying() == struct{f int} (t)
1277
- // For `{f: 1}` in `[]S{{f: 1}}`, we compute `typ` and `t` as:
1278
- // typeOf({f: 1}) == S
1279
- // deref(S) == S (typ)
1280
- // CoreType(S) == *N
1281
- // deref(*N) == N
1282
- // N.Underlying() == struct{f int} (t)
1283
- switch t := t .(type ) {
1255
+ typ , _ := deref (fn .typeOf (e )) // type with name [may be type param]
1256
+ switch t := typeparams .CoreType (typ ).(type ) {
1284
1257
case * types.Struct :
1285
1258
if ! isZero && len (e .Elts ) != t .NumFields () {
1286
1259
// memclear
1287
- dt , _ := deptr (addr .Type ())
1288
- sb .store (& address {addr , e .Lbrace , nil }, zeroConst (dt ))
1260
+ zt , _ := deref (addr .Type ())
1261
+ sb .store (& address {addr , e .Lbrace , nil }, zeroConst (zt ))
1289
1262
isZero = true
1290
1263
}
1291
1264
for i , e := range e .Elts {
@@ -1329,8 +1302,8 @@ func (b *builder) compLit(fn *Function, addr Value, e *ast.CompositeLit, isZero
1329
1302
1330
1303
if ! isZero && int64 (len (e .Elts )) != at .Len () {
1331
1304
// memclear
1332
- dt , _ := deptr (array .Type ())
1333
- sb .store (& address {array , e .Lbrace , nil }, zeroConst (dt ))
1305
+ zt , _ := deref (array .Type ())
1306
+ sb .store (& address {array , e .Lbrace , nil }, zeroConst (zt ))
1334
1307
}
1335
1308
}
1336
1309
@@ -1385,7 +1358,7 @@ func (b *builder) compLit(fn *Function, addr Value, e *ast.CompositeLit, isZero
1385
1358
// map[*struct{}]bool{&struct{}{}: true}
1386
1359
wantAddr := false
1387
1360
if _ , ok := unparen (e .Key ).(* ast.CompositeLit ); ok {
1388
- _ , wantAddr = t .Key (). Underlying ().( * types. Pointer )
1361
+ _ , wantAddr = deref ( t .Key ())
1389
1362
}
1390
1363
1391
1364
var key Value
@@ -1416,7 +1389,7 @@ func (b *builder) compLit(fn *Function, addr Value, e *ast.CompositeLit, isZero
1416
1389
sb .store (& address {addr : addr , pos : e .Lbrace , expr : e }, m )
1417
1390
1418
1391
default :
1419
- panic ("unexpected CompositeLit type: " + t .String ())
1392
+ panic ("unexpected CompositeLit type: " + typ .String ())
1420
1393
}
1421
1394
}
1422
1395
0 commit comments