Skip to content

tune "convert to set literal" assist to avoid producing code w/ type errors #35907

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

Closed
pq opened this issue Feb 11, 2019 · 3 comments
Closed

tune "convert to set literal" assist to avoid producing code w/ type errors #35907

pq opened this issue Feb 11, 2019 · 3 comments
Labels
devexp-quick-fix Issues with analysis server (quick) fixes legacy-area-analyzer Use area-devexp instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@pq
Copy link
Member

pq commented Feb 11, 2019

In the world of set-literals, an assist is presented on this snippet.

Set<String> s = new HashSet<String>();

If you perform it, and get:

Set<String> s = <String>{};

which provokes the following error:

error: The set literal type 'Set<String>' isn't of expected type 'HashSet<String>'. The set's type can be changed with an explicit generic type argument or by changing the element types. (strong_mode_invalid_cast_literal_set at ...)

As discussed in #57905, we should consider not providing the assist if it would produce errored results.

/cc @bwilkerson

@pq pq added legacy-area-analyzer Use area-devexp instead. devexp-quick-fix Issues with analysis server (quick) fixes type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Feb 11, 2019
@leafpetersen
Copy link
Member

I don't think that's the example you mean - that fix should not cause an error. Perhaps you mean that the original code was:

 HashSet<String> s = new HashSet<String>();

?

@bwilkerson
Copy link
Member

I just confirmed that Set<String> s = <String>{}; does not produce any error, while HashSet<String> s = <String>{}; does produce an error.

However, as far as I can tell, the assist is only offered if the explicitly created type is Set, not when it is either HashSet or LinkedHashSet.

@pq
Copy link
Member Author

pq commented Feb 11, 2019

@leafpetersen: you're spot on. Sorry for the confusion. I've been juggling a lot of cases and got this one mixed up.

However, as far as I can tell, the assist is only offered if the explicitly created type is Set, not when it is either HashSet or LinkedHashSet.

And it looks doubly so. You're right @bwilkerson. The assist does the right thing.

Closing this out. Feel free to re-open if there's anything of value here.

Thanks!

@pq pq closed this as completed Feb 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devexp-quick-fix Issues with analysis server (quick) fixes legacy-area-analyzer Use area-devexp instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

3 participants