Skip to content

Compare with v:none #17358

@habamax

Description

@habamax

Steps to reproduce

Hi, not sure if this is a bug or just my misunderstanding.

There is :h v:none which says that we can use is v:none to compare "something" with v:none

Image

However, running the simple code:

vim9script

def None(): any
    return v:none
enddef

if None() is v:none
    echow "None"
endif

Will result in error E1037
Image

Expected behaviour

Should be able to compare function return value with v:none?

Use case is to use omnicompletion function result with set complete=f{func}:

def LspSetup()
    if !exists("g:loaded_lsp")
        return
    endif

    def g:LspCompletor(maxitems: number, findstart: number, base: string): any
        if findstart == 1
            return g:LspOmniFunc(findstart, base)
        endif

        var data = g:LspOmniFunc(findstart, base)

        # can't use it here, due to error `E1072 Can not compary any with special`
        # return data isnot v:none ? {words: data->slice(0, maxitems), refresh: 'always'} : data

        # using this instead
        if type(data) == v:t_list
            return {words: data->slice(0, maxitems), refresh: 'always'}
        else
            return v:none
        endif
    enddef

    set complete+=ffunction("g:LspCompletor"\\,[10])
    g:LspOptionsSet({ autoComplete: false, omniComplete: true })
enddef

Version of Vim

9.1.1401

Environment

debian12

Logs and stack traces

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugvim9scriptVim9 script related issues

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions