Skip to content

fixUnusedIdentifier: Don't remove parameter in override or non-last parameter in callback #24306

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
3 commits merged into from
May 29, 2018

Conversation

ghost
Copy link

@ghost ghost commented May 21, 2018

Fixes #24303

@ghost ghost force-pushed the codeFixUnusedIdentifier_parameterInOverride branch from 4aadf21 to d6f95e2 Compare May 21, 2018 22:35
// Can't remove a non-last parameter in a callback. (Can if future parameters are also unused.)
const index = parent.parameters.indexOf(p);
Debug.assert(index !== -1);
return parent.parameters.slice(index).every(p => p.name.kind === SyntaxKind.Identifier && !p.symbol.isReferenced) || !checker.getContextualType(parent);
Copy link
Contributor

Choose a reason for hiding this comment

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

even if you did not have a contextual type, the function may be called or assigned to something else that passes or expects different parameters.

Copy link
Author

@ghost ghost May 21, 2018

Choose a reason for hiding this comment

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

That's true, though it would mean we could never remove any parameters. Maybe we should play it safe in code-fix-all but still provide the option to delete as a single fix?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is always safe to remove from the end, contextual type or not.

We should think about updating call sites to remove the unused arguments as well.. but that is a different change..

Copy link
Author

Choose a reason for hiding this comment

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

So never remove a non-last parameter? A method in a class may also be expected to conform to some interface that wasn't declared.

Copy link
Contributor

Choose a reason for hiding this comment

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

a method with fewer required arguments is assignable to one with more. so that should work. but yes, it could result in errors.. really any change to the signature can result in errors.. so we can either be conservative and say we only do it if we know all references, and know it was never aliased, or we can be more open and say, as long as the error will be caught by type check, we should be fine..

@ghost ghost force-pushed the codeFixUnusedIdentifier_parameterInOverride branch from 9e5e161 to 9bf1690 Compare May 29, 2018 18:08
@ghost ghost merged commit 160b667 into master May 29, 2018
@ghost ghost deleted the codeFixUnusedIdentifier_parameterInOverride branch May 29, 2018 19:39
@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant