Skip to content

Literal alias will throw false alarm #1684

Description

@evan361425

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

MacOS

What is the issue affecting?

Annotations, Type Checking

Expected Behaviour

Follow the wiki tutorial:

local A = "Hello"
local B = "World"

---@alias myLiteralAliases `A` | `B`

---@param x myLiteralAliases
function foo(x) end

it should not show any warning when using it:

foo(A)

Actual Behaviour

It show warning:

Cannot assign `string` to parameter ``A`|`B``.
- `string` cannot match ``A`|`B``Lua Diagnostics.(param-type-mismatch)

Screen Shot 2022-11-10 at 11 42 56 AM

Reproduction steps

Enter the code in VSCode

local A = "Hello"
local B = "World"

---@alias myLiteralAliases `A` | `B`

---@param x myLiteralAliases
function foo(x) end

foo(A)

then you will see it

Additional Notes

Some info:

$ code --version
1.73.0
8fa188b2b301d36553cbc9ce1b0a146ccb93351f
x64
$ ls ~/.vscode/extensions/ | grep sumneko
sumneko.lua-3.6.2-darwin-x64

Log File

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions