View Issue Details

IDProjectCategoryView StatusLast Update
0037913pas2jstranspilerpublic2020-10-29 07:05
ReporterOndrej Pokorny Assigned ToMattias Gaertner  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Versiontrunk 
Summary0037913: Buggy + (+=) operator on arrays
DescriptionThis syntax compiles but shows a runtime error:
var
  A: array of TMyObjectClass;
begin
  A := nil;
  A += [TTest];
  document.body.innerText := A[0].Test;

Error:
Uncaught TypeError: $mod.A[0].Test is not a function
    at Object.$mod.$main (ClassFunctionBug.js:1528)
    at Object.run (ClassFunctionBug.js:141)
    at ClassFunctionBug.html:11
Steps To ReproduceSee the attached project.
TagsNo tags attached.
Fixed in Revision
Attached Files

Activities

Ondrej Pokorny

2020-10-12 13:47

developer  

ClassFunctionBug.lpr (600 bytes)   
program ClassFunctionBug;

{$mode delphi}

uses
  JS, Classes, SysUtils, Web;

type
  TMyObject = class;
  TMyObjectClass = class of TMyObject;
  TMyObject = class
  public
    class function Test: string; virtual; abstract;
  end;

  TTest = class(TMyObject)
  public
    class function Test: string; override;
  end;

{ TTest }

class function TTest.Test: string;
begin
  Result := 'abc';
end;

var
  A: array of TMyObjectClass;
begin
  A := nil;
  A += [TTest];
  { workaround:
  SetLength(A, 1);
  A[0] := TTest;}
  document.body.innerText := A[0].Test;
end.
ClassFunctionBug.lpr (600 bytes)   

Mattias Gaertner

2020-10-28 21:36

manager   ~0126615

pas2js now gives an error.

Ondrej Pokorny

2020-10-29 07:05

developer   ~0126625

OK, thanks

Issue History

Date Modified Username Field Change
2020-10-12 13:47 Ondrej Pokorny New Issue
2020-10-12 13:47 Ondrej Pokorny File Added: ClassFunctionBug.lpr
2020-10-12 13:58 Mattias Gaertner Assigned To => Mattias Gaertner
2020-10-12 13:58 Mattias Gaertner Status new => assigned
2020-10-28 21:36 Mattias Gaertner Status assigned => resolved
2020-10-28 21:36 Mattias Gaertner Resolution open => fixed
2020-10-28 21:36 Mattias Gaertner Note Added: 0126615
2020-10-29 07:05 Ondrej Pokorny Status resolved => closed
2020-10-29 07:05 Ondrej Pokorny Note Added: 0126625