-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Wrong inferred argument bounds violation #35518
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
The weirdness goes on. The function // works
@override
KList<T> filterIndexed(bool Function(int index, T) predicate) {
final list = filterIndexedTo(mutableListOf<T>(), predicate);
return list;
} One might assume this method could be simlified, but there comes the weirdness: // throws
@override
KList<T> filterIndexed(bool Function(int index, T) predicate) {
return filterIndexedTo(mutableListOf<T>(), predicate);
} Instantly returning
|
Bug dart-lang/sdk#35518 prevents calls from external classes to those methods to not pass the generic bound type correctly resulting in a wrong inferred argument bounds violation
Although this error exists, I made progress by using final KIterable<int> iterable = listOf([4, 25, -12, 10]);
final result = mutableListOf<num>(); // contravariant!
final filtered = iterable.filterIndexedTo(result, (i, it) => it < 10);
expect(identical(result, filtered), isTrue);
expect(result, listOf([4, -12]));
C filterIndexedTo<C extends KMutableCollection<dynamic>>(
C destination, bool Function(int index, T) predicate) {
assert(() {
if (destination == null) throw ArgumentError("destination can't be null");
if (predicate == null) throw ArgumentError("predicate can't be null");
if (mutableListOf<T>() is! C)
throw ArgumentError(
"filterIndexedTo destination has wrong type parameters."
"\nExpected: KMutableCollection<$T>, Actual: ${destination.runtimeType}"
"\ndestination (${destination.runtimeType}) entries aren't subtype of "
"map ($runtimeType) entries. Entries can't be copied to destination."
"\n\n$kBug35518GenericTypeError");
return true;
}());
// impl ...
} Kotlin uses the |
Most likely related to #35068 |
@leafpetersen @lrhn @eernstg - can one of you take a look? Is this a CFE bug or working as intended? |
This looks like a CFE bug to me. Minimal repro which (correctly) passes the analyzer but fails with a static error in the CFE enclosed below. I think this is related to mixins, since hand inlining cc @kmillikin abstract class KMutableCollection<T> {}
abstract class KIterableExtensionMixin<T> {
C toCollection<C extends KMutableCollection<T>>(C destination) => null;
}
class DartMutableList<T>
with KIterableExtensionMixin<T> implements KMutableCollection<T> {}
void main() {
var other = DartMutableList<String>();
var list = DartMutableList<String>();
// Error in CFE both when explicitly and implicitly instantiated
final r1 = list.toCollection<DartMutableList<String>>(other);
final r2 = list.toCollection(other);
} |
Does still exist with dart 2.12.2. Here the nullsafe example abstract class KMutableCollection<T> {}
mixin KIterableExtensionMixin<T> {
C toCollection<C extends KMutableCollection<T>>(C destination) {
return destination;
}
}
class DartMutableList<T>
with KIterableExtensionMixin<T> implements KMutableCollection<T> {}
void main() {
var other = DartMutableList<String>();
var list = DartMutableList<String>();
// Error in CFE both when explicitly and implicitly instantiated
final r1 = list.toCollection<DartMutableList<String>>(other);
final r2 = list.toCollection(other);
} Error
|
This appears to be fixed now. Please reopen if needed. |
Confirmed, this bug is fixed in |
I run into a generic bounds bug. I tried to create a minimal sample but wasn't able to. It seems it has to do with the number of levels of inheritance. That's why I stripped all irrelevant code from my project and pushed it. Minimal sample project
Here's a gist of what I'm doing:
I don't get what's the violation here.
Also the
kollection
package contains similar methods, which have similar errors. i.e.filterIndexedTo
Which errors with:
Signature:
Here' a workaroud I found:
It seems like the type
T
of the owning class doesn't get passed into theextends Something<T>
part leaving the type asextends Something<dynamic>
.Dart VM version: 2.1.0 (Tue Nov 13 18:22:02 2018 +0100) on "macos_x64"
The text was updated successfully, but these errors were encountered: