Git Product home page Git Product logo

Comments (9)

mpeterv avatar mpeterv commented on August 23, 2024

Update: I'm sorry for not providing an actual example.

> assert = require "luassert"
> assert.is_true()
/usr/local/share/lua/5.2/luassert/assertions.lua:97: bad argument #2 to 'insert' (position out of bounds)
stack traceback:
    [C]: in function 'insert'
    /usr/local/share/lua/5.2/luassert/assertions.lua:97: in function 'callback'
    /usr/local/share/lua/5.2/luassert/assert.lua:54: in function 'is_true'
    stdin:1: in main chunk
    [C]: in ?

The error is only raised under Lua >= 5.2.2.

I'll try to make a pull request fixing the issue.

from luassert.

Tieske avatar Tieske commented on August 23, 2024

This is what I get;

C:\Users\Thijs>lua52
Lua 5.2.1  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> assert = require("luassert")
> assert.is_true()
stdin:1: Expected objects to be the same. Passed in:
(nil)
Expected:
true
stack traceback:
        [C]: in function 'error'
        ...(x86)\LuaRocks\systree\share\lua\5.1\luassert\assert.lua:60: in function 'is_true'
        stdin:1: in main chunk
        [C]: in ?
>

Has your interpreter been compiled without the 'compatibility' flag?

What happens when you run the luassert test suite?

from luassert.

mpeterv avatar mpeterv commented on August 23, 2024

@Tieske, I checked Lua source and the check doesn't depend on the compatibility flag, but it was only introduced in Lua 5.2.2. 5.2.1 5.2.2

Luassert test suite fails, most errors are related to this issue.

from luassert.

DorianGray avatar DorianGray commented on August 23, 2024

It looks like the lua developers decided that table.insert should treat tables only as arrays as of lua 5.2.2. They do not allow insertion at arbitrary indices.

I suggest we change the offending line in assertions to read

arguments[2] = true

instead of

table.insert(arguments, 2, true)

from luassert.

DorianGray avatar DorianGray commented on August 23, 2024

This will need to be changed for the other assertions as well. I don't understand why they did this to us. The change in lua 5.2 seems...silly. The only thing I can think of is that they didn't want undefined behavior for sparse arrays?

from luassert.

Tieske avatar Tieske commented on August 23, 2024

I think the best solution would be to create a local tinsert() function that does the right thing and replace all calls to table.insert() with that.

from luassert.

DorianGray avatar DorianGray commented on August 23, 2024

What is your reasoning on why calling tinsert is best?

from luassert.

mpeterv avatar mpeterv commented on August 23, 2024

There is even utils.tinsert implemented already which seems to do the right thing.

from luassert.

Tieske avatar Tieske commented on August 23, 2024

@DorianGray because stock Lua is bad at handling nils. And luassert really needs it. That is why utils.tinsert was added in the first place.

Imo it would provide least chance of problems

@mpeterv thanks for bringing that back to memory!

from luassert.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.