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

Related error spans on "used before declared" error messages #25359

Merged
merged 3 commits into from
Jul 2, 2018

Conversation

DanielRosenwasser
Copy link
Member

Fixes #25003.

@mhegazy
Copy link
Contributor

mhegazy commented Jul 2, 2018

@weswigham added the harness support for related spans in #25328. you will need to merge from master.

@@ -1592,18 +1592,34 @@ namespace ts {
if (declaration === undefined) return Debug.fail("Declaration to checkResolvedBlockScopedVariable is undefined");

if (!(declaration.flags & NodeFlags.Ambient) && !isBlockScopedNameDeclaredBeforeUse(declaration, errorLocation)) {
let err;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit. i would call this variable diagnosticMessage.

}
}
}

function placeRelatedSpanOnLaterDeclaration(declarationName: string, declarationLocation: Declaration, diagnostic: Diagnostic) {
Copy link
Contributor

Choose a reason for hiding this comment

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

consider inlining this function, it is simple enough that it does not benefit from the indirection.

@weswigham
Copy link
Member

@DanielRosenwasser I think we could have a second message if the declaration is in a separate file (as I believe can happen for scripts), like 'v' was declared here, and this file is ordered before the above usage. If you believe the usage is correct, reorder the files using triple-slash references or in your compiler options using the "files" option to make this file come first.

@DanielRosenwasser
Copy link
Member Author

@weswigham maybe; I'd rather get this in first, especially since modules are going to be the more common scenario.

@weswigham
Copy link
Member

weswigham commented Jul 2, 2018

Ah, @DanielRosenwasser while you're undoing your harness changes, I should probably also mention that there's an addRelatedInfo helper in the checker now, which should make where you add the related information cleaner, too.

diagnostic.relatedInformation = diagnostic.relatedInformation || [];
diagnostic.relatedInformation.push(createDiagnosticForNode(importNode, Diagnostics.Type_originates_at_this_import_A_namespace_style_import_cannot_be_called_or_constructed_and_will_cause_a_failure_at_runtime_Consider_using_a_default_import_or_import_require_here_instead));
Debug.assert(!diagnostic.relatedInformation);
diagnostic.relatedInformation = [createDiagnosticForNode(importNode, Diagnostics.Type_originates_at_this_import_A_namespace_style_import_cannot_be_called_or_constructed_and_will_cause_a_failure_at_runtime_Consider_using_a_default_import_or_import_require_here_instead)];
Copy link
Member

@weswigham weswigham Jul 2, 2018

Choose a reason for hiding this comment

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

If we're going to update this, we should probably just update it to use addRelatedInfo. This can actually potentially stack with the related info provided by #25140, after all, since they're for the same (assignability) diagnostics.

@DanielRosenwasser DanielRosenwasser merged commit f7dfc7f into master Jul 2, 2018
@DanielRosenwasser DanielRosenwasser deleted the useBeforeDeclareRelatedSpans branch July 2, 2018 19:48
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