From d11925853f6dd02ae5684a587257fd9b29202771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 18 Apr 2024 17:00:11 +0800 Subject: =?UTF-8?q?=E8=A1=A5=E5=85=85=E6=B5=8B=E8=AF=95=E5=92=8C=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E8=AF=B4=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.md | 31 +++++++++++++++++++++++++++++++ script/parser/luadoc.lua | 2 +- test/type_inference/init.lua | 9 ++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/changelog.md b/changelog.md index 20110331..50e719d8 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,37 @@ # changelog ## 3.7.5 +* `NEW` alias and enums supports attribute `merge` + ```lua + ---@alias Animal Cat + + ---@alias(merge) Animal Dog + + ---@type Animal + local animal --> animal is `Cat|Dog` here + ``` + + ```lua + ---@enum(key) ErrorCodes + local codes1 = { + OK = 0, + ERROR = 1, + FATAL = 2, + } + + ---@enum(key, merge) ErrorCodes + local codes2 = { + WARN = 3, + INFO = 4, + } + + ---@type ErrorCodes + local code + + code = 'ERROR' --> OK + code = 'WARN' --> OK + + ``` * `FIX` rename in library files ## 3.7.4 diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index bbffed25..7fd73c91 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -1026,7 +1026,7 @@ local docSwitch = util.switch() local result = { type = 'doc.alias', } - result.docAttr = parseDocAttr() + result.docAttr = parseDocAttr(result) result.alias = parseName('doc.alias.name', result) if not result.alias then pushWarning { diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index 98a07ca3..093cfb1e 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -4335,4 +4335,11 @@ end local = f() ]=] --- + +TEST 'boolean|number' [[ +---@alias A number +---@alias(merge) A boolean + +---@type A +local +]] -- cgit v1.2.3