       translateIr ctx, op
   (jsCall op, (join classParams, (translateIr ctx, args)))
 
-addConstraintsFrom = (ctx, {name, type}, to) ->
-  typed = ctx.type name
+addConstraintsFrom = (ctx, {id, type}, to) ->
+  typed = ctx.typeForId id
   if typed and (_empty to.constraints) and _notEmpty typed.type.constraints
     inferredType = freshInstance ctx, typed
     sub = matchType inferredType.type, (substitute ctx.substitution, type).type

  else
    to

irReference = (name, type, arity) ->
  {ir: irReferenceTranslate, name, type, arity}

irReferenceTranslate = (ctx, {name, type, arity}) ->
  if ctx.isMethod name, type
    translateIr ctx, (irMethod type, name)
  else
    finalType = addConstraintsFrom ctx, {name, type}, substitute ctx.substitution, type
    classParams = dictsForConstraint ctx, finalType.constraints
    if classParams.length > 0
      (irFunctionTranslate ctx,

      if declaration.type and declaration.type not instanceof TempType
        throw new Error "assignType: #{name} already has a type"
      declaration.type = type
      @types[declaration.id] = type
    else
      throw new Error "assignType: #{name} is not declared"

  typeForId: (id) ->
    @types[id]

  currentDeclarations: ->
    cloneMap @_scope()

  declareArity: (name, arity) ->
    @declare name, arity: arity
