Giter VIP home page Giter VIP logo

Comments (7)

firas-assaad avatar firas-assaad commented on September 26, 2024 1

It didn't work because of the introduction of the missing field diagnostic. osdate fields returned by os.date won't have nil values, but you can pass a partial osdate to os.time. Simply updating osdate to make the fields optional would've made it difficult to work with the value returned from os.date (you'd have to check for nil), so I can understand why a separate type was needed.

from lua-language-server.

carsakiller avatar carsakiller commented on September 26, 2024 1

That is the problem talked about pretty extensively in #1456.

from lua-language-server.

C3pa avatar C3pa commented on September 26, 2024

Interesting, I can't reproduce this issue.

from lua-language-server.

firas-assaad avatar firas-assaad commented on September 26, 2024

I can reproduce it. It's because of the fix for this issue: #2235

os.time should probably be updated to accept osdate as well.

from lua-language-server.

C3pa avatar C3pa commented on September 26, 2024

I also narrowed it down to that commit. Maybe @carsakiller can tell us why the osdate param type didn't work and needed to be duplicated as osdateparam?

from lua-language-server.

carsakiller avatar carsakiller commented on September 26, 2024

@firas-assaad is correct. It was necessary to prevent excessive nil checking. This seems to be a similar problem, unfortunately. os.date can return a string or table (depending on the argument) but the server is unable to narrow the resulting type, leading to this warning that it could be a string.

I'm not sure if there is anything we can do with just the definitions to fix the string issue, as the return types of os.date are correct and the argument type of os.time is correct. We can't add a string as an option for os.time and we can't remove it as a return type of os.date either.

If we add osdate like @firas-assaad said, we can do the following:

local tDate = os.date("*t", os.time())
---@cast tDate -string
local newTime = os.time(tDate)

from lua-language-server.

firas-assaad avatar firas-assaad commented on September 26, 2024

I'm fine with having to cast to remove the string type. The current logic makes sense: a function may return a string, so if you pass the value to another function that only accepts tables, you'll have to add annotations to express your intent.

Now it'd be nice if we could override function definitions to say that the more specific '*t' argument returns a table whereas any other string argument returns a string, but that's probably a different story.

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.