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

Wrong result of multi-assignment #440

Open
1 of 2 tasks
AlexanderYastrebov opened this issue Jun 2, 2023 · 2 comments
Open
1 of 2 tasks

Wrong result of multi-assignment #440

AlexanderYastrebov opened this issue Jun 2, 2023 · 2 comments

Comments

@AlexanderYastrebov
Copy link

You must post issues only here. Questions, ideas must be posted in discussions.

  • GopherLua is a Lua5.1 implementation. You should be familiar with Lua programming language. Have you read Lua 5.1 reference manual carefully?
  • GopherLua is a Lua5.1 implementation. In Lua, to keep it simple, it is more important to remove functionalities rather than to add functionalities unlike other languages . If you are going to introduce some new cool functionalities into the GopherLua code base and the functionalities can be implemented by existing APIs, It should be implemented as a library.

Please answer the following before submitting your issue:

  1. What version of GopherLua are you using? : 2b3f02d
  2. What version of Go are you using? : go version go1.20.4 linux/amd64
  3. What operating system and processor architecture are you using? : -
  4. What did you do? :
-- x.lua
local a, b = 0, 0
a, b = a + 1, a + b
print(a, b)
$ lua -v
Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
$ lua x.lua 
1       0
$ git describe --tags
v1.1.0-11-g2b3f02d
$ make glua
$ ./glua x.lua 
1       1
  1. What did you expect to see? :
1       0
  1. What did you see instead? :
1       1

This looks related to #355 and #315.

Discovered while debugging test suite for https://github.com/Egor-Skriptunoff/pure_lua_SHA

$ glua sha2_test.lua 
./sha2.lua:87: at least 53-bit floating point numbers are required
stack traceback:
        [G]: in function 'assert'
        ./sha2.lua:87: in function <./sha2.lua:0>
        [G]: in function 'require'
        sha2_test.lua:5: in main chunk
        [G]: ?

which fails due to incorrect multi-assignment calculation here https://github.com/Egor-Skriptunoff/pure_lua_SHA/blob/6adac177c16c3496899f69d220dfb20bc31c03df/sha2.lua#L75

@AlexanderYastrebov
Copy link
Author

Funny, #315 (comment) reports the same problem and comment is liked by @Egor-Skriptunoff who is the author https://github.com/Egor-Skriptunoff/pure_lua_SHA 🙈

@octalide
Copy link

Bump. Hugely annoying issue.

A bog-standard non-recursive fib function that uses multi-assignment can be easily used to reproduce this bug:

function fib(n)
    if n <= 1 then
        return n
    end
    local a, b = 0, 1
    for i = 2, n do
        print("calc: [i: " .. i .. ", b: " .. b .. "]")
        a, b = b, a + b
    end
    return b
end

fib(35) -- produces 17179869184 instead of 9227465, a symptom of doubling the value every cycle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants