fix #917
This commit is contained in:
parent
088639816b
commit
f406dfd173
15
TestSuite/lambdas6.pas
Normal file
15
TestSuite/lambdas6.pas
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
function f1(self:array of byte; a:byte):byte; extensionmethod := a+1;
|
||||
|
||||
procedure p1<T>(self:T; f:()->byte); extensionmethod;
|
||||
begin
|
||||
assert(f = 1);
|
||||
assert(f() = 1);
|
||||
end;
|
||||
|
||||
begin
|
||||
var a:array of byte;
|
||||
SetLength(a, 2);
|
||||
var b:byte;
|
||||
b.p1(()->a.f1(0));
|
||||
|
||||
end.
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
begin
|
||||
begin
|
||||
var f: IntFunc := x->x*4;
|
||||
var g: IntFunc := x->x + f(0);
|
||||
f(1);
|
||||
assert(f(1) = 4);
|
||||
end.
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
var o: object;
|
||||
procedure p<X,Y>(a: System.Func<X, Y>; b:System.Func<Y, X>; c: X);
|
||||
begin
|
||||
writeln(a(c));
|
||||
o := a(c);
|
||||
end;
|
||||
|
||||
begin
|
||||
p(x -> x, x -> 1.0, 4.0);
|
||||
assert(Round(real(o)) = 4);
|
||||
end.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
uses System, System.Collections.Generic, System.Linq;
|
||||
uses System, System.Collections.Generic, System.Linq;
|
||||
|
||||
type Customer = class
|
||||
public
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
begin
|
||||
begin
|
||||
var a := new System.Collections.Generic.List<string>();
|
||||
a.Add('abc');
|
||||
a.Add('def');
|
||||
var b := a.SelectMany(x -> x).Select(x -> x);
|
||||
foreach var c in b do
|
||||
writeln(c);
|
||||
assert(b.SequenceEqual(Seq('a','b','c','d','e','f')));
|
||||
end.
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
function psd<T>(e: IEnumerable<T>): IEnumerable<T>; where T:constructor;
|
||||
function psd<T>(e: IEnumerable<T>): IEnumerable<T>; where T:constructor;
|
||||
begin
|
||||
result := e.OrderBy(x -> x);
|
||||
end;
|
||||
|
||||
begin
|
||||
var ttt := psd(Seq(1,2,4,2,3,5,6));
|
||||
writeln(ttt);
|
||||
assert(ttt.SequenceEqual(Seq(1,2,2,3,4,5,6)));
|
||||
end.
|
||||
|
|
@ -1,11 +1,13 @@
|
|||
type
|
||||
TBaseClass = abstract class
|
||||
property p1: byte read write; abstract;
|
||||
property p2: byte read; abstract;
|
||||
end;
|
||||
|
||||
TClass = class(TBaseClass)
|
||||
b: byte;
|
||||
property p1: byte read b write b; override;
|
||||
property p2: byte read b; override;
|
||||
end;
|
||||
|
||||
TClass2 = class(TBaseClass)
|
||||
|
|
@ -13,13 +15,16 @@
|
|||
function getb := b;
|
||||
procedure setb(value: byte) := b := value;
|
||||
property p1: byte read getb write setb; override;
|
||||
property p2: byte read getb; override;
|
||||
end;
|
||||
|
||||
begin
|
||||
var o: TBaseClass := new TClass;
|
||||
o.p1 := 2;
|
||||
assert(o.p1 = 2);
|
||||
assert(o.p2 = 2);
|
||||
o := new TClass2;
|
||||
o.p1 := 2;
|
||||
assert(o.p1 = 2);
|
||||
assert(o.p2 = 2);
|
||||
end.
|
||||
|
|
@ -18728,6 +18728,7 @@ namespace PascalABCCompiler.TreeConverter
|
|||
expression_node qq = null;
|
||||
delegated_methods dm = null;
|
||||
common_type_node delegate_type = null;
|
||||
int err_cnt = ErrorsList.Count;
|
||||
try
|
||||
{
|
||||
qq = convert_strong(ff.dereferencing_value);
|
||||
|
|
@ -18738,6 +18739,8 @@ namespace PascalABCCompiler.TreeConverter
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (ErrorsList.Count != err_cnt)//delete fake errors
|
||||
ErrorsList.RemoveRange(err_cnt, ErrorsList.Count - err_cnt);
|
||||
// Погасить все исключения. Значит, не вывелось, и в правой части лямбды - не вызов процедуры, а скорее всего приведение типа T(x)
|
||||
// К сожалению, сюда попадает случай a->a.Print() где a до более позднего этапа не определяется
|
||||
// Плохо, но лучше пока не получается
|
||||
|
|
|
|||
Loading…
Reference in a new issue