TEnumerableBase<T>.Min(const comparer: IComparer<T>) uses fComparer instead of comparer

Issue #195 resolved
Kasper Tofte created an issue

The following function (line 846 in Spring.Collections.Base.pas) uses the fComparer from TEnumerableBase<T> instead of the one passed to the function. Line 860 should be

      if comparer.Compare(item, Result) < 0 then

instead of

      if fComparer.Compare(item, Result) < 0 then

function TEnumerableBase<T>.Min(const comparer: IComparer<T>): T;
var
  flag: Boolean;
  item: T;
begin
{$IFDEF SPRING_ENABLE_GUARD}
  Guard.CheckNotNull(Assigned(comparer), 'comparer');
{$ENDIF}

  flag := False;
  for item in Self do
  begin
    if flag then
    begin
      if fComparer.Compare(item, Result) < 0 then
        Result := item;
    end
    else
    begin
      flag := True;
      Result := item;
    end;
  end;
  if not flag then
    raise EInvalidOperationException.CreateRes(@SSequenceContainsNoElements);
end;

Comments (4)

  1. Log in to comment