Giter Club home page Giter Club logo

Comments (1)

aatxe avatar aatxe commented on August 27, 2024 1

Here is some context about why this is happening.

There's currently an affordance that indexing a table with an indexer returns a non-nil type. This is present because (at some point) we believed users would find it too frustrating to have to check for nil on every index, and we did not have the type refinement and typestate machinery to necessarily support inferring it automatically.

For example,

local x = { 1, 2, 3 }
if x[4] then
    fib(x[5])
end

In this case, it's not really clear what behavior is possible with the systems in place that doesn't lead to issues (either DX issues or unsoundness issues). This applies as well to function returns because you can return the results from indexing:

function getFourth<T>(tbl: {T}): T
    return tbl[4]
end

The current design point we're at for the new solver here is that indexers (and functions, as a result) can return nil without the type reflecting that, but we want people to be able to still write guards which require them to be able to compare to nil, and so, in conditional contexts, the type of function results and indexing results include implicit nil possibilities.

This lets you still write a check like...

if x[4] ~= nil then
    use(x[4])
end

without requiring refinements to be able to support a refinement per-individual-index and so forth.

All that context being said, it seems like the bug here is that it, for whatever reason, is continuing into the ensuing scope which is unexpected. The type shouldn't be changed, only temporarily viewed as containing nil in a conditional context.

from luau.

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.