 # Assumes definition name
 preDeclareExplicitlyTyped = (ctx, type, docs) ->
   explicitType = quantifyUnbound ctx, type
+  copyOrigin explicitType.type, type
   name = ctx.definitionName()
   id = ctx.definitionId()
   if ctx.isPreTyped name

    # console.log "attaching", t1.name, t2
    # console.log "attached", (printType t2)
    newSubstitution()
  else if t1.TypeConstr and t2.TypeConstr and t1.name is t2.name
    emptySubstitution()
  else if t1.TypeApp and t2.TypeApp

  ctx.declareAsFinal name, scopeIndex
  return deferredConstraints or []

declaredTypeTooGeneral = (ctx, inferredType, updatedDeclaredType, declaredType) ->
  {fails: [{conflicts, types}]} = matchType inferredType.type.type, copyOrigin (updatedDeclaredType.type.type), declaredType.type.type
  [fromInferred, fromDeclared] = types
  [t1, t2] = sortBasedOnOriginPosition fromInferred, fromDeclared
  ctx.extendSubstitution substitutionFail
    message: "declared type is too general, " +
      if t1 is fromInferred
        "inferred #{printType types[0]}, got #{print originOf types[1]}"
      else
        "got #{print originOf types[1]}, inferred #{printType types[0]}"
    conflicts: conflicts

topLevelExpression = (ctx, expression) ->
  ctx.bareDefine()
