[Feature request] Better semantics for try/catch
Nobody has claimed this yet.
- Dominant language
- Lua
- Stars
- 613
- Forks
- 45
- PR merge metrics
- No merged PRs in 30d
Description
Note: this is a breaking change!
I would like to see the semantics of try/catch be changed to make it (in my opinion) more useful.
I think that
x = try
do_something()
catch err
handle_error(err)
should be changed from compiling to
local x = xpcall(function()
return do_something()
end, function(err)
return handle_error(err)
end)
into compiling to this:
local x = select(2, xpcall(function()
return do_something()
end, function(err)
return handle_error(err)
end))
The addition of select(2, [...]) causes the boolean that's normally returned by xpcall() to be skipped. This would feel more natural to use in many cases, and allow for patterns like this:
x = (try maybe_failing_operation()) ?? "default"
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the compiler handling try/catch and the existing xpcall lowering, then compare its generated Lua with the examples in this issue. Done means the proposed result-handling semantics are implemented consistently, including the default-value pattern, with coverage for the breaking behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- lua
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100