 
     # TODO: defer for class declaration if not defined
     ## if not ctx.isClassDefined className    ...
-
-    instance = (new Constrained freshConstraints,
-      (new ClassConstraint instanceType.className, freshInstanceType.type))
-    ## if overlaps ctx, instance
-    ##   malformed 'instance overlaps with another', instance
-    ## else
-    ctx.addInstance instanceName, instance
-
-    # """var #{instanceName} = new #{className}(#{listOf methods});"""
-    (jsVarDeclaration (validIdentifier instanceName),
-      (irDefinition (new Constrained freshConstraints, (tupleOfTypes methodTypes).type),
-        (jsNew className, (join superClassInstances, methods))))
+    if not freshInstanceType
+      jsNoop()
+    else
+      freshConstraints = freshInstanceType.constraints
+      instance = (new Constrained freshConstraints,
+        (new ClassConstraint instanceType.className, freshInstanceType.type))
+      ## if overlaps ctx, instance
+      ##   malformed 'instance overlaps with another', instance
+      ## else
+      ctx.addInstance instanceName, instance
+
+      # """var #{instanceName} = new #{className}(#{listOf methods});"""
+      (jsVarDeclaration (validIdentifier instanceName),
+        (irDefinition (new Constrained freshConstraints, (tupleOfTypes methodTypes).type),
+          (jsNew className, (join superClassInstances, methods))))
 
 # Makes sure methods are typed explicitly and returns the instance constraint
 # with renamed type variables to avoid clashes
-assignMethodTypes = (ctx, instanceName, classDeclaration, instanceType, instanceConstraints) ->
+assignMethodTypes = (ctx, typeExpression, instanceName, classDeclaration, instanceType, instanceConstraints) ->
   # First we must freshen the instance type, to avoid name clashes of type vars
   freshInstanceType = freshInstance ctx,
     (quantifyUnbound ctx,


toHtml = (highlighted) ->
  crawl highlighted, (word, symbol, parent) ->
    (word.ws or '') + colorize(theme[labelOf word], symbol)

labelOf = (word) ->
  word.malformed and 'malformed' or word.label or 'normal'

collapse = (nodes) ->
  collapsed = ""


  # log "mguing", classDeclaration.constraint.types, freshInstanceType.type
  sub = mostGeneralUnifier classDeclaration.constraint.types, freshInstanceType.type
  if isFailed sub
    malformed typeExpression, 'Type doesn\'t match class type'
    return null

  ctx.bindTypeVariables setToArray (findFree freshInstanceType)
  for name, {arity, type} of values classDeclaration.declarations
