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

TypeLiteral does not work for non-core types (generator.dart) #184

Open
vsavkin opened this issue Sep 25, 2014 · 2 comments
Open

TypeLiteral does not work for non-core types (generator.dart) #184

vsavkin opened this issue Sep 25, 2014 · 2 comments

Comments

@vsavkin
Copy link
Contributor

vsavkin commented Sep 25, 2014

To reproduce define two types

@Injectable()
class GenericType<T> {
  String desc;

  GenericType(this.desc);
}

@Injectable()
class NeedsGenerticTypeString {
  GenericType<String> myObj;
  NeedsGenerticTypeString(this.myObj);
}

And run the following test:

ii("Non-core types and TypeLiteral do not work with each other", () {
  var injector = new ModuleInjector([moduleFactory()
    ..bind(NeedsGenerticTypeString)
    ..bind(new TypeLiteral<GenericType<String>>().type, toValue: new GenericType("String"))
  ]);

  expect(() => injector.get(NeedsGenerticTypeString)).not.toThrow();
});

It will fail with "No provider found for GenericType!"

This is because this expression (in generator.dart)

if (typeArgs != null && typeArgs.isNotEmpty && typeArgs.any((arg) => arg is! dynamic))

Will never evaluate to true.

@vicb
Copy link
Contributor

vicb commented Oct 15, 2014

@vsavkin is this fixed now ?

@vsavkin
Copy link
Contributor Author

vsavkin commented Oct 15, 2014

It has not been fixed.

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

No branches or pull requests

2 participants