Sdk: type 'WhereIterable<DeclarationMirror>' is not a subtype of type 'Iterable<MethodMirror>'

Created on 9 Nov 2013  路  7Comments  路  Source: dart-lang/sdk

_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)

area-vm library-mirrors

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:

  • iterable.map((x) => x) (removing the generic type),
  • new List<MethodMirror>.from(iterable)
  • new MyIterableWrapper<MethodMirror>(iterable) (where the iterable-wrapper that would need to be written).

I'm closing for now, but Peter can reopen if he thinks that I'm mistaken.


cc @peter-ahe-google.
_Added AsDesigned label._

All 7 comments

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:

  • iterable.map((x) => x) (removing the generic type),
  • new List<MethodMirror>.from(iterable)
  • new MyIterableWrapper<MethodMirror>(iterable) (where the iterable-wrapper that would need to be written).

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._

Fixed in r32225.


_Added Fixed label._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ranquild picture ranquild  路  3Comments

matanlurey picture matanlurey  路  3Comments

matanlurey picture matanlurey  路  3Comments

DartBot picture DartBot  路  3Comments

jmesserly picture jmesserly  路  3Comments