Dart Mirrors in JS: type '_ListConstructorSentinel' is not a subtype of type 'int'

Issue

The following code executes fine on the VM, but fails with

“‘_ListConstructorSentinel’ is not a subtype of type ‘int'”

when converted to javascript via Dart2JS. I’m using “pub run test -p chrome ” to run the code.

import "dart:mirrors";

main() {
  TypeMirror tm = new TypeToken<List<String>>().typeMirror;
  (tm as ClassMirror).newInstance(const Symbol(""), []);
}

class TypeToken<T> {
  TypeMirror get typeMirror => reflectType(T);
}

StackTrace:

type '_ListConstructorSentinel' is not a subtype of type 'int'
  error.dart.browser_test.dart.js 4385:15    dart.wrapException
  error.dart.browser_test.dart.js 4604:13    dart.intTypeCheck
  error.dart.browser_test.dart.js 36709:11   Isolate.dart.List.static.List_List.H.computeSignature.func
  error.dart.browser_test.dart.js 13292:31   JsMethodMirror.dart.JsMethodMirror._invoke$2
  error.dart.browser_test.dart.js 12724:21   JsClassMirror.dart.JsClassMirror._getInvokedInstance$3
  error.dart.browser_test.dart.js 12054:30   JsTypeBoundClassMirror.<fn>
  error.dart.browser_test.dart.js 12058:19   JsTypeBoundClassMirror.dart.JsTypeBoundClassMirror.newInstance$3
  error.dart.browser_test.dart.js 85680:232  dart.main0
  error.dart.browser_test.dart.js 15329:32   dart.Future.static.Future_Future$sync.H.computeSignature.func
  error.dart.browser_test.dart.js 97668:16   IframeListener_start_closure.dart.IframeListener_start_closure.call$0

Am I doing something that shouldn’t be allowed, or is this a bug? If it’s a bug, is there any way to work around it?

Thanks in advance!

Solution

Looks like this is a known issue: github.com/dart-lang/sdk/issues/21927

Answered By – Jim Simon

Answer Checked By – Willingham (FlutterFixes Volunteer)

Leave a Reply

Your email address will not be published.