Skip to content

Increase span of unreachable code error #25388

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

Merged
4 commits merged into from
Jul 10, 2018
Merged

Increase span of unreachable code error #25388

4 commits merged into from
Jul 10, 2018

Conversation

ghost
Copy link

@ghost ghost commented Jul 3, 2018

Fixes #25384

@ghost ghost force-pushed the unreachableCodeRange branch from 5d67cdc to 01cf8b0 Compare July 3, 2018 15:08
@@ -1211,7 +1211,7 @@ namespace ts {
bind(node.statement);
popActiveLabel();
if (!activeLabel.referenced && !options.allowUnusedLabels) {
errorOrSuggestionOnFirstToken(unusedLabelIsError(options), node, Diagnostics.Unused_label);
errorOrSuggestion(unusedLabelIsError(options), node.label, Diagnostics.Unused_label);
Copy link
Contributor

Choose a reason for hiding this comment

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

this will mark function declarations as well, right?

Copy link
Author

Choose a reason for hiding this comment

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

Right. The quick fix will skip them, but the error message will be a single span rather than several spans separated by functions.

Copy link
Contributor

Choose a reason for hiding this comment

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

do you think it is worth changing it to multiple spans?

Copy link
Author

Choose a reason for hiding this comment

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

I guess this would be ugly for a pattern like:

return { fn1, fn2, fn3, <<etc>> };
doSometing();

function fn1() { ... }
function fn2() { ... }
<<etc>>

that would show hundreds of lines as unreachable when only one line is.

The problem is that our current interface is:

export interface Diagnostic extends DiagnosticRelatedInformation {
    /** May store more in future. For now, this will simply be `true` to indicate when a diagnostic is an unused-identifier diagnostic. */
    reportsUnnecessary?: {};
    source?: string;
    relatedInformation?: DiagnosticRelatedInformation[];
}
export interface DiagnosticRelatedInformation {
    category: DiagnosticCategory;
    code: number;
    file: SourceFile | undefined;
    start: number | undefined;
    length: number | undefined;
    messageText: string | DiagnosticMessageChain;
}
export interface DiagnosticWithLocation extends Diagnostic {
    file: SourceFile;
    start: number;
    length: number;
}

So each additional span would need a new messageText. But it's unreachable for the same reason the first line of code was unreachable, so it doesn't feel right to add an additional span for that.

We could just add a new diagnostic for each group of unreachable statements separated by functions.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking of multiple diagnostics, one for each contiguous span..

@ghost ghost force-pushed the unreachableCodeRange branch from 01cf8b0 to 96db135 Compare July 3, 2018 22:47
@ghost ghost merged commit 1fc1495 into master Jul 10, 2018
@ghost ghost deleted the unreachableCodeRange branch July 10, 2018 18:45
ghost pushed a commit that referenced this pull request Jul 10, 2018
* Increase span of unreachable code error

* Add a new diagnostic for each range of unreachable statements

* Update baselines
This pull request was closed.
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.

1 participant