Skip to content

Improve error messages for generic pack and variadic type mismatches#2504

Open
PhoenixWhitefire wants to merge 4 commits into
luau-lang:masterfrom
PhoenixWhitefire:pack-variadic-mismatch
Open

Improve error messages for generic pack and variadic type mismatches#2504
PhoenixWhitefire wants to merge 4 commits into
luau-lang:masterfrom
PhoenixWhitefire:pack-variadic-mismatch

Conversation

@PhoenixWhitefire

Copy link
Copy Markdown
Contributor

Given;

local function _foo<T...>(a: number, ...: T...)
    -- E1
    local _t = table.pack(...)
end

type fn = <DT...>(b: string, DT...) -> number
-- E2
local _fun: fn = function<FT>(b: string, ...: FT): number
    return 5
end

-- E3
type fn2 = <DT>(DT...) -> number

-- E4
local _fun2 = function<FT...>(...: FT)
end

, where;

E1: Expected this to be '...V', but got 'T...'

E2: Expected this to be
	'<DT...>(string, DT...) -> number'
but got
	'<FT>(string, ...FT) -> number'; 
it takes a tail of `...FT` in the latter type and `DT...` in the former type, and `...FT` is not a supertype of `DT...`

E3: Generic type 'DT' is used as a variadic type parameter; consider changing 'DT' to 'DT...' in the generic argument list

E4: Variadic type parameter 'FT...' is used as a regular generic type; consider changing 'FT...' to 'FT' in the generic argument list

, updates them to:

E1: Expected this to be '...V', but got 'T...'; the former is a variadic, and the latter is a generic pack; consider changing the generic to 'T', and the variadic parameter to  '...: T'.

E2: [...], and `...FT` is not a supertype of `DT...`; the former type has a generic pack, and the latter type has a variadic, consider changing the former generic to `DT` or the latter generic to `FT...`

E3: Generic type 'DT' is used like a generic pack; consider changing it to 'DT...' in the generic argument list or using it as 'DT' or '...DT'

E4: Generic pack 'FT...' is used like a generic type; consider changing it to 'FT' in the generic argument list or using it as 'FT...'

Adds flag LuauBetterPackAndVariadicMismatchErrors and 1 test

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

Successfully merging this pull request may close these issues.

1 participant