Skip to content
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

Bug: Incorrect type error, dead code marked as missing return statement #2

Closed
kevinvandervlist opened this issue Apr 7, 2020 · 3 comments

Comments

@kevinvandervlist
Copy link

If the code below is type checked, the function dead is marked with a Missing return statement error. This is incorrect and should be the dead code warning/error for the println statement.

I've executed this with rascal version 0.18.0.202004041615

module DeadCode

import IO;

int dead() {
    while(true) {
        return 0;    
    };
    println("This is dead code");
}
@PaulKlint
Copy link
Member

Hi @kevinvandervlist thanks for the report. You are right that it would be desirable to mark the println statement as dead code. But can it be done by the type checker? It all depends on the analysis of the condition of the while statement. Here it is trivial and this exceptional case could be added. In general, the type checker cannot decide whether the condition will be true or false without executing it. I will think about it what it requires to add such special casing.

BTW, we would prefer to have these and similar issues in the Rascal repo and reserve the issues here for TypePal specific issues.

@kevinvandervlist
Copy link
Author

kevinvandervlist commented Apr 7, 2020

Okay, thanks, will keep using rascal repo from now on.

I agree obviously, and it's not feasible it is to always do this, especially in general.

However, the current approach of marking this as Missing return code, especially as an error, also seems to far off the actual situation. This reduces the value quite a bit I'd say.

It's obviously up to you, but a simple heuristic like 'there is a return statement within the while, so we might exit, therefore we mark this as a warning' seems to be much more helpful compared to the current error.

@PaulKlint
Copy link
Member

I have made a minimal fix for this specific case: usethesource/rascal-core@fff79a8
Maybe later more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants