         return classDeclaration
 
   addInstance: (name, type) ->
-    (@classNamed type.type.className).instances.push {name, type}
+    (@classNamed type.type.type.className).instances.push {name, type}
 
   isMethod: (name, type) ->
     any (for {className} in type.constraints

constraintsFromInstance = (ctx, constraint) ->
  {className, type} = constraint
  for instance in (ctx.classNamed className).instances
    # log "trying to find the instance", (printType instance.type.type), (printType constraint)
    substitution = toMatchTypes instance.type.type.types, constraint.types
    if substitution
      ctx.extendSubstitution substitution
      return map ((c) -> substitute substitution, c), instance.type.constraints
  null

_names = (list) ->

instanceDictFor = (ctx, constraint) ->
  for {name, type} in (ctx.classNamed constraint.className).instances
    # TODO: support lookup of composite types, by traversing left depth-first
    if toMatchTypes (freshInstance ctx, type).type.types, constraint.types
      return validIdentifier name
  throw new Error "no instance for #{safePrintType constraint}"

