Repository: goplus/xgo

Issue:
expr? compile error
### The following program `sample.gop` triggers an unexpected result

```coffee
func F() (a int8, b int16, err error) {
	a = 1
	return
}

func F2() (err error) {
	c, d := F()?
	_ = c
	_ = d
	return
}

F2()
println "ok"
```

### Expected result

```console
ok
```

### Got

```console
prog.xgo:7:2: assignment mismatch: 2 variables but 1 values
prog.xgo:8:6: undefined: c
prog.xgo:9:6: undefined: d
```

### XGo Version

The XGo Playground

### Additional Notes

_No response_

Hints from issue comments:
@funnywwh: c, d := F()! pass,but c, d := F()? failed.
@xushiwei 

Solution patch:
diff --git a/cl/_testgop/errwrap1/in.xgo b/cl/_testgop/errwrap1/in.xgo
index 0d9a3663..ec81b0ae 100644
--- a/cl/_testgop/errwrap1/in.xgo
+++ b/cl/_testgop/errwrap1/in.xgo
@@ -10,4 +10,4 @@ func F2() (err error) {
 	return
 }
 
-F2()
\ No newline at end of file
+F2()
diff --git a/cl/_testgop/errwrap2/in.xgo b/cl/_testgop/errwrap2/in.xgo
new file mode 100644
index 00000000..9a88ec51
--- /dev/null
+++ b/cl/_testgop/errwrap2/in.xgo
@@ -0,0 +1,13 @@
+func F() (a int8, b int16, err error) {
+	a = 1
+	return
+}
+
+func F2() (err error) {
+	c, d := F()?
+	_ = c
+	_ = d
+	return
+}
+
+F2()
diff --git a/cl/stmt.go b/cl/stmt.go
index 5d453b6e..74eb39d1 100644
--- a/cl/stmt.go
+++ b/cl/stmt.go
@@ -300,6 +300,8 @@ func compileAssignStmt(ctx *blockCtx, expr *ast.AssignStmt) {
 		inFlags = clCallWithTwoValue
 	}
 	if tok == token.DEFINE {
+		stk := ctx.cb.InternalStack()
+		base := stk.Len()
 		names := make([]string, len(expr.Lhs))
 		for i, lhs := range expr.Lhs {
 			if v, ok := lhs.(*ast.Ident); ok {
@@ -332,7 +334,7 @@ func compileAssignStmt(ctx *blockCtx, expr *ast.AssignStmt) {
 		for _, rhs := range expr.Rhs {
 			compileExpr(ctx, rhs, inFlags)
 		}
-		ctx.cb.EndInit(len(expr.Rhs))
+		ctx.cb.EndInit(stk.Len() - base)
 		return
 	}
 	for _, lhs := range expr.Lhs {



Test patch:
diff --git a/cl/_testgop/errwrap2/out.go b/cl/_testgop/errwrap2/out.go
new file mode 100644
index 00000000..2889f597
--- /dev/null
+++ b/cl/_testgop/errwrap2/out.go
@@ -0,0 +1,29 @@
+package main
+
+import "github.com/qiniu/x/errors"
+
+func F() (a int8, b int16, err error) {
+	a = 1
+	return
+}
+func F2() (err error) {
+	var _autoGo_1 int8
+	var _autoGo_2 int16
+	{
+		var _xgo_err error
+		_autoGo_1, _autoGo_2, _xgo_err = F()
+		if _xgo_err != nil {
+			_xgo_err = errors.NewFrame(_xgo_err, "F()", "cl/_testgop/errwrap2/in.xgo", 7, "main.F2")
+			return _xgo_err
+		}
+		goto _autoGo_3
+	_autoGo_3:
+	}
+	c, d := _autoGo_1, _autoGo_2
+	_ = c
+	_ = d
+	return
+}
+func main() {
+	F2()
+}