Skip to content

Commit c922479

Browse files
author
mforce
committed
fix(#417): codex round 104 — default(T) operands inside literal chains
default(string) is null and contributes an empty string to a concatenation, but the gap checker recognized only the literal null keyword, so the fold broke at `default`. The gap now consumes a word-bounded `default` followed by a balanced type-paren (reused TryConsumeTypeParen), folded as an empty contribution. Deliberately conservative on the type question: a text scan cannot tell reference types (where default IS null — the actual evasion) from value types (where it adds text), so ALL default(T) operands are consumed; a value-type default in a fragment chain folds inexactly and may refuse absurd-but-harmless code — the same fail-closed stance as the cast/subtraction ambiguity. Untyped `default` cannot compile inside a concatenation, so the paren form is required. Mutation-verified: codex's exact default(string) form and a default(string?)! variant each failed PostgresImagePin with the composed-chain refusal; a variable merely NAMED defaultName in the same gap position passed. Restored, rebuilt, all three SchemaDocsTests green.
1 parent 896cdbe commit c922479

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

tests/Cluckwork.Api.IntegrationTests/SchemaDocsTests.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,32 @@ static bool IsPlusGap(string t, int start, int end)
499499
if (p < end && t[p] == '+') { p = SkipTrivia(t, p + 1); continue; }
500500
return false;
501501
}
502+
// default(T) likewise: for any reference type it IS
503+
// null and contributes nothing, which is the actual
504+
// evasion — and a text scan cannot tell reference
505+
// from value types, so ALL default(T) operands are
506+
// consumed as empty. Deliberately conservative: a
507+
// value-type default in a fragment chain folds
508+
// inexactly and may refuse absurd-but-harmless code
509+
// (same fail-closed stance as the cast/subtraction
510+
// ambiguity). Untyped `default` cannot compile in a
511+
// concatenation, so the paren form is required.
512+
if (p + 7 <= end && t.Substring(p, 7) == "default"
513+
&& (p + 7 == end || !(char.IsLetterOrDigit(t[p + 7]) || t[p + 7] == '_')))
514+
{
515+
var d = SkipTrivia(t, p + 7);
516+
if (d < end && t[d] == '(')
517+
{
518+
var de = TryConsumeTypeParen(t, d);
519+
if (de > 0 && de <= end)
520+
{
521+
p = SkipTrivia(t, de);
522+
while (p < end && (t[p] == ')' || t[p] == '!')) p = SkipTrivia(t, p + 1);
523+
if (p < end && t[p] == '+') { p = SkipTrivia(t, p + 1); continue; }
524+
}
525+
}
526+
return false;
527+
}
502528
return false;
503529
}
504530
return true;

0 commit comments

Comments
 (0)