-
Notifications
You must be signed in to change notification settings - Fork 12.8k
"implicit any" where circularity is trivially resolvable #49837
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
Comments
Your playground link does not work. Here's a working one: Playground link Constructor argument of You can add an explicit return type annotation to your method, that will solve your issue.
Because that doesn't solve the issue: What type is |
My point is that the compiler does not need to know if the |
That would require the compiler to perform type checks in two iterations (first inference, then the rest), which it currently not does. The issue exists for a long time already, and Ryan mentions the issue in this comment. The best approach is really to just add a type annotation. |
Alright, close as wontfix then I guess? Or is it possible that this could be implemented at some point in the future? Is there an open issue that tracks this? |
If someone can make this work without making a bunch of other stuff (perf, maintainability, etc) worse they're free to send a PR, but we don't think that's possible. |
This issue has been marked as 'Not a Defect' and has seen no recent activity. It has been automatically closed for house-keeping purposes. |
Bug Report
π Search Terms
π Version & Regression Information
β― Playground Link
Playground link with relevant code
π» Code
π Actual behavior
The type of the variable
result
, and thus the return type ofFooFactory.getFoo
,defaults to
any
. This is wrong, becauseresult
clearly has the typeFoo
regardless of the type of the argument to the
Foo
constructor.Adding
implements FooProvider
toFooFactory
does not help, which I alsofind a bit strange.
π Expected behavior
The circularity should be resolved at the
new Foo(this)
expression, sincecalling this non-generic constructor can only result in one possible type,
regardless of arguments.
The text was updated successfully, but these errors were encountered: