-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Detect empty loop #1825
Comments
That compiles to an infinite loop: - var n = 0
ul
while n < 20
= n++ is approximately like writing: buf.push('<ul>');
while (n < 20) {
}
buf.push(n++);
buf.push('</ul>'); You need to indent the code within the - var n = 0
ul
while n < 20
= n++ This error is unfortunately impossible to statically detect in the most general case (it requires solving the halting problem). We could, however, do one of two things that would perhaps produce useful results:
The first might be possible to make a non-breaking change, but it is very limited. The second option is a definite breaking change, and it makes for very slow feedback. |
Owwww Is this an old known issue? Hummmm.. I don't think that any of given solutions would be the best choice because we don't know how long the Jade will take to complete the compile process. Is there not any regular expression could catch this case? |
This isn't an issue, the code is just misindented. |
@marcelaraujo This is a known issue with all turing complete languages. Look up "The Halting Problem". It is one of the most famous computer science problems there is. It cannot be caught with a regular expression. It would of course be possible to catch the specific case you illustrated (as I suggested in option 1) but it is not possible in the most general case. Consider the following example JavaScript program: function foo() {
return true;
}
var i = 0;
while (i % 2 === 0) {
i++;
if (foo()) i++;
} As a human I can prove that that program never terminates. It gets stuck in an infinite loop. The only way to know that for a computer though, is to execute the program. We may sometimes be able to do clever tricks to spot cases where it will never finish, but it is not possible in all cases. |
We can apply https://github.com/ForbesLindesay/halting-problem to loops, which will catch a lot of the most common of these cases. |
Hey, I found this bug when I have this template
FATAL ERROR: JS Allocation failed - process out of memory
https://gist.github.com/marcelaraujo/e4b35cb90a15699a5f8a
The text was updated successfully, but these errors were encountered: