Skip to content

Commit cc04d24

Browse files
committed
TestBigIntVarInit: bugfix
1 parent 279f5b7 commit cc04d24

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

gop_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,22 @@ var a builtin.Gop_bigint
123123
`)
124124
}
125125

126+
func TestBigIntVarInit(t *testing.T) {
127+
pkg := newGopMainPackage()
128+
mbig := pkg.Import("github.com/goplus/gox/internal/builtin")
129+
pkg.CB().NewVarStart(mbig.Ref("Gop_bigint").Type(), "a").
130+
UntypedBigInt(big.NewInt(6)).EndInit(1)
131+
domTest(t, pkg, `package main
132+
133+
import (
134+
builtin "github.com/goplus/gox/internal/builtin"
135+
big "math/big"
136+
)
137+
138+
var a builtin.Gop_bigint = builtin.Gop_bigint_Init__1(big.NewInt(6))
139+
`)
140+
}
141+
126142
func TestBigInt(t *testing.T) {
127143
pkg := newGopMainPackage()
128144
big := pkg.Import("github.com/goplus/gox/internal/builtin")

type_var_and_const.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,13 @@ func (p *ValueDecl) endInit(cb *CodeBuilder, arity int) *ValueDecl {
160160
pkg, scope := cb.pkg, cb.current.scope
161161
typ := p.typ
162162
if typ != nil {
163-
for _, ret := range rets {
163+
for i, ret := range rets {
164164
if err := matchType(pkg, ret, typ, "assignment"); err != nil {
165165
panic(err)
166166
}
167+
if values != nil { // ret.Val may be changed
168+
values[i] = ret.Val
169+
}
167170
}
168171
}
169172
for i, name := range p.names {

0 commit comments

Comments
 (0)