diff --git a/NETGenerator/NETGenerator.cs b/NETGenerator/NETGenerator.cs index 405879445..289aa39dd 100644 --- a/NETGenerator/NETGenerator.cs +++ b/NETGenerator/NETGenerator.cs @@ -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(); diff --git a/TestSuite/foreach13.pas b/TestSuite/foreach13.pas new file mode 100644 index 000000000..0ad3c1389 --- /dev/null +++ b/TestSuite/foreach13.pas @@ -0,0 +1,18 @@ +type + // Обязательно запись + r1 = record(IEnumerable) + res := new Exception[](new System.InvalidOperationException('OK')); + + function GetEnumerator: IEnumerator := 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. \ No newline at end of file