Benjamin-Dobell / IntelliJ-Luanalysis

Type-safe Lua IDE — IntelliJ IDEA plugin
Apache License 2.0
155 stars 22 forks source link

`table<>` definitions with incorrect Type Mismatch errors #148

Closed pouwelsjochem closed 1 year ago

pouwelsjochem commented 1 year ago

Environment

Name Version
IDEA version 2022.3.1
Luanalysis version 1.4.0
OS MacOS

Lua

Name Setting
Language level 5.2

Type Safety

Name Setting
Strict nil checks ☑️
Unknown type (any) is indexable ☑️
Unknown type (any) is callabale ☑️

What are the steps to reproduce this issue?

---@alias MyKey "key1"|"key2"|"key3"

---@shape MyShape
---@field a string
---@field b number

local shapeTable = {
    key1 = {a = "1", b = 1},
    key2 = {a = "2", b = 2},
    key3 = {a = "3", b = 3},
} ---@type table<MyKey, MyShape>

local shapeTableWithEqualValues = {
    key1 = {a = "1", b = 1},
    key2 = {a = "1", b = 1},
    key3 = {a = "1", b = 1},
} ---@type table<MyKey, MyShape>

What happens?

Since Luanalysis 1.4.0 (I think this didn't happen before) table<> definitions give incorrect errors about the type not matching. Weirdly if all values are the same the error disappears.

Might be related to the plugin's new display format of tables since the error does include this new format: Type mismatch. Required: 'table<string, MyShape>' Found: '{ key1: { a: "1", b: 1 }, key2: { a: "2", b: 2 }, key3: { a: "3", b: 3 } }'

What were you expecting to happen?

No error to be given for shapeTable

Benjamin-Dobell commented 1 year ago

Strangely I'm unable to reproduce any errors being displayed on shapeTable's assignment. In fact, I'm actually able to get away with modifying shapeTable's table expression to be fundamentally invalid, and I'm still not seeing errors I would expect. So there's definitely some buggy behavior here!

I suspect this will be related generic parameter resolution changes I made.