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
unexpected dart2js error with external element #28371
Comments
@a14n - I wonder if there is a missing The difference with or without angular could be related to whether or not _LatLngBounds is consider to be instantiated by dart2js. In the simple example dart2js can tell that you only see the type, but that you never call it's constructor, so we don't complain. Is angular2 in this mode also using mirrors or some other feature that will lead dart2js to think that this class is intantiated? Do you see the same error if you try to call |
The problem here is similar to a more complex case with my google_maps package. dart-google-maps uses those kinds of abstract classes as template to generate classes (eg. _LatLng is used to generate LatLng). Those classes are actually never used (like in the above example) and not instantiated. However I have a more complex project with the same version of google_maps and angular2 that does not lead to this error. So it is really strange and hard to understand. |
BTW I face the same issue with |
mmm.. not sure what's going on yet. My guess is that something is making dart2js believe that this constructor could be instantiated - is dart:mirrors used in this configuration? Does the problem go a way when you run the ng2 transformers to get rid of dart:mirrors? |
With the single import 'package:angular2/core.dart';
import 'package:angular2/platform/browser.dart';
abstract class _LatLngBounds {
external factory _LatLngBounds();
}
@Component(
selector: 'main-app',
template: 'foo'
)
class MainApp {}
main() => bootstrap(MainApp); and name: angular_maps
dependencies:
angular2: ^2.2.0
transformers:
- angular2:
platform_directives:
- 'package:angular2/common.dart#COMMON_DIRECTIVES'
platform_pipes:
- 'package:angular2/common.dart#COMMON_PIPES'
entry_points: web/index.dart then If I remove the transformer section to have a name: angular_maps
dependencies:
angular2: ^2.2.0 then
Now it becomes even funnier! If I split // web/index.dart
import 'package:angular_maps/file.dart' as app;
main() => app.main();
// lib/part.dart
import 'package:angular2/core.dart';
import 'package:angular2/platform/browser.dart';
abstract class _LatLngBounds {
external factory _LatLngBounds();
}
@Component(
selector: 'main-app',
template: 'foo'
)
class MainApp {}
main() => bootstrap(MainApp); then |
I forgot to mention that in the cases where |
That makes sense - the angular2 transformer removes the use of dart:mirrors (typically needed for di purposes). Practically speaking, your code above is equivalent to something like this: import 'dart:mirrors';
abstract class _A {
external factory _A();
}
class _B {}
main() {
reflectClass(_B).newInstance(const Symbol(''), []);
} When dart2js sees the use of reflection, it becomes very conservative and assumes anything can be reflected and instantiated. This example is a bit silly because you can clearly tell that It seems to me that the fix for this needs to be either on the angular side or in the dart-google-maps package (or the generator in js_wrapping). In particular, the use of It seems to me that you are using this external method just to seed a code generator, but you never expect to call I can think of 2 options to fix the issue:
My personal preference would be to fix I'll close this bug shortly since I believe there is no action item on the dart2js side of things, but feel free to reopen if I misunderstood the problem. Cheers! |
Thanks a lot for your help. I will try to find a workaround with your explanations in mind. |
First try, bad try! I crashed the compiler :D I resurrected an old pattern I used some times ago ( import 'package:angular2/core.dart';
import 'package:angular2/platform/browser.dart';
abstract class _LatLngBounds {
factory _LatLngBounds() = dynamic;
get a;
}
@Component(
selector: 'main-app',
template: 'foo'
)
class MainApp {}
main() => bootstrap(MainApp); with the error :
|
oh my - I'll open a separate bug for that.
|
|
|
Filed at #28392 Note that |
Good to know. Thanks for the advice! |
Oops, pattern
Let's go with |
Just a FYI, I was having the exact same issue as described here, but I was able to solve it as following: My dart library which declared the interop classes was importing My annotations would accordingly look like When I then ran build, I got the same error messages, after some efforts I've simply removed the alias and instead just used Now the errors are gone (this is with SDK 1.23.0 and Angular 2.0) |
I face an issue with
angular-2.2.0
andsdk-1.20.1
by runningdart2js web/index.dart
with :The error is :
This error doesn't appear without
angular2
if theindex.dart
content is only :The text was updated successfully, but these errors were encountered: