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

Linter Should Work According to Language Specifications #3035

Open
jakitliang opened this issue Jan 11, 2025 · 0 comments
Open

Linter Should Work According to Language Specifications #3035

jakitliang opened this issue Jan 11, 2025 · 0 comments

Comments

@jakitliang
Copy link

jakitliang commented Jan 11, 2025

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?

Diagnostics/Syntax Checking

Expected Behaviour

local Animal = Extends(Object)
function Animal:Speak(self)
  print('Animal.Speak')
end

local Person = Extends(Animal)
function Person:Speak(self) --- No error and diagnostics message 
  print('Person.Speak')
end

local p1 = New(Person)
p1:Speak() -- Code completion matches the function `Person:Speak(self)`

Actual Behaviour

local Animal = Extends(Object)
function Animal:Speak(self)
  print('Animal.Speak')
end

local Person = Extends(Animal)
function Person:Speak(self) --- Err: Duplicate field `Speak`. Lua Diagnostics
  print('Person.Speak')
end

Reproduction steps

  1. Just copy the code and let lsp lint them

Additional Notes

My Points:

  1. Polymorphism is a Core Feature of Object-Oriented Programming:
    Polymorphism is one of the core features of object-oriented programming. It allows different objects to use the same interface but exhibit different behaviors. It is widely used in many programming languages and is a key method for writing maintainable and extensible code.

  2. Lua is a Dynamic Language:
    Lua is dynamically typed, meaning it does not need to determine types at compile time like static languages. This provides great flexibility for programming. Through metatables and mechanisms such as __index and __call, Lua can implement many traditional object-oriented features, like inheritance and polymorphism.

  3. If Polymorphism is Opposed, Static Languages Should Be Chosen Instead of Using duplicate-set-field:
    If dynamic polymorphism is not acceptable, instead of enforcing the duplicate-set-field rule, a feature like @Final annotation should be introduced. Until such a feature is implemented, no changes should be made.
    If dynamic polymorphism is unacceptable, instead of adding duplicate-set-field, developers should consider other programming languages such as C#, Java, or C++, which are statically bound and support the final syntax for methods.

  4. Performance Trade-offs in Scripting Languages:
    The design of scripting languages typically makes trade-offs between performance and flexibility. For example, Python's OOP is based on the dict mechanism, which allows dynamic modification of object behavior. Ruby, on the other hand, uses the Object, BasicObject, Class, and ancestor lookup chains to achieve flexibility, which sacrifices some performance.
    For most scripting languages, performance is not the sole design consideration. Development efficiency, maintainability, and extensibility are the key goals. Over-optimization for performance, especially by limiting flexibility, is contrary to the design intent of scripting languages.

Log File

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant