Skip to content
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
@jacob314

Description

@jacob314

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

sigmundch commented on Dec 23, 2014

@sigmundch
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

vsmenon commented on Jan 6, 2015

@vsmenon
Contributor

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.

changed the title [-]Seemingly spurious type checks for is checks on Function objects[/-] [+]Implement arity check for function types[/+] on Jan 13, 2015
vsmenon

vsmenon commented on Apr 24, 2015

@vsmenon
Contributor

This should be obsolete now.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @jacob314@sigmundch@vsmenon

        Issue actions

          Implement arity check for function types · Issue #16 · dart-archive/dev_compiler