From ef64ba4e08883da9449c9910025b7c0d37ba63ba Mon Sep 17 00:00:00 2001 From: copygirl Date: Sat, 6 May 2023 17:34:24 +0200 Subject: [PATCH] Run queries that only match singletons --- src/gaemstone.SourceGen/ModuleGenerator.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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("");