-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Disabling unreachable code detection partially for the condition completeness check #5978
Comments
Is there any precedent for this? It seems odd. If you want a workaround, you can put the |
also you can just use |
I cannot find a precedent now. But developers sometimes forget the other case: function f(n) {
if (n >= 0) {
return n;
}
else if (n < 0) {
return n;
}
else { // don't forget
return 0;
}
// call if you forget the else clause
throw new Error();
} @mhegazy I want to disable partially. |
I think this would be better served by a lint tool, but others can weigh in on this. |
I agree with @DanielRosenwasser |
Additionally, a reachability check cannot detect that fault case because an incomplete condition reach the tail statement. @DanielRosenwasser But an lint tool cannot allow that code in compilation. Reachability check disallow that prevention code completely? |
I find the entire construct here very confusing. You want to make sure that you don't have any unreachable code... so you add a line of unreachable code? Many coding styles (e.g. ours) say that if you unconditionally It seems like what you're trying to enforce is " |
I add oneself a reachability check code instead of reachability check by compiler. This is my use case using a DbC(Design by Contract) like coding style. Is this not good?
https://github.com/falsandtru/arch-stream/blob/v0.0.36/src/lib/message.ts#L126 Assertions will remove by unassert: https://github.com/twada/unassert |
I guess my question is: in what situation do you expect this assert to be raised? If compiler can statically prove that this code is unreachable (using a very conservative set of checks) then what is the point of putting the bit of code that will never be triggered. The only situation I can imagine when it might be useful is if you want to make your code more resilient to occasional modifications, i.e. if somebody removes a |
It is right. I feel calm writing that clearly contracted code. I am already using a |
can you please elaborate: did you step on any issue related to reachability checks or you just suspect that they might exists? |
I did not step on any issue because my tail assertion work effectively. I explain the background: That my switch statement simulate the overloaded function for pattern matching like a Haskell. Haskell check the typings and the condition completeness. My tail assertion is embedding for the checking of the condition completeness. In short, must I remove the prevention code immediately to use that new features? |
why won't we ask for exhaustive switch and if/then/else that eliminates a possibility of forgotten cases and elses instead? |
expected: function f(n) {
switch (n) {
case 0:
return 0;
default:
if (n > 0) {
return n;
}
else {
return -n;
}
}
// assert(false) or throw error
function g() {
}
// many functions...
function z() {
}
} actual: function f(n) {
switch (n) {
case 0:
return 0;
default:
if (n > 0) {
return n;
}
// forgotten else...
}
// assert(false) or throw error
function g() {
}
// many functions...
function z() {
}
return n; // bad hidden code
} This is a weak point of
|
Please review this point, @vladima @RyanCavanaugh @mhegazy @DanielRosenwasser . I think, unreachable code detection should be an optional feature because unreachable code detection cannot to be the perfect in JavaScript. JavaScript cannot segregate the main statement block(for detect the tail statement of main flow in function) and the declaration block like a |
Improve to #6009 |
I want to disable the unreachable code detection for the condition completeness check.
The text was updated successfully, but these errors were encountered: