Git Product home page Git Product logo

Comments (1)

tomlau10 avatar tomlau10 commented on August 22, 2024

I debugged a bit and seems that the logic doesn't handle the case when source object is of variable type which can also be inferred as integer:

: case '<<'
: case '>>'
: case '&'
: case '|'
: case '~'
: call(function (source)
local a = vm.getInteger(source[1])
local b = vm.getInteger(source[2])
local op = source.op.type
if a and b then
local result = op == '<<' and a << b
or op == '>>' and a >> b
or op == '&' and a & b
or op == '|' and a | b
or op == '~' and a ~ b
---@diagnostic disable-next-line: missing-fields
vm.setNode(source, {
type = 'integer',
start = source.start,
finish = source.finish,
parent = source,
[1] = result,
})
else
local node = vm.runOperator(binaryMap[op], source[1], source[2])
if not node then
node = vm.runOperator(binaryMap[op], source[2], source[1])
end
if node then
vm.setNode(source, node)
end
end

  • it will run the else case as vm.getInteger() will not handle variable source objects

Meanwhile for the + case, it has the following extra handling:

if op == '+'
or op == '-'
or op == '*'
or op == '%' then
local uri = guide.getUri(source)
local infer1 = vm.getInfer(source[1])
local infer2 = vm.getInfer(source[2])
if infer1:hasType(uri, 'integer')
and infer2:hasType(uri, 'integer') then
vm.setNode(source, vm.declareGlobal('type', 'integer'))
return
end

I copied this to the << case, and it seems to work now:

    : case '<<'
    : case '>>'
    : case '&'
    : case '|'
    : case '~'
    : call(function (source)
        local a = vm.getInteger(source[1])
        local b = vm.getInteger(source[2])
        local op = source.op.type
        if a and b then
            local result = op == '<<' and a << b
                        or op == '>>' and a >> b
                        or op == '&'  and a &  b
                        or op == '|'  and a |  b
                        or op == '~'  and a ~  b
            ---@diagnostic disable-next-line: missing-fields
            vm.setNode(source, {
                type   = 'integer',
                start  = source.start,
                finish = source.finish,
                parent = source,
                [1]    = result,
            })
        else
            local node = vm.runOperator(binaryMap[op], source[1], source[2])
            if not node then
                node = vm.runOperator(binaryMap[op], source[2], source[1])
            end
            if node then
                vm.setNode(source, node)
--- patch start
                return
            end
            local uri = guide.getUri(source)
            local infer1 = vm.getInfer(source[1])
            local infer2 = vm.getInfer(source[2])
            if  infer1:hasType(uri, 'integer')
            and infer2:hasType(uri, 'integer') then
                vm.setNode(source, vm.declareGlobal('type', 'integer'))
                return
--- patch finish
            end
        end
    end)

maybe @RomanSpector you can test about it and open a PR?

from lua-language-server.

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.