diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index dd3bad1ad..17bc83ea3 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -1288,6 +1288,10 @@ proc genArg(p: PProc, n: PNode, param: PSym, r: var TCompRes) = add(r.res, a.address) add(r.res, ", ") add(r.res, a.res) + elif n.typ.kind == tyVar and n.kind in nkCallKinds: + # this fixes bug #5608: + let tmp = getTemp(p) + add(r.res, "($1 = $2, $1[0]), $1[1]" % [tmp, a.rdLoc]) else: add(r.res, a.res) diff --git a/tests/js/tbyvar.nim b/tests/js/tbyvar.nim index f974049b9..e3690df98 100644 --- a/tests/js/tbyvar.nim +++ b/tests/js/tbyvar.nim @@ -5,6 +5,11 @@ bar 12 foo 12 bar 12 2 +12.5 +(nums: @[5, 5, 10, 5, 5, 5, 5, 5, 5, 5]) +(nums: @[5, 5, 50, 5, 5, 5, 5, 5, 5, 5]) +(nums: @[5, 5, 45, 5, 5, 5, 5, 5, 5, 5]) +(nums: @[5, 5, 9, 5, 5, 5, 5, 5, 5, 5]) ''' """ @@ -59,3 +64,41 @@ block: # Test var arg inside case expression. #5244 var a = "ok" foo(a) doAssert(a == "ok") + + +proc mainowar = + var x = 9.0 + x += 3.5 + echo x + +mainowar() + + +# bug #5608 + +type Foo = object + nums : seq[float] + +proc newFoo(len : int, default = 0.0) : Foo = + result = Foo() + result.nums = newSeq[float](len) + for i in 0..(len - 1): + result.nums[i] = default + +proc `[]=`(f : var Foo, i : int, v : float) = + f.nums[i] = v + +proc `[]`(f : Foo, i : int) : float = f.nums[i] + +proc `[]`(f : var Foo, i : int) : var float = f.nums[i] + +var f = newFoo(10,5) + +f[2] += 5 +echo f +f[2] *= 5 +echo f +f[2] -= 5 +echo f +f[2] /= 5 +echo f