Git Product home page Git Product logo

candle-compiler's People

Stargazers

 avatar

Watchers

 avatar  avatar

candle-compiler's Issues

Annotate generic classes as generic

Right now all generic classes are represented without the generic aspect. Generic classes are not actually supported by LuaLS right now, but annotating them as generic would still benefit developers. For example, IsoCell.getZombieList is annotated as returning ArrayList - annotating this as ArrayList<IsoZombie> instead would save a visit to the javadocs.
The annotations for this are quite simple:

---@generic T
---@class ArrayList<T>

---@return ArrayList<IsoZombie>

Unfortunately, the type inference ArrayList<T>.get -> T is not possible with LuaLS's current lack of support for generic classes - class methods annotated with the generic get dropped by intellisense completely. Because of this, defining generic classes has no actual effect on the type checker, making this issue a low priority.

Represent interfaces as classes

Currently we use a decorative ---@implement to annotate what interfaces that a class implements. I suggest that we instead have implementing classes inherit from them.
The benefit to this would be when a method's return type is an interface - for example, IsoZombie's getThumpTarget returns a Thumpable. There's basically nothing you can do with this without raising a warning.

local thumpable = zombie:getThumpTarget()
---@cast thumpable IsoThumpable

---@type IsoThumpable
local thumpable = zombie:getThumpTarget()

Both of these snippets raise a warning in the type checker as it doesn't see Thumpable as assignable to IsoThumpable (though they do still work).

If we were to do this, we'd also need to generate stubs for non-exposed interfaces that are implemented by exposed classes (I'm not really sure why there are exposed interfaces, but only they are currently annotated) - for example, Thumpable from the previous example isn't exposed, which means you can't call the interface methods without a warning either. We'd also need to undo the work on 'flattening' interfaces into their implementing classes.

I recall us having some trouble with interfaces before, so there may be a pitfall to this approach I'm missing. If there is, we could instead just alias all interfaces as a union type of all exposed implementing classes for similar effect - in fact we've already done this manually for Map and List.

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.