diff --git a/src/gaemstone.SourceGen/ModuleGenerator.cs b/src/gaemstone.SourceGen/ModuleGenerator.cs index ec797cb..3a83f0a 100644 --- a/src/gaemstone.SourceGen/ModuleGenerator.cs +++ b/src/gaemstone.SourceGen/ModuleGenerator.cs @@ -321,7 +321,10 @@ public class ModuleGenerator .Append(param.IsNullable ? "iter.FieldOrEmpty" : "iter.Field") .AppendLine($"<{param.FieldType!.GetFullName()}>({param.TermIndex});"); - sb.AppendLine("\t\t\tfor (var i = 0; i < iter.Count; i++) {"); + // When the shim method is called, there's guaranteed to be at least one match. + // iter.Count may be 0 when there's no variable entities that can be matched. + // For example for a query that only matches singleton entities. + sb.AppendLine("\t\t\tfor (var i = 0; i == 0 || i < iter.Count; i++) {"); sb.Append($"\t\t\t\t{method.Name}"); if (method.IsGeneric) sb.Append("");