_This issue was originally filed by qincc...@gmail.com_
What steps will reproduce the problem?
library test;
import 'dart:mirrors';
void main() {
LibraryMirror lm = currentMirrorSystem().findLibrary(const Symbol('test'));
Iterable<ClassMirror> cms = lm.declarations.values.where((d) => d is ClassMirror); // no error
Iterable<MethodMirror> mms = cms.first
.declarations.values
.where((d) => d is MethodMirror); // exception thrown by this line
}
class Foo {
void FooMethod() {}
}
What is the expected output? What do you see instead?
Expected: The program to run to end without exception in checked mode:
Actual: type 'WhereIterable<DeclarationMirror>' is not a subtype of type 'Iterable<MethodMirror>' of 'mms'.
What version of the product are you using? On what operating system?
dart r30104
Please provide any additional information below.
Attachment:
castError.jpg (191.96 KB)
_Added Area-Library, Library-Mirrors, Triaged labels._
I believe this is working as intended. A List<Fruit> is not assignable to a List<Apple>, even if it only contains Apples.
There are several ways to work around this:
I'm closing for now, but Peter can reopen if he thinks that I'm mistaken.
cc @peter-ahe-google.
_Added AsDesigned label._
Thank you for the explanation, Florian. I completely agree with your analysis.
_This comment was originally written by qinc...@gmail.com_
If the error
'WhereIterable<DeclarationMirror>' is not a subtype of type 'Iterable<MethodMirror>
is expected, wouldn't the previous line
Iterable<ClassMirror> cms = lm.declarations.values.where((d) => d is ClassMirror)
also exit with an error? lm.declarations.values.where((d) => d is ClassMirror) returns a 'WhereIterable<DeclarationMirror>'.
Good point. I thought I could cheat and save some type arguments.
_Removed Area-Library label._
_Added Area-Dart2JS, Accepted labels._
_Set owner to @rmacnak-google._
_Removed Area-Dart2JS label._
_Added Area-VM, Started labels._
Most helpful comment
I believe this is working as intended. A List<Fruit> is not assignable to a List<Apple>, even if it only contains Apples.
There are several ways to work around this:
I'm closing for now, but Peter can reopen if he thinks that I'm mistaken.
cc @peter-ahe-google.
_Added AsDesigned label._