Skip to content

Conversation

@fvkluck
Copy link
Contributor

@fvkluck fvkluck commented Nov 1, 2017

filter(v:_null_list, 'v:val') currently returns 0, but should return v:_null_list. Ref #4615

@marvim marvim added the WIP label Nov 1, 2017
@ZyX-I
Copy link
Contributor

ZyX-I commented Nov 1, 2017

Don’t alter src/nvim/testdir with anything Neovim-specific, that is legacy Vim test suite. All the NULL checks are currently in test/functional/eval/null_spec.lua, commented with FIXME’s and given that tests are not failing problem is not fixed.

@ZyX-I
Copy link
Contributor

ZyX-I commented Nov 1, 2017

Also you must not use assert_equal or equality operator in any fashion at all: NULL list is supposed to be equal to any empty list (actually, one of the problems listed in the issue), but you need to check that filter() returns the same and not equal list. The file I referenced uses is# for the purpose.

@fvkluck
Copy link
Contributor Author

fvkluck commented Nov 9, 2017

[Edit]: I just noticed my repo history is incorrect even though I thought I had it fixed locally. I don't have time anymore to look into it now, but will try to fix it in the weekend.

Thank you for the feedback. I had completely looked over/forgotten about the new
tests, even though they were mentioned in the documentation.
I have a couple of questions/remarks to accompany my new commit:

  • There are two tests that test that the filter and map functions do not crash
    when they get passed the null list as argument. But if these functions run
    and have the result v:_null_list as required, this also implies that they
    have not crashed. Assuming this is true, I have removed these tests, or did I miss something?
  • The function filter_map can take either a list or a dict as an argument. I
    only changed the list part now, but if the general idea is approved I'd also
    like to change the dict part in a similar way. Is this ok?
  • Currently, when the list passed as an argument is not the null list, but it is locked, the function
    still returns 0. This is to maintain original behaviour. However, I could
    imagine that in this case actually we also would want to return the original
    list. Do you have any thoughts about this matter?
    Apart from that, all feedback is of course welcome.

@ZyX-I
Copy link
Contributor

ZyX-I commented Nov 10, 2017

  • The crash was fixed earlier, but map() and filter() got to return zero and not a list, NULL or not: FIXME above no longer talks about crash . Better leave them, just fix expected result.
  • NULL dictionaries are tested for in below describe() block. But I did not go and check how various functions behave with NULL dictionaries, so it just tests what got my attention.
  • filter() errors out in such conditions immediately, but map() is fine (checking locked empty list). I would not say what is better and whether they both should do one or the other, but zero is not described in documentation and I think still returning original list is better.

-- FIXME filter() should at least return L
null_expr_test('makes filter() return v:_null_list', 'map(L, "1") is# L', 0, 0)
null_expr_test('makes map() return v:_null_list', 'map(L, "v:val") is# L', 0, 1)
null_expr_test('makes filter() return v:_null_list', 'map(L, "1") is# L', 0, 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is a copy-paste typo, test needs to test filter(). And, BTW, list with OK tests is below, in this part only tests that need fixing are located. You may see “Incorrect behaviour” comment above.

call assert_equal([2, 3, 4], filter([1, 2, 3, 4], 'v:val > 1'))
call assert_equal([3, 4], filter([1, 2, 3, 4], 'v:key > 1'))
call assert_equal([], filter([1, 2, 3, 4], 0))
call assert_equal(v:_null_list, filter(v:_null_list, 'v:val'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs not be here.

src/nvim/eval.c Outdated
if ((l = argvars[0].vval.v_list) == NULL
|| (!map && tv_check_lock(l->lv_lock, arg_errmsg, TV_TRANSLATE))) {
l = argvars[0].vval.v_list;
if (l != NULL && !map && tv_check_lock(l->lv_lock, arg_errmsg, TV_TRANSLATE)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to leave check as-is. Just move tv_copy() here and into the VAR_DICT case to leave only invalid inputs with zero return, modifications are in-place in any case. This also means that you need not modify anything else at all, only one line transition to two places.

src/nvim/eval.c Outdated
} else if (argvars[0].v_type == VAR_DICT) {
if ((d = argvars[0].vval.v_dict) == NULL
|| (!map && tv_check_lock(d->dv_lock, arg_errmsg, TV_TRANSLATE))) {
tv_copy(&argvars[0], rettv);
Copy link
Contributor

@ZyX-I ZyX-I Nov 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you have three tv_copy() calls like if that needs to be called before return for some reason; I meant that in the surrounding if(), but with the bottommost one removed: like if saying that first argument is always returned if it has valid type.

@fvkluck
Copy link
Contributor Author

fvkluck commented Dec 3, 2017

Sorry for the delay, had to allocate time to different things in the past three weeks. I think this is what you meant, right?

filter('v:_null_list, 'v:val') should return v:_null_list and a similar
statement should hold for map.

Changes after review

 * Test inserted in legacy test suite has been removed by reverting the commit
adding it.
 * Change the fix to tv_copy the argument before returning.
 * Readd the two tests on crashes, and modified their expected return value.
 * Move the test from 'incorrect behaviour' section to 'correct behaviour section'
 * Add analogous tests for v:_null_dict

Always copy list or dictionary to return variable

If the type of input is correct (i.e. either a list or a dictionary), this
should also be returned.
@fvkluck
Copy link
Contributor Author

fvkluck commented Dec 3, 2017

Ok, I retrieved the latest changes in the repository, and then rebased and force pushed. As far as I understand it, this means it is ready to be merged. However, do note that this is my first time working non-locally with git.

@fvkluck fvkluck changed the title [WIP] viml: Add test for filter on v:_null_list [RDY] viml: Add test for filter on v:_null_list Dec 3, 2017
@marvim marvim added RDY and removed WIP labels Dec 3, 2017
@justinmk justinmk merged commit aec81f4 into neovim:master Dec 5, 2017
@justinmk justinmk removed the RDY label Dec 5, 2017
@fvkluck fvkluck deleted the empty-lists-dicts-strings branch December 5, 2017 17:47
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

Successfully merging this pull request may close these issues.

4 participants