Exhaustive `constexpr` for `switch`
@tolk-vm is already working on this.
Since Mar 16, 2023.
Assessment
This issue has not been assessed yet.
Description
constexpr for switch was supported in #727 and #770.
The problem
Consider following snippet
f(new Foo());
/**
* @kphp-generic T
* @param T $o
*/
function f($o) {
switch (classof($foo)) {
case Bar::class:
// doing some work
break;
// No case for Foo::class.
// No `default` too.
// We have completely forgotten about Foo :(
}
}
Now, trying to compile this code and... everything compiles just fine. For Foo we'll get following codegen:
static_cast<void>(v$matched_with_one_case$ub9cfc05ca56516ed_0);
do {
v$condition_on_switch$ub9cfc05ca56516ed_0 = v$const_string$us2098c7d17029d8a0;
v$matched_with_one_case$ub9cfc05ca56516ed_0 = false;
{
}
} while(false);
;
That's it, this is basically "Do nothing for Foo::class". No errors, no warnings.
Solution
Require to cover all T in switch OR default branch, fail compilation otherwise (just like in Rust).
- Dominant language
- C++
- Stars
- 1.5k
- Forks
- 116
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 11
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.
More from VKCOM/kphp
-
Difficulty 5/5 Over a week Newbie friendliness 10/100
-
Khan Open
Difficulty 5/5 Over a week Newbie friendliness 10/100
-
.github/CODEOWNERS Open
Difficulty 3/5 1-2 days Newbie friendliness 25/100
-
Difficulty 4/5 3-5 days Newbie friendliness 32/100
-
Difficulty 4/5 3-5 days Newbie friendliness 25/100
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
AXERA-TECH/ax-llm#77 ·
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
games-on-whales/wolf#509 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
bug-unconfirmed
Difficulty 2/5 1-3 hours Newbie friendliness 76/100