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

Report unreachable code warnings for if- and while-statements. #140

Merged
merged 1 commit into from
May 22, 2020
Merged

Report unreachable code warnings for if- and while-statements. #140

merged 1 commit into from
May 22, 2020

Conversation

Catalin-Andronie
Copy link
Contributor

@Catalin-Andronie Catalin-Andronie commented May 13, 2020

Issue: #136
Code review video: Episode 26

The IsError & IsWarning flags were added in the Diagnostic class to differentiate between warning and error diagnostics . Also the construction of a Diagnostic is now possible just via the Error and Warning static methods. Warnings are displayed in DarkYellow color.

  • Block statements report unreachable code warning on the first statement span.
  • No diagnostics are reported for empty block statements.
  • Call expressions report warning on function name span (same on C#).

Warnings are reported for scenarios like:

    // Scenario 1
    if false
        continue // Report on [continue] span.

    // Scenario 2
    if false
        return
    else
        return // Report on [return] span.

    // Scenario 3
    while false
        print("") // Report on [print] span.

Until now I did NOT find a way to handle scenarios like:

    function test(): int
    {
        while true
        {
            return -1
        }

        // How to report warning here?
        // Can we use `ControlFlowGraph` when binding block statements??
        return 0
    }

Mate, you have amazing teaching skills 😄.
Your videos are better than Netflix. 👍

Copy link
Contributor

@ltrzesniewski ltrzesniewski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just wanted to point out a conflict with #132 due to a whitespace change. It's better to avoid formatting changes unrelated to the PR. 😉

Also, this should not conflict with #133, but it will need some adjustment to only bail out on errors. It will still work correctly after merging, but only because the lexer and parser never emit warnings.

src/Minsk/CodeAnalysis/Emit/Emitter.cs Outdated Show resolved Hide resolved
@Catalin-Andronie Catalin-Andronie changed the title Generate unreachable code warnings for if- and while-statements. Report unreachable code warnings for if- and while-statements. May 13, 2020
@terrajobst terrajobst merged commit 7223f82 into terrajobst:master May 22, 2020
@Catalin-Andronie Catalin-Andronie deleted the warning-for-dead-code branch May 22, 2020 16:17
@Catalin-Andronie Catalin-Andronie restored the warning-for-dead-code branch May 22, 2020 16:17
@Catalin-Andronie Catalin-Andronie deleted the warning-for-dead-code branch May 22, 2020 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants