Skip to content

fix(type): preserve unknown unions and narrow pcall(any)#997

Open
lewis6991 wants to merge 1 commit intoEmmyLuaLs:mainfrom
lewis6991:fix/pcallneverunion
Open

fix(type): preserve unknown unions and narrow pcall(any)#997
lewis6991 wants to merge 1 commit intoEmmyLuaLs:mainfrom
lewis6991:fix/pcallneverunion

Conversation

@lewis6991
Copy link
Copy Markdown
Collaborator

@lewis6991 lewis6991 commented Mar 29, 2026

Preserve unknown as a real union member in type unions and doc-type
parsing instead of collapsing unknown|T to T.

Update call sites that previously used Unknown as an empty union
accumulator to use Never or explicit first-value handling, and avoid
merging missing closure param annotations as unknown.

Keep the pcall(any) flow fixes so the payload stays unknown|string
outside the branch, narrows to unknown on success, and narrows to string
on failure.


This fixes local ok, result = pcall(x) where x:any so the success branch
sees unknown and the failure branch sees string.

---@type any
local x

local ok, result = pcall(x)
if ok then
    success = result -- should be unknown
else
    failure = result -- should be string
end

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request improves the handling of never types within unions and simplifies the processing of MultiLineUnion types across the codebase. Specifically, LuaType::from_vec now correctly preserves LuaType::Never when a union would otherwise be empty, and several semantic analysis functions were refactored to recursively handle the results of MultiLineUnion::to_union. Additionally, new test cases were added to verify type preservation for multiline aliases and type narrowing with pcall. I have no feedback to provide.

@lewis6991 lewis6991 marked this pull request as draft March 29, 2026 12:29
@lewis6991 lewis6991 force-pushed the fix/pcallneverunion branch from 6e67f2c to 553df12 Compare March 29, 2026 13:07
@lewis6991 lewis6991 changed the title fix(flow): preserve pcall narrowing for normalized alias payloads fix(flow): split pcall any payload by branch Mar 29, 2026
@lewis6991 lewis6991 marked this pull request as ready for review March 29, 2026 14:19
@lewis6991 lewis6991 marked this pull request as draft March 29, 2026 14:52
@lewis6991 lewis6991 force-pushed the fix/pcallneverunion branch from 553df12 to dde00cd Compare March 29, 2026 16:02
@lewis6991 lewis6991 changed the title fix(flow): split pcall any payload by branch fix(type): preserve unknown unions and narrow pcall(any) Mar 29, 2026
@lewis6991 lewis6991 marked this pull request as ready for review March 29, 2026 16:10
@lewis6991 lewis6991 force-pushed the fix/pcallneverunion branch from dde00cd to 23f70d7 Compare March 29, 2026 16:34
Preserve unknown as a real union member in type unions and doc-type
parsing instead of collapsing unknown|T to T.

Update call sites that previously used Unknown as an empty union
accumulator to use Never or explicit first-value handling, and avoid
merging missing closure param annotations as unknown.

Keep the pcall(any) flow fixes so the payload stays unknown|string
outside the branch, narrows to unknown on success, and narrows to string
on failure.
@lewis6991 lewis6991 force-pushed the fix/pcallneverunion branch from 23f70d7 to ccab61c Compare March 29, 2026 16:45
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