Skip to content

Commit

Permalink
Merge pull request #1494 from xushiwei/typesutil
Browse files Browse the repository at this point in the history
typesutil.Check fix: exprLHS
  • Loading branch information
xushiwei committed Oct 26, 2023
2 parents 15ad484 + 17c4a9a commit f3cc127
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
18 changes: 18 additions & 0 deletions cl/builtin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,24 @@ func TestErrMultiStarRecv(t *testing.T) {
})
}

func TestErrAssign(t *testing.T) {
defer func() {
if e := recover(); e == nil {
t.Fatal("TestErrAssign: no panic?")
}
}()
ctx := &blockCtx{}
compileAssignStmt(ctx, &ast.AssignStmt{
Tok: token.DEFINE,
Lhs: []ast.Expr{
&ast.SelectorExpr{
X: ast.NewIdent("foo"),
Sel: ast.NewIdent("bar"),
},
},
})
}

func TestErrPanicToRecv(t *testing.T) {
ctx := &blockCtx{
tlookup: &typeParamLookup{
Expand Down
4 changes: 4 additions & 0 deletions cl/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,10 @@ func compileSelectorExprLHS(ctx *blockCtx, v *ast.SelectorExpr) {
}
default:
compileExpr(ctx, v.X)
if rec := ctx.recorder(); rec != nil {
e := ctx.cb.Get(-1)
rec.Type(v.X, types.TypeAndValue{Type: e.Type, Value: e.CVal})
}
}
ctx.cb.MemberRef(v.Sel.Name, v)
}
Expand Down
1 change: 1 addition & 0 deletions cl/stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ func compileAssignStmt(ctx *blockCtx, expr *ast.AssignStmt) {
if v, ok := lhs.(*ast.Ident); ok {
names[i] = v.Name
} else {
compileExprLHS(ctx, lhs) // only for typesutil.Check
log.Panicln("TODO: non-name $v on left side of :=")
}
}
Expand Down

0 comments on commit f3cc127

Please sign in to comment.