This commit is contained in:
Ivan Bondarev 2024-01-04 10:27:26 +01:00
parent 970f5827a0
commit 6764768a02
2 changed files with 21 additions and 0 deletions

View file

@ -11599,7 +11599,10 @@ namespace PascalABCCompiler.NETGenerator
}
LocalBuilder lb = il.DeclareLocal(return_type);
if (save_debug_info) lb.SetLocalSymInfo("$enumer$" + uid++);
value.InWhatExpr.visit(this);
if (value.InWhatExpr.type.is_value_type)
il.Emit(OpCodes.Box, in_what_type);
il.Emit(OpCodes.Callvirt, enumer_mi);
il.Emit(OpCodes.Stloc, lb);
Label exl = il.BeginExceptionBlock();

18
TestSuite/foreach13.pas Normal file
View file

@ -0,0 +1,18 @@
type
// Обязательно запись
r1 = record(IEnumerable<Exception>)
res := new Exception[](new System.InvalidOperationException('OK'));
function GetEnumerator: IEnumerator<Exception> := res.AsEnumerable.GetEnumerator;
function System.Collections.IEnumerable.GetEnumerator: System.Collections.IEnumerator := self.GetEnumerator;
end;
begin
var ex: Exception;
foreach var e in new r1 do
begin
ex := e;
end;
assert(ex.Message = 'OK');
end.