fix #807
This commit is contained in:
parent
2208af5f9d
commit
d3a461ff39
|
|
@ -10300,7 +10300,7 @@ namespace PascalABCCompiler.NETGenerator
|
|||
Type return_type = null;
|
||||
bool is_generic = false;
|
||||
MethodInfo enumer_mi = null; //typeof(System.Collections.IEnumerable).GetMethod("GetEnumerator", Type.EmptyTypes);
|
||||
if (var_tp.IsValueType && !(in_what_type.IsArray && in_what_type.GetArrayRank() > 1))
|
||||
if (/*var_tp.IsValueType &&*/ !var_tp.IsGenericParameter && !(in_what_type.IsArray && in_what_type.GetArrayRank() > 1))
|
||||
{
|
||||
enumer_mi = helper.GetEnumeratorMethod(in_what_type);
|
||||
if (enumer_mi == null)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
type TClass = class(System.Collections.IEnumerable)
|
||||
type TClass = class(System.Collections.IEnumerable)
|
||||
public function GetEnumerator : System.Collections.IEnumerator;
|
||||
begin
|
||||
Result := nil;
|
||||
|
|
@ -24,7 +24,7 @@ begin
|
|||
end;
|
||||
i := 0;
|
||||
arr[1] := 1; arr[2] := 2; arr[3] := 3;
|
||||
{foreach v : integer in arr do
|
||||
foreach v : integer in arr do
|
||||
begin
|
||||
case i of
|
||||
0 : assert(v=1);
|
||||
|
|
@ -32,7 +32,7 @@ begin
|
|||
2 : assert(v=3);
|
||||
end;
|
||||
Inc(i);
|
||||
end;}
|
||||
end;
|
||||
i := 0;
|
||||
SetLength(arr2,2);
|
||||
arr2[0] := 3.14; arr2[1] := 2.71;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
procedure WriteArray<T>(a: array of T);
|
||||
procedure WriteArray<T>(a: array of T);
|
||||
begin
|
||||
foreach x: T in a do
|
||||
writeln(x);
|
||||
|
|
@ -8,8 +8,13 @@ begin
|
|||
var a := Arr(2,3,5);
|
||||
WriteArray(a);
|
||||
var a2 := new integer[2,2]((3,3),(3,3));
|
||||
var i := 0;
|
||||
foreach x: integer in a2 do
|
||||
begin
|
||||
assert(x = 3);
|
||||
Inc(i);
|
||||
end;
|
||||
assert(i = 4);
|
||||
var a3 := new integer[2,2]((3,3),(3,3));
|
||||
foreach var x in a3 do
|
||||
assert(x=3);
|
||||
|
|
|
|||
40
TestSuite/foreach5.pas
Normal file
40
TestSuite/foreach5.pas
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
var i: integer;
|
||||
|
||||
type
|
||||
e1 = class(System.Collections.IEnumerator)
|
||||
public function MoveNext := false;
|
||||
public function get_current:object := nil;
|
||||
public procedure Reset := exit;
|
||||
end;
|
||||
e2<T> = class(System.Collections.Generic.IEnumerator<T>)
|
||||
public function MoveNext := false;
|
||||
public function System.Collections.IEnumerator.get_current:object := nil;
|
||||
public function get_current:T := default(T);
|
||||
public procedure Reset := exit;
|
||||
public procedure Dispose := exit;
|
||||
end;
|
||||
|
||||
t2=class
|
||||
b:byte;
|
||||
end;
|
||||
t1<T> = class(System.Collections.Generic.IEnumerable<T>)
|
||||
|
||||
public function System.Collections.IEnumerable.GetEnumerator: System.Collections.IEnumerator;
|
||||
begin
|
||||
i := 1;
|
||||
Result := new e1;
|
||||
end;
|
||||
|
||||
public function GetEnumerator: System.Collections.Generic.IEnumerator<T>;
|
||||
begin
|
||||
i := 2;
|
||||
Result := new e2<T>;
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
begin
|
||||
foreach var o in new t1<t2> do
|
||||
o.b := 2;
|
||||
assert(i = 2);
|
||||
end.
|
||||
12
TestSuite/foreach6.pas
Normal file
12
TestSuite/foreach6.pas
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
function test<T>(a: T): sequence of T;
|
||||
begin
|
||||
var lst: List<List<T>> := new List<List<T>>;
|
||||
lst.Add(new List<T>(Arr(a, a)));
|
||||
foreach var x in lst do
|
||||
begin
|
||||
yield x[0];
|
||||
end;
|
||||
end;
|
||||
begin
|
||||
assert(test(2).ToArray[0] = 2);
|
||||
end.
|
||||
Loading…
Reference in a new issue