diff --git a/changelog.md b/changelog.md index 59d4dee24..b46eb936b 100644 --- a/changelog.md +++ b/changelog.md @@ -2,6 +2,7 @@ ## Unreleased +* `FIX` Incorrect generation of function signatures with tuple-parameters * `FIX` Incorrect inject-field message for extra table field in exact class * `CHG` Rename configuration option `Lua.diagnostics.disableScheme` to `Lua.diagnostics.validScheme` and improve its description. Now it enables diagnostics for Lua files that use the specified scheme. * `FIX` adds the `|lambda|` operator to the `Lua.runtime.nonstandardSymbol` configuration template, which allows the use of that option. Previously, support for it existed in the parser, but we could not actually use the option because it is not recognised in the configuration. diff --git a/script/core/signature.lua b/script/core/signature.lua index 3f32bd3f7..1c3ba76b8 100644 --- a/script/core/signature.lua +++ b/script/core/signature.lua @@ -63,7 +63,11 @@ local function makeOneSignature(source, oop, index) : gsub('%b{}', function (str) return ('_'):rep(#str) end) - : gsub('[%[%]%(%)]', '_') + : gsub ('%b[]', function (str) + return ('_'):rep(#str) + end) + : gsub('[%(%)]', '_') + for start, finish in converted:gmatch '%s*()[^,]+()' do i = i + 1 params[i] = { diff --git a/test/signature/init.lua b/test/signature/init.lua index 010c15314..3423a03ec 100644 --- a/test/signature/init.lua +++ b/test/signature/init.lua @@ -234,6 +234,39 @@ end)() ]] {'function (, b: any)'} +TEST [[ +---@param a [any, any] +---@param b any +function X(a, b) end + +X({ 1, 2 }, ) +]] +{ +'function X(a: [any, any], )' +} + +TEST [[ +---@param a any +---@param b [any, any] +---@param c any +function X(a, b, c) end + +X(1, { 2, 3 }, 4) +]] +{ +'function X(a: any, , c: any)' +} + +TEST [[ +---@param a [table, {[1]:any,[2]:any}] +function X(a) end + +X({ { 1 }, { 2, 3 } }) +]] +{ +'function X(, { [1]: any, [2]: any }]!>)' +} + TEST [[ ---@overload fun() ---@overload fun(a:number)