-
Notifications
You must be signed in to change notification settings - Fork 43
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
Regression fix: Binds factory method w/ interface #70
Conversation
177eb99
to
d8d96e7
Compare
@@ -81,9 +81,12 @@ class CompilerType( | |||
return type | |||
} | |||
|
|||
val superType = MoreTypes.nonObjectSuperclass(env.typeUtils, env.elementUtils, type).orNull() ?: return null | |||
env.typeUtils.directSupertypes(type).forEach { superType -> | |||
getMatchingSuperType(baseType, superType as DeclaredType)?.let { return it } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this cast fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes for error types but that assumption is made across the codebase. To handle error types correctly a more holistic approach is needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Link a followup issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -81,9 +81,12 @@ class CompilerType( | |||
return type | |||
} | |||
|
|||
val superType = MoreTypes.nonObjectSuperclass(env.typeUtils, env.elementUtils, type).orNull() ?: return null | |||
env.typeUtils.directSupertypes(type).forEach { superType -> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be simplified and made safer to
return env.typeUtils.directSupertypes(type)
.asSequence()
.filterInstance<DeclaredType>()
.mapNotNull { getMatchingType(baseType, it) }
.firstOrNull()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also - is this necessary? On mobile but there is definitely some API on Types like isAssignable(Type from, Type to)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We actually don't want to filter out DeclaredTypes here. We should fail fast instead, so going to keep the cast until we have a holistic error type strategy. Will make the sequence change though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could move that cast into the mapNotNull body then and remove the filter
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
@@ -0,0 +1,26 @@ | |||
/* | |||
* Copyright (c) 2018 Uber Technologies, Inc. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2019 here and elsewhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do this in a follow up
d8d96e7
to
8717d92
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely think there should be a wildcard test/coverage if you want this to play nice with Kotlin, which contains wildcards by default in bytecode
*/ | ||
package testcases.T052_binds_interface_generic; | ||
|
||
public class A<T> implements B<T> {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens with wildcards?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will add tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wildcards aren't valid here - what do you mean?
8717d92
to
cb1df1f
Compare
I assume you mean bounded type parameters right? |
cb1df1f
to
9d5805a
Compare
Updated with tests for bounded type parameters and wildcard return types / parameter types. |
9d5805a
to
368e27a
Compare
Support for binding to interface types with binds factory methods.