   ctx.declareAsFinal name, scopeIndex
   return deferredConstraints or []
 
-# Old comment:
-# here I will create type schemes for all definitions
-# The problem is I don't know which are impricise, because the names are done inside the
-# pattern. I can use the context to know which types where added in the current assignment.
-
-# TODO: malformed ctx, "LHS\'s type doesn\'t match the RHS in assignment", pattern
+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()

      unifiedType = explicitType# substitute ctx.substitution, explicitType
      inferredType = quantifyUnbound ctx, unifiedType
      if not typeEq inferredType, updatedDeclaredType
        ctx.extendSubstitution substitutionFail "#{name}'s declared type is too general, inferred #{plainPrettyPrint inferredType}"
      # Context reduction
      isDeclaredConstraint = (c) ->
        entailed = entail ctx, unifiedType.constraints, c

# 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
