anchor.diff:           || {RecordType, FieldName, FieldType, When} <- Constraints],
       SolvedConstraints =
           [begin
  -             RecId = {id, Attrs, RecName} = record_type_name(RecType),
  -             case ets:lookup(record_types, RecName) of
  -                 [] ->
  -                     type_error({not_a_record_type, RecId, When}),
  -                     not_solved;
  -                 [{RecName, Formals, Fields}] ->
  +            RecId = {id, Attrs, RecName} = record_type_name(RecType),
  +            case lookup_type(RecName) of
  +                {Formals, {record_t, Fields}} ->
                        FieldTypes = [{Name, Type} || {field_t, _, {id, _, Name}, Type} <- Fields],
                        {id, _, FieldString} = FieldName,
                        case proplists:get_value(FieldString, FieldTypes) of
  
positive.code:                              unify(FreshFldType, FieldType, {todo, {solve_field_constraint_field, When}}),
                               unify(FreshRecType, RecType, {todo, {solve_field_constraint_record, When}}),
                               {RecType, FieldName, FieldType, When}
                       end
               end
           end
           || {RecType, FieldName, FieldType, When} <- DerefConstraints,
  
negative.code:     ets:new(record_types, [public, named_table, set]),
      %% A relation from field names to types
      ets:new(record_fields, [public, named_table, bag]),
      [ insert_typedef(Id, Args, Typedef)
       || {type_def, _Attrs, Id, Args, Typedef} <- Defs].
  
  destroy_record_types() ->
      ets:delete(record_types),
      ets:delete(record_fields).
  
  -spec insert_typedef(aeso_syntax:id(), [aeso_syntax:tvar()], aeso_syntax:typedef()) -> ok.
  insert_typedef(Id = {id, Attrs, Name}, Args, Typedef) ->
      case Typedef of
          {record_t, Fields} ->
              ets:insert(record_types, {Name, Args, Fields}),
              [ets:insert(record_fields, {FieldName, FieldType, {app_t, Attrs, Id, Args}})
               || {field_t, _, {id, _, FieldName}, FieldType} <- Fields];
          {variant_t, _} -> ok;
          {alias_t, _} -> ok
      end,
      ok.
  
  -spec lookup_type(string()) -> false | {[aeso_syntax:tvar()], aeso_syntax:typedef()}.
  lookup_type(Name) ->
      case ets:lookup(record_types, Name) of
          []                       -> false;
          [{Name, Params, Fields}] -> {Params, {record_t, Fields}}
      end.
  
  create_field_constraints() ->
      %% A relation from uvars to constraints
  