From 345de8b1fb5e36be0356164173e54790f0b121e6 Mon Sep 17 00:00:00 2001 From: Henrik Valve <102954461+HenrikAkseliValve@users.noreply.github.com> Date: Tue, 20 Aug 2024 10:54:49 +0300 Subject: [PATCH] Couldn't remove mobules without translation unit (#1861) I do not know I'm first to encounter this, however, loop that removes module without translation units, could not have worked. In C# Enumerator prohibs editing the collection so you cannot remove modules from `options.Module` while iterating `options.Mobule`. Chose `RemoveAll` for its simplicity. Not necessary optimal solution although it might be. Co-authored-by: HenrikVDestia --- src/Generator/Driver.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Generator/Driver.cs b/src/Generator/Driver.cs index 9b2084333..cb19a0c24 100644 --- a/src/Generator/Driver.cs +++ b/src/Generator/Driver.cs @@ -417,12 +417,12 @@ public static bool Run(ILibrary library) } new CleanUnitPass { Context = driver.Context }.VisitASTContext(driver.Context.ASTContext); - foreach (var module in options.Modules.Where( - m => m != options.SystemModule && !m.Units.GetGenerated().Any())) + options.Modules.RemoveAll(m => { - Diagnostics.Message($"Removing module {module} because no translation units are generated..."); - options.Modules.Remove(module); - } + bool result = m != options.SystemModule && !m.Units.GetGenerated().Any(); + if (result) Diagnostics.Message($"Removing module {m} because no translation units are generated..."); + return result; + }); if (!options.Quiet) Diagnostics.Message("Processing code...");