Skip to content

Commit 2ee9577

Browse files
mdempskyjproberts
authored andcommitted
cmd/compile: support structural typing in unified IR
This CL updates unified IR to look at the structural type of a composite literal type, rather than merely the underlying type, to determine if it's a structure. This fixes a number of currently failing regress test cases. Updates #50833. Change-Id: I11c040c77ec86c23e8ffefcf1ce1aed548687dc5 Reviewed-on: https://go-review.googlesource.com/c/go/+/381074 Run-TryBot: Matthew Dempsky <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Trust: Matthew Dempsky <[email protected]> Reviewed-by: Robert Griesemer <[email protected]>
1 parent 9a428a1 commit 2ee9577

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

src/cmd/compile/internal/noder/writer.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1218,6 +1218,7 @@ func (w *writer) expr(expr syntax.Expr) {
12181218
}
12191219

12201220
obj := obj.(*types2.Var)
1221+
assert(!obj.IsField())
12211222
assert(targs.Len() == 0)
12221223

12231224
w.code(exprLocal)
@@ -1337,10 +1338,11 @@ func (w *writer) compLit(lit *syntax.CompositeLit) {
13371338
w.typ(tv.Type)
13381339

13391340
typ := tv.Type
1341+
// TODO(mdempsky): Use types2.StructuralType here too? See #50833.
13401342
if ptr, ok := typ.Underlying().(*types2.Pointer); ok {
13411343
typ = ptr.Elem()
13421344
}
1343-
str, isStruct := typ.Underlying().(*types2.Struct)
1345+
str, isStruct := types2.StructuralType(typ).(*types2.Struct)
13441346

13451347
w.len(len(lit.ElemList))
13461348
for i, elem := range lit.ElemList {

test/run.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2167,7 +2167,6 @@ var unifiedFailures = setOf(
21672167

21682168
"fixedbugs/issue42284.go", // prints "T(0) does not escape", but test expects "a.I(a.T(0)) does not escape"
21692169
"fixedbugs/issue7921.go", // prints "… escapes to heap", but test expects "string(…) escapes to heap"
2170-
"typeparam/issue48538.go", // assertion failure, interprets struct key as closure variable
21712170
"typeparam/issue47631.go", // unified IR can handle local type declarations
21722171
"fixedbugs/issue42058a.go", // unified IR doesn't report channel element too large
21732172
"fixedbugs/issue42058b.go", // unified IR doesn't report channel element too large
@@ -2178,10 +2177,7 @@ var unifiedFailures = setOf(
21782177
"typeparam/typeswitch2.go", // duplicate case failure due to stenciling
21792178
"typeparam/typeswitch3.go", // duplicate case failure due to stenciling
21802179
"typeparam/typeswitch4.go", // duplicate case failure due to stenciling
2181-
"typeparam/issue50417b.go", // Need to handle field access on a type param
21822180
"typeparam/issue50552.go", // gives missing method for instantiated type
2183-
"typeparam/absdiff2.go", // wrong assertion about closure variables
2184-
"typeparam/absdiffimp2.go", // wrong assertion about closure variables
21852181
)
21862182

21872183
func setOf(keys ...string) map[string]bool {

0 commit comments

Comments
 (0)