This repository was archived by the owner on Feb 22, 2018. It is now read-only.
This repository was archived by the owner on Feb 22, 2018. It is now read-only.
Implement arity check for function types #16
Closed
Description
From di/lib/src/injector.dart
library di.check_bind_args;
import "src/module.dart";
export "src/module.dart" show DEFAULT_VALUE, IDENTITY, isSet, isNotSet;
checkBindArgs(dynamic toValue, Function toFactory,
Type toImplementation, List inject, toInstanceOf) {
int count = 0;
bool argCountMatch = true;
if (isSet(toValue)) count++;
if (isSet(toFactory)) {
count++;
var len = inject.length;
switch (len) {
case 0: argCountMatch = /* severe: InvalidRuntimeCheckError */ toFactory is _0; break;
case 1: argCountMatch = /* severe: InvalidRuntimeCheckError */ toFactory is _1; break;
case 2: argCountMatch = /* severe: InvalidRuntimeCheckError */ toFactory is _2; break;
case 3: argCountMatch = /* severe: InvalidRuntimeCheckError */ toFactory is _3; break;
case 4: argCountMatch = /* severe: InvalidRuntimeCheckError */ toFactory is _4; break;
case 5: argCountMatch = /* severe: InvalidRuntimeCheckError */ toFactory is _5; break;
case 6: argCountMatch = /* severe: InvalidRuntimeCheckError */ toFactory is _6; break;
case 7: argCountMatch = /* severe: InvalidRuntimeCheckError */ toFactory is _7; break;
case 8: argCountMatch = /* severe: InvalidRuntimeCheckError */ toFactory is _8; break;
case 9: argCountMatch = /* severe: InvalidRuntimeCheckError */ toFactory is _9; break;
case 10: argCountMatch = /* severe: InvalidRuntimeCheckError */ toFactory is _10; break;
case 11: argCountMatch = /* severe: InvalidRuntimeCheckError */ toFactory is _11; break;
case 12: argCountMatch = /* severe: InvalidRuntimeCheckError */ toFactory is _12; break;
case 13: argCountMatch = /* severe: InvalidRuntimeCheckError */ toFactory is _13; break;
case 14: argCountMatch = /* severe: InvalidRuntimeCheckError */ toFactory is _14; break;
case 15: argCountMatch = /* severe: InvalidRuntimeCheckError */ toFactory is _15; break;
}
if (!argCountMatch) throw "toFactory's argument count does not match amount provided by inject";
}
Activity
sigmundch commentedon Dec 23, 2014
yeah, we should support arity checks. I assume
_1
etc are defined like:vsmenon commentedon Jan 6, 2015
Here's the code: https://github.com/angular/di.dart/blob/master/lib/check_bind_args.dart
We disallow this as our subtype rule (i.e., is) is stricter than standard for this case. We could provide a helper function for arity instead.
[-]Seemingly spurious type checks for is checks on Function objects[/-][+]Implement arity check for function types[/+]vsmenon commentedon Apr 24, 2015
This should be obsolete now.