Skip to content
This repository has been archived by the owner on Dec 19, 2017. It is now read-only.

Problems using generics in mixin with reflectable 0.4.0 #653

Closed
dam0vm3nt opened this issue Dec 2, 2015 · 7 comments
Closed

Problems using generics in mixin with reflectable 0.4.0 #653

dam0vm3nt opened this issue Dec 2, 2015 · 7 comments

Comments

@dam0vm3nt
Copy link
Contributor

This is a prosecution of #651 . Using generics on mixin makes reflectable mess the generated wrapper code.

For example with:

@behavior
class FantasticMixin<X> {
 @property X field;
}

@PolymerRegister("example-list")
class ExampleList extends PolymerElement with FantasticMixin<String> {
  @property List<String> values = [
        "uno",
        "due",
        "tre"
        ];
  ExampleList.created() : super.created();
}

building you get :

web/index.dart:34:7:
A final variable must be initialized.
Try adding an initializer or removing the 'final' modifier.

but the real problem is that the generated code will contains something that is messed up:

final _data = {
  const prefix0.JsProxyReflectable(): new r.ReflectorData(
        <m.TypeMirror>[
        new r.GenericClassMirrorImpl(r"FantasticMixin", r".FantasticMixin", 7, 0, const prefix0.JsProxyReflectable(), const <int>[0], const <int>[2, 3], const <int>[], 14, {}, {}, {}, -1, 0, const <int>[], const <Object>[prefix7.behavior], (o) { return o is prefix1.FantasticMixin && o is! prefix1.polymer.lib.polymer_micro.PolymerElement with .FantasticMixin; }, const <int>[15], 0),
        new r.NonGenericClassMirrorImpl(r"JsProxy", r"polymer.lib.src.common.js_proxy.JsProxy", 519, 1, const prefix0.JsProxyReflectable(), const <int>[], const <int>[], const <int>[], 14, {}, {}, const {}, -1, 1, const <int>[], const <Object>[prefix0.jsProxyReflectable]),
        new r.NonGenericClassMirrorImpl(r"PolymerMixin", r"polymer.src.common.polymer_js_proxy.PolymerMixin", 519, 2, const prefix0.JsProxyReflectable(), const <int>[], const <int>[], const <int>[], 14, {}, {}, const {}, -1, 2, const <int>[], const <Object>[prefix0.jsProxyReflectable]),
        new r.NonGenericClassMirrorImpl(r"polymer.lib.polymer_micro.PolymerElement with .FantasticMixin", r".polymer.lib.polymer_micro.PolymerElement with .FantasticMixin", 583, 3, const prefix0.JsProxyReflectable(), const <int>[0], const <int>[4, 5, 6, 7, 2, 3], const <int>[], 8, const {}, const {}, const {}, -1, 0, const <int>[], const []),
        new r.NonGenericClassMirrorImpl(r"dart.dom.html.HtmlElement with polymer.src.common.polymer_js_proxy.PolymerMixin", r"polymer.lib.polymer_micro.dart.dom.html.HtmlElement with polymer.src.common.polymer_js_proxy.PolymerMixin", 583, 4, const prefix0.JsProxyReflectable(), const <int>[], const <int>[4, 5, 6], const <int>[], -1, const {}, const {}, const {}, -1, 2, const <int>[], const []),
        new r.NonGenericClassMirrorImpl(r"PolymerSerialize", r"polymer.src.common.polymer_serialize.PolymerSerialize", 519, 5, const prefix0.JsProxyReflectable(), const <int>[8, 9], const <int>[8, 9], const <int>[], 14, {}, {}, const {}, -1, 5, const <int>[2], const <Object>[]),
        new r.NonGenericClassMirrorImpl(r"ExampleList", r".ExampleList", 7, 6, const prefix0.JsProxyReflectable(), const <int>[1], const <int>[4, 5, 6, 7, 2, 3, 10, 11], const <int>[], 3, {}, {}, {}, -1, 6, const <int>[], const <Object>[const prefix8.PolymerRegister("example-list")]),
        new r.NonGenericClassMirrorImpl(r"dart.dom.html.HtmlElement with polymer.src.common.polymer_js_proxy.PolymerMixin, polymer_interop.src.js_element_proxy.PolymerBase", r"polymer.lib.polymer_micro.dart.dom.html.HtmlElement with polymer.src.common.polymer_js_proxy.PolymerMixin, polymer_interop.src.js_element_proxy.PolymerBase", 583, 7, const prefix0.JsProxyReflectable(), const <int>[7], const <int>[4, 5, 6, 7], const <int>[], 4, const {}, const {}, const {}, -1, 9, const <int>[], const []),
        new r.NonGenericClassMirrorImpl(r"PolymerElement", r"polymer.lib.polymer_micro.PolymerElement", 7, 8, const prefix0.JsProxyReflectable(), const <int>[], const <int>[4, 5, 6, 7], const <int>[], 7, {}, {}, {}, -1, 8, const <int>[], const <Object>[]),
        new r.NonGenericClassMirrorImpl(r"PolymerBase", r"polymer_interop.src.js_element_proxy.PolymerBase", 519, 9, const prefix0.JsProxyReflectable(), const <int>[7], const <int>[7], const <int>[], 14, {}, {}, const {}, -1, 9, const <int>[], const <Object>[]),
        new r.NonGenericClassMirrorImpl(r"String", r"dart.core.String", 519, 10, const prefix0.JsProxyReflectable(), const <int>[], const <int>[], const <int>[], 14, {}, {}, const {}, -1, 10, const <int>[], const <Object>[]),
        new r.NonGenericClassMirrorImpl(r"Type", r"dart.core.Type", 519, 11, const prefix0.JsProxyReflectable(), const <int>[], const <int>[], const <int>[], 14, {}, {}, const {}, -1, 11, const <int>[], const <Object>[]),
        new r.GenericClassMirrorImpl(r"List", r"dart.core.List", 519, 12, const prefix0.JsProxyReflectable(), const <int>[], const <int>[], const <int>[], 14, {}, {}, const {}, -1, 12, const <int>[], const <Object>[], (o) { return o is List && o is! prefix6.DomStringList && o is! prefix6.FileList && o is! prefix6.HtmlCollection && o is! prefix6.MimeTypeArray && o is! prefix6.NodeList && o is! prefix6.PluginArray && o is! prefix6.SourceBufferList && o is! prefix6.SpeechGrammarList && o is! prefix6.TextTrackCueList && o is! prefix6.TextTrackList && o is! prefix6.TouchList && o is! prefix6.ImmutableListMixin && o is! prefix9.ListMixin && o is! prefix9.UnmodifiableListView && o is! prefix10.Int8List && o is! prefix10.Uint8List && o is! prefix10.Uint8ClampedList && o is! prefix10.Int16List && o is! prefix10.Uint16List && o is! prefix10.Int32List && o is! prefix10.Uint32List && o is! prefix10.Int64List && o is! prefix10.Uint64List && o is! prefix10.Float32List && o is! prefix10.Float64List && o is! prefix10.Float32x4List && o is! prefix10.Int32x4List && o is! prefix10.Float64x2List && o is! prefix11.SqlResultSetRowList && o is! prefix12.LengthList && o is! prefix12.NumberList && o is! prefix12.PathSegList && o is! prefix12.StringList && o is! prefix12.TransformList; }, const <int>[16], 12),
        new r.NonGenericClassMirrorImpl(r"Element", r"dart.dom.html.Element", 7, 13, const prefix0.JsProxyReflectable(), const <int>[4, 5, 6], const <int>[4, 5, 6], const <int>[], -1, {}, {}, {}, -1, 13, const <int>[], const <Object>[]),
        new r.NonGenericClassMirrorImpl(r"Object", r"dart.core.Object", 7, 14, const prefix0.JsProxyReflectable(), const <int>[], const <int>[], const <int>[], null, {}, {}, {}, -1, 14, const <int>[], const <Object>[]),
        new r.TypeVariableMirrorImpl(r"X", r".FantasticMixin.X", const prefix0.JsProxyReflectable(), 14, 0, <Object>[]),
        new r.TypeVariableMirrorImpl(r"E", r"dart.core.List.E", const prefix0.JsProxyReflectable(), 14, 12, <Object>[])], <m.DeclarationMirror>[
          new r.VariableMirrorImpl(r"field", 5, 0, const prefix0.JsProxyReflectable(), -1, -1, -1, const <Object>[prefix13.property]),
          new r.VariableMirrorImpl(r"values", 2129925, 6, const prefix0.JsProxyReflectable(), 12, -1, -1, const <Object>[prefix13.property]),
          new r.ImplicitGetterMirrorImpl(const prefix0.JsProxyReflectable(), 0, -1, -1, 2),
          new r.ImplicitSetterMirrorImpl(const prefix0.JsProxyReflectable(), 0, -1, -1, 3),
          new r.MethodMirrorImpl(r"attached", 262146, 13, null, -1, -1, const <int>[], const prefix0.JsProxyReflectable(), const <Object>[]),
          new r.MethodMirrorImpl(r"detached", 262146, 13, null, -1, -1, const <int>[], const prefix0.JsProxyReflectable(), const <Object>[]),
          new r.MethodMirrorImpl(r"attributeChanged", 262146, 13, null, -1, -1, const <int>[1, 2, 3], const prefix0.JsProxyReflectable(), const <Object>[]),
          new r.MethodMirrorImpl(r"serializeValueToAttribute", 262146, 9, null, -1, -1, const <int>[4, 5, 6], const prefix0.JsProxyReflectable(), const <Object>[]),
          new r.MethodMirrorImpl(r"serialize", 131074, 5, 10, 10, 10, const <int>[7], const prefix0.JsProxyReflectable(), const <Object>[]),
          new r.MethodMirrorImpl(r"deserialize", 65538, 5, null, null, null, const <int>[8, 9], const prefix0.JsProxyReflectable(), const <Object>[]),
          new r.ImplicitGetterMirrorImpl(const prefix0.JsProxyReflectable(), 1, -1, -1, 10),
          new r.ImplicitSetterMirrorImpl(const prefix0.JsProxyReflectable(), 1, -1, -1, 11)],
          <m.ParameterMirror>[
          new r.ParameterMirrorImpl(r"_field", 102, 3, const prefix0.JsProxyReflectable(), null, -1, -1, const [], null),
          new r.ParameterMirrorImpl(r"name", 32774, 6, const prefix0.JsProxyReflectable(), 10, -1, -1, const <Object>[], null),
          new r.ParameterMirrorImpl(r"oldValue", 32774, 6, const prefix0.JsProxyReflectable(), 10, -1, -1, const <Object>[], null),
          new r.ParameterMirrorImpl(r"newValue", 32774, 6, const prefix0.JsProxyReflectable(), 10, -1, -1, const <Object>[], null),
          new r.ParameterMirrorImpl(r"value", 16390, 7, const prefix0.JsProxyReflectable(), null, -1, -1, const <Object>[], null),
          new r.ParameterMirrorImpl(r"attribute", 32774, 7, const prefix0.JsProxyReflectable(), 10, -1, -1, const <Object>[], null),
          new r.ParameterMirrorImpl(r"node", 36870, 7, const prefix0.JsProxyReflectable(), 13, -1, -1, const <Object>[], null),
          new r.ParameterMirrorImpl(r"value", 16390, 8, const prefix0.JsProxyReflectable(), null, -1, -1, const <Object>[], null),
          new r.ParameterMirrorImpl(r"value", 32774, 9, const prefix0.JsProxyReflectable(), 10, -1, -1, const <Object>[], null),
          new r.ParameterMirrorImpl(r"type", 32774, 9, const prefix0.JsProxyReflectable(), 11, -1, -1, const <Object>[], null),
        new r.ParameterMirrorImpl(r"_values", 2130022, 11, const prefix0.JsProxyReflectable(), 12, -1, -1, const [], null)], <Type>[prefix1.FantasticMixin, prefix0.JsProxy, prefix2.PolymerMixin, const r.FakeType(r".polymer.lib.polymer_micro.PolymerElement with .FantasticMixin"), const r.FakeType(r"polymer.lib.polymer_micro.dart.dom.html.HtmlElement with polymer.src.common.polymer_js_proxy.PolymerMixin"), prefix4.PolymerSerialize, prefix1.ExampleList, const r.FakeType(r"polymer.lib.polymer_micro.dart.dom.html.HtmlElement with polymer.src.common.polymer_js_proxy.PolymerMixin, polymer_interop.src.js_element_proxy.PolymerBase"), prefix3.PolymerElement, prefix5.PolymerBase, String, Type, List, prefix6.Element, Object], 15, {r"field": (dynamic instance) => instance.field, r"attached": (dynamic instance) => instance.attached, r"detached": (dynamic instance) => instance.detached, r"attributeChanged": (dynamic instance) => instance.attributeChanged, r"serializeValueToAttribute": (dynamic instance) => instance.serializeValueToAttribute, r"serialize": (dynamic instance) => instance.serialize, r"deserialize": (dynamic instance) => instance.deserialize, r"values": (dynamic instance) => instance.values}, {r"field=": (dynamic instance, value) => instance.field = value, r"values=": (dynamic instance, value) => instance.values = value}, null)};

Notably :

... (o) { return o is prefix1.FantasticMixin && o is! prefix1.polymer.lib.polymer_micro.PolymerElement with .FantasticMixin; } ...

And:

... new r.NonGenericClassMirrorImpl(r"polymer.lib.polymer_micro.PolymerElement with .FantasticMixin", ...
@dam0vm3nt
Copy link
Contributor Author

I realize only now that probably this should be a reflectable issue more than a polymer-dart one...

@eernstg
Copy link

eernstg commented Dec 2, 2015

There is an issue at google/reflectable.dart#48 about this bug now. Copy/paste from the code quoted above produces text containing some <span>..</span> tokens, but after I removed that it seems likely that there is only one problem: A mixin application (whose "name" is on the format A with M) is used in an is! test, which is of course not syntactically correct. That problem is being addressed in relation to google/reflectable.dart#48.

@eernstg
Copy link

eernstg commented Dec 2, 2015

You can do git clone 'https://github.com/dart-lang/reflectable.git' now and put something like

dependencies:
  reflectable:
    path: ../the/path/to/reflectable

into your 'pubspec.yaml', and try it out with the version of reflectable that contains a fix for the code generation bug (0f06199f91c49601ba1133a0a8f42cd0faa0d4b9).

@dam0vm3nt
Copy link
Contributor Author

ok now it works. tnx.

@donny-dont
Copy link
Contributor

@eernstg I'm getting

web\main.dart:56:23403:
Cannot resolve 'field'.

Doesn't seem to like this area

const <Object>[const prefix32.field('created_at')]

That's an annotation on one of my models. So not sure what it's doing there.

@eernstg
Copy link

eernstg commented Dec 3, 2015

Sounds like a new issue, could you please report it as an issue on https://github.com/dart-lang/reflectable/issues?

The fact that it is an annotation on one of your models could mean that it is there because there is a reflector which covers that class and includes a metadataCapability. In that case it should be possible to perform a myClassMirorr.metadata query, and it should return the list you mentioned. But maybe it fails because something is wrong in the computation of prefix32.

@jakemac53
Copy link
Contributor

I think this is resolved now, please re-open if that is not the case

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

4 participants