Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typesutil.Check fix: exprLHS #1494

Merged
merged 3 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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