Skip to content

ipairs iterator nil argument handling difference vs pairs iterator #91

@Wojbie

Description

@Wojbie

It seems there is small difference how pairs vs ipairs handle it when you explicitly put incorrect argument type.
obraz

While pairs provides bad argument error, ipairs instead attempts to index that wrong type value, leading to different error that is less readable to end user.

private Varargs pairs(LuaState state, Varargs args) throws LuaError, UnwindThrowable {
// pairs(t) -> iter-func, t, nil
LuaValue value = args.checkValue(1);
LuaValue pairs = value.metatag(state, Constants.PAIRS);
if (pairs.isNil()) {
return varargsOf(next, value, Constants.NIL);
} else {
return Dispatch.invoke(state, pairs, value);
}
}
private Varargs ipairs(LuaState state, Varargs args) throws LuaError {
// ipairst) -> iter-func, t, 0
return varargsOf(inext, args.checkValue(1), Constants.ZERO);
}

I understand from #87 that iterator returned by ipairs is supposed to be what is handling the erroring, but would it be possible to change the error handling of the iterator to be one for incorrect argument instead attempt to index? It would improve clarity and to simplify debugging for end users.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions