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

Global typed variables have union type with themself #63

Closed
Perryvw opened this issue Oct 10, 2017 · 1 comment
Closed

Global typed variables have union type with themself #63

Perryvw opened this issue Oct 10, 2017 · 1 comment

Comments

@Perryvw
Copy link
Contributor

Perryvw commented Oct 10, 2017

When defining a global variable, such as:

--- @type CustomGameState
CUSTOM_GAME_STATE_PRE_GAME = 0
--- @type CustomGameState
CUSTOM_GAME_STATE_INTRO = 1
--- @type CustomGameState
CUSTOM_GAME_STATE_PHASE_1A = 2

I would expect the type of these two enum values to simply be CustomGameState, instead their type is CustomGameState|CUSTOM_GAME_STATE_PHASE_1A, a union with themself. I do not want this union, it messes up all my definitions.

@tangzx tangzx closed this as completed in e317a4f Oct 11, 2017
@Perryvw
Copy link
Contributor Author

Perryvw commented Oct 11, 2017

I do not agree with that fix, that changes the subtype definition of a union type, which was fine. The issue is that global variables are declared as their own global type, even though they have a special type definition.

The issue here is the type of the variable, not the definition of subtype of union, which is now incorrect. This would mean that a function requiring type string|number (requiring string or number) would allow a variable of string|boolean (string or boolean) as input. This would mean it would allow assignment of booleans to fields that expect numbers or strings:

---@return number | string
function myfun()
    ---@type number | boolean
    local myvar = true
    return myvar -- Allowed in your version! Returns true while return type is number|string.
end

Please re-open.

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