Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Implement arity check for function types #16

Closed
jacob314 opened this issue Dec 23, 2014 · 3 comments
Closed

Implement arity check for function types #16

jacob314 opened this issue Dec 23, 2014 · 3 comments

Comments

@jacob314
Copy link
Contributor

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";
  }
@sigmundch
Copy link
Contributor

yeah, we should support arity checks. I assume _1 etc are defined like:

typedef dynamic _0();
typedef dynamic _1(arg);
typedef dynamic _2(arg, arg);
...

@vsmenon
Copy link
Contributor

vsmenon commented 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.

@vsmenon vsmenon changed the title Seemingly spurious type checks for is checks on Function objects Implement arity check for function types Jan 13, 2015
@vsmenon
Copy link
Contributor

vsmenon commented Apr 24, 2015

This should be obsolete now.

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

No branches or pull requests

3 participants