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

Comparing against type overrides it #1841

Closed
firas-assaad opened this issue Jan 21, 2023 · 3 comments
Closed

Comparing against type overrides it #1841

firas-assaad opened this issue Jan 21, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@firas-assaad
Copy link
Contributor

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, Hover

Expected Behaviour

Trying the following minimal example:

---@param v integer
---@return boolean
local function is_string(v)
    return type(v) == 'string'
end

print(is_string(3))

The type of the parameter v should be integer, and I shouldn't get any warnings about passing an integer value to is_string.

Actual Behaviour

I get a type mismatch at is_string(3):

image

Hovering over v inside the is_string function also shows its type as string instead of integer.

Reproduction steps

  1. Try the code above in vscode with extension version 3.6.7

Additional Notes

No response

Log File

No response

@Immow
Copy link

Immow commented Jan 21, 2023

Not sure if it's relevant but when I try to print a number with love.graphics.print(10) I also get a warning that it's not a string.
I would expect print can just print anything honestly?

image

My temp fix is changing ---@param text string to ---@param text any

Complete code snippet

---@overload fun(coloredtext: table, x?: number, y?: number, angle?: number, sx?: number, sy?: number, ox?: number, oy?: number, kx?: number, ky?: number)
---@overload fun(text: string, transform: love.Transform)
---@overload fun(coloredtext: table, transform: love.Transform)
---@overload fun(text: string, font: love.Font, transform: love.Transform)
---@overload fun(coloredtext: table, font: love.Font, transform: love.Transform)
---@param text string # The text to draw.
---@param x? number # The position to draw the object (x-axis).
---@param y? number # The position to draw the object (y-axis).
---@param r? number # Orientation (radians).
---@param sx? number # Scale factor (x-axis).
---@param sy? number # Scale factor (y-axis).
---@param ox? number # Origin offset (x-axis).
---@param oy? number # Origin offset (y-axis).
---@param kx? number # Shearing factor (x-axis).
---@param ky? number # Shearing factor (y-axis).
function love.graphics.print(text, x, y, r, sx, sy, ox, oy, kx, ky) end

@firas-assaad
Copy link
Contributor Author

Not sure if it's relevant but when I try to print a number with love.graphics.print(10) I also get a warning that it's not a string. I would expect print can just print anything honestly?

I don't think that's related. I can't verify what actually works in love, but both the wiki and the API Documentation specify either a string or a table as the parameter, so the param type mismatch warning is probably correct.

@iiAngel
Copy link

iiAngel commented Jan 21, 2023

Just like firas said you can't print out a number parameter when table/string parameters are specified but if you wanna print out a number you can use tostring()

@sumneko sumneko added the bug Something isn't working label Jan 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants