"varargs" methods need to be handled differently for generic types (as in, explicitly type-checked)
Original Reporter info from Mantis: Akira1364
-
Reporter name:
Original Reporter info from Mantis: Akira1364
- Reporter name:
Description:
For example, using my "JSGenerics" unit (mentioned on the Pas2 mailing list recently) containing generic versions of the types from JS.pas, the following program compiles, but in theory should not:
program Example;
{$mode Delphi}
uses JS, JSGenerics, NodeJS, NodeJSApp;
type
TStringArray = TGJSArray<String>;
TMyApplication = class(TNodeJSApplication)
procedure DoRun; override;
end;
procedure TMyApplication.DoRun;
var A: TStringArray;
begin
A := TStringArray._of(2.0, 3.0, 4.0, 5.0);
Console.Log(A);
Terminate;
end;
begin
with TMyApplication.Create(nil) do begin
Initialize;
Run;
Free;
end;
end.
This is obviously because "varargs" is simply written to accept "JSValue", and isn't currently aware of any difference between generic and non-generic contexts.
In contrast, the following little TypeScript snippet:
const num: number = 2;
let A = Array&LtPos;string>(num, num, num);
Gives the error: "Argument of type 'number' is not assignable to parameter of type 'string'."
Steps to reproduce:
Compile provided examples.
Mantis conversion info:
- Mantis ID: 36210
- OS: Windows
- OS Build: 10
- Build: Trunk
- Platform: x86_64
- Monitored by: » Akira1364 (Akira1364)