       message: "declared type is too general, " +
         if t1 is fromInferred then "#{inferred}, #{got}" else "#{got}, #{inferred}"
       conflicts: conflicts
+
+replaceQuantifiedByOrigin = (type) ->
+  if type.TypeApp
+    new TypeApp (replaceQuantifiedByOrigin type.op),
+      (replaceQuantifiedByOrigin type.arg)
+  else if type.QuantifiedVar and type.origin
+    new TypeVariable (print type.origin), star
+  else
+    type
 
 topLevelExpression = (ctx, expression) ->
   ctx.bareDefine()

    if not includesJsType currentType.type
      # Check the declared type
      declaredType = ctx.type name
      explicitType = freshInstance ctx, declaredType
      updatedDeclaredType = quantifyUnbound ctx, explicitType#(substitute ctx.substitution, explicitType)
      unify ctx, currentType.type, explicitType.type
      unifiedType = explicitType# substitute ctx.substitution, explicitType
      inferredType = quantifyUnbound ctx, unifiedType
      if not typeEq inferredType, updatedDeclaredType
        declaredTypeTooGeneral ctx, inferredType, updatedDeclaredType, declaredType
      # Context reduction
      isDeclaredConstraint = (c) ->
        entailed = entail ctx, unifiedType.constraints, c

  ctx.declareAsFinal name, scopeIndex
  return deferredConstraints or []

declaredTypeTooGeneral = (ctx, inferredType, updatedDeclaredType, unifiedType, declaredType) ->
  # Have to copy origins to these ForAll types so I can use them in completion
  {fails: [{conflicts, types}]} = matchType (copyOrigin inferredType.type.type, unifiedType.type),
    (copyOrigin updatedDeclaredType.type.type, declaredType.type.type)
  [fromInferred, fromDeclared] = types
  [t1, t2] = sortBasedOnOriginPosition fromInferred, fromDeclared
  # Dont report for fake types
  declaringType = originOf fromDeclared
  if isFake declaringType
    declaringType.inferredType = replaceQuantifiedByOrigin fromInferred
  else
    inferred = "inferred #{printType fromInferred}"
    got = "got #{print declaringType}"
