LuaLS / LuaLS/lua-language-server

Class Inheritance Triggers Typing Issues

Ouverte
#1,893 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

question
Langage dominant
Lua
Étoiles
4.4k
Forks
442
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

### How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

### Which OS are you using?

Windows

### What is the issue affecting?

Type Checking, Diagnostics/Syntax Checking

### Expected Behaviour

To put it in plain terms, this is for a system of UserControls for a settings-panel system. There is a single Superclass, called "MCT.Option", which houses all of the unified behavior of all the UserControls. Then there are subclasses, for each type of UserControl - checkbox, dropdown, etc.

There's an abstracted method on the UserControl "holders", `holder:get_option_by_key("user_control_key')` that I have annotated as returning an MCT.Option. In reality, that superclass is never actually returned in practice - it's purely abstracted, and any option is one of the several subclasses.

So when I call:
```
---@type MCT.Option.Checkbox
local option = holder:get_option_by_key("i_know_this_is_a_checkbox")
```
I'm expecting to very easily call a conversion from superclass -> subclass.

I have all that (I think) I need to tell the debugger that it's a subclass: initial definition of the subclass is `---@class MCT.Option.Checkbox : MCT.Option, Class` to tell it its parents, and it reads from the higher methods and properties completely fine.

But when I call ---@type like that, the debugger doesn't let me simply convert from one to another.

I can of course use `---@cast option MCT.Option.Checkbox` after the variable is defined, but that's a bit clunkier in my opinion than having the type defined above the variable, and it ends up requiring me to reference the variable in the annotation, so it takes a bit longer to write up (and I have a lot of these!)

### Actual Behaviour

![image](https://user-images.githubusercontent.com/39225561/217849625-8341465c-2717-438d-940f-c31cb41e0a7d.png)

### Reproduction steps

1. Create a superclass:
```
---@class MySuperclass
local o = {}
```
2. Create a subclass:
```
---@class MySubclass : MySuperclass
local o = {}
```
3. Create a function that returns MySuperclass
4. Try to direct the type that returns from that function into MySublass

### Additional Notes

Thank you for all the hard work you've done over the years - I've been using this extension for a very very long time and it's truly a lifesaver.

### Log File

[file_s%3A_modding_warhammer_3_groovy_mct.log](https://github.com/LuaLS/lua-language-server/files/10698513/file_s.3A_modding_warhammer_3_groovy_mct.log)

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par reproduire les exemples de superclasse et de sous-classe de l’issue via l’extension Visual Studio Code sous Windows, en vous concentrant sur le diagnostic de vérification de type pour l’affectation d’un résultat de MySuperclass à MySubclass. Suivez le comportement de vérification de type impliqué dans l’héritage de classes et confirmez que l’affectation est acceptée sans nécessiter @cast une fois la correction terminée.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
lua
Domaine
devtools
Type d'issue
Bug
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.