Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

部分函数返回值判断错误 #1292

Closed
Redbeanw44602 opened this issue Jul 6, 2022 · 4 comments
Closed

部分函数返回值判断错误 #1292

Redbeanw44602 opened this issue Jul 6, 2022 · 4 comments
Labels
bug Something isn't working
Milestone

Comments

@Redbeanw44602
Copy link

类似 #1260 ,也是最近出现的问题。
prob

可以复现问题的代码:

N = {
    p =  {nil,9}
}

function N:TestBug()
    local a = math.random(99)
    if a > 88 then
        return self.p[a]
    end
    return nil
end
@sumneko sumneko added the as designed Functioning as intended, will not be modified label Jul 6, 2022
@sumneko
Copy link
Collaborator

sumneko commented Jul 6, 2022

如果没有明确指定表的类型,以整数键从表中取值时,我只会根据索引1推测类型

---@type integer
local i
local t = ({nil, 9})[i] -- `t` is `nil`

@Redbeanw44602
Copy link
Author

emm,self.loaded 开发中是{}(运行时加载),这个推断就有点不方便了。
能否考虑未声明表类型则判断为 unknown 之类的?

@sumneko
Copy link
Collaborator

sumneko commented Jul 7, 2022

请提供演示代码

@Redbeanw44602
Copy link
Author

比如

N = {
    p =  {}
}

J = require "dkjson"
N.p = J.decode('[1,2,3,4]')

function N:TestBug() -- 返回值依旧判断为nil
    local a = math.random(99)
    if a > 88 then
        return self.p[a]
    end
    return nil
end

@sumneko sumneko added bug Something isn't working and removed as designed Functioning as intended, will not be modified labels Jul 7, 2022
@sumneko sumneko added this to the 3.5.0 milestone Jul 7, 2022
@sumneko sumneko closed this as completed in 91f9683 Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants