Skip to content
GitLab
Next
    • GitLab: the DevOps platform
    • Explore GitLab
    • Install GitLab
    • How GitLab compares
    • Get started
    • GitLab docs
    • GitLab Learn
  • Pricing
  • Talk to an expert
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
    Projects Groups Topics Snippets
  • Register
  • Sign in
  • FPC Source FPC Source
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
    • Locked files
  • Issues 1,404
    • Issues 1,404
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 67
    • Merge requests 67
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Artifacts
    • Schedules
    • Test cases
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Container Registry
    • Infrastructure Registry
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • FPC
  • FPCFPC
  • FPC SourceFPC Source
  • Issues
  • #35580
Closed
Open
Issue created May 13, 2019 by FPC Admin account@fpc_adminOwner

Compiler picks up wrong overload for TMemoryStream.Write(TBytes, Longint);

Original Reporter info from Mantis: kluug.net @onpok
  • Reporter name: Ondrej Pokorny

Description:

FPC calls the "Write(const Buffer; Count: Longint)" overload even when the "Write(const Buffer: TBytes; Count: Longint)" should be called.

This is because the TMemoryStream.Write declaration misses the "overload" keyword. See docs: https://www.freepascal.org/docs-html/ref/refsu79.html "There is only one case where the overload modifier is mandatory: if a function must be overloaded that resides in another unit."

The docs should be enhanced as well - it is mandatory for object methods across different classes; not only functions across different units.

Steps to reproduce:

program Project1;
{$mode objfpc}
uses
  SysUtils, Classes;
var
  B1, B2: TBytes;
  S: TMemoryStream;
  I: Integer;
begin
  B1 := [1, 2, 3, 4, 5];
  S := TMemoryStream.Create;
  S.Write(B1, Length(B1)); // <<< BUG: wrong overload is called
  S.Position := 0;
  SetLength(B2, Length(B1));
  S.ReadData(B2, Length(B2));
  S.Free;
  if not(Length(B2) = Length(B1)) then
    Halt(999);
  for I := Low(B1) to High(B1) do
    if B1[I] <> B2[I] then
      Halt(I);
  Writeln('OK');
  Readln;
end.

Additional information:

Patch attached.

Mantis conversion info:

  • Mantis ID: 35580
  • Build: r42056
  • Version: 3.3.1
  • Fixed in version: 3.3.1
  • Fixed in revision: 42058 (#6649fab2), 42118 (#77658b92)
  • Target version: 3.2.0
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
Time tracking