Read on 2026-09-19: every FSharp.Refactor analyzer module behind a CR rule's twin, compared with the guard list DESIGN.md §8 gives that CR rule. Each entry lists the conditions, alternative shapes and knobs the F# CODE enforces (often only in comments, sometimes not even in Rules.md) that the design left out, with the C# reading of each. Items marked port go into DESIGN.md's guard list; items marked n/a do not apply to C#, and are recorded so nobody re-derives them.
Reading method: the module's doc comments and inline reasoning, which in this codebase carry the guards; the code was opened where a comment named a corpus case.
- port The negated form:
if c then false else true→not c. C#:return c ? false : true/if (c) return false; return true;→return !c;. - port An
else iflink: replacing the wholeifnode with the bare condition glues it onto the preceding branch (F#: anelifnode's range starts at the keyword). C#: anifthat is theelseclause of anotherifis not rewritten to a bare expression statement. - port A test whose branch reads the payload is a match in disguise:
FR0010 never produces
x.IsSomebesidex.Valueand leaves the shape to FR0034. C#: CR0001 stands down where the branch readsx.Valueof aNullable<T>tested byHasValue; CR0004 owns it. - port Nothing is rewritten inside an argument the compiler quotes into a LINQ expression tree (typed callee). Already the rule for CR0011; make it the shared rule for every family-A rewrite except CR0007/CR0008, which the F# side runs inside quotations deliberately (a strictly simpler tree).
- n/a The unannotated-parameter case (
x.IsSomeis FS0072 where the type is not settled): C# has no left-to-right inference. - n/a Emptiness rewrites (
List.length xs = 0→isEmpty): CA1827/CA1860.
- port Only chain HEADS fire; an
ifnested in another'selseyields an inner suggestion the overlap hold-back resolves in the outer's favour. - port An else-less trailing
ifmeans the chain has no terminalelse: the F# rewrite needs one for the wildcard arm and stands down. C#: the statement form (switchstatement) is fine without adefault; the expression form (switchexpression) needs_ =>and stands down. - port Verbatim and raw literals are valid constant patterns and are
spliced with their original text, prefix included (
@"x","""x"""). - port The rewrite splices ORIGINAL source text of literals and bodies, never re-serialised nodes.
- The F# side has no minimum arm count; the design's "at least three" is a
C# decision (two
==tests read fine asif/else) — keep, but say so.
- port Branch bodies never ASSIGN the subject (the pattern variable would then diverge from it).
- port The subject is textually identical in every test and every cast;
a plain
elsecloses the chain, or its absence makes every branch a statement (default:omitted). - port Only the outermost
ifof a chain fires; theelse iflinks are visited separately and must not each produce a garbled suggestion. - port A parenthesised cast is replaced together with its parentheses; substitution runs right-to-left per body.
- n/a Single-line branches (F#'s column-based substitution); C# spans are exact, multi-line bodies are fine.
- port The
Nonearm must not itself read.Value(that code throws today and is not ours to rewrite); theSomearm must read it at least once. - port The binder name is derived (
v, else<x>Value, elsevalue) and must not appear ANYWHERE in the expression, and the receiver must not be rebound inside the branch (lambda parameter, local, pattern, loop variable): substituting under a shadow changes what the binder refers to. - port The comparison spellings are the same test:
x == null,x != nullon aNullable<T>(either operand order) swap the branches like!HasValue. - port The boolean-chain forms:
x.HasValue && p(x.Value) && q→x is { } v && p(v) && q;!x.HasValue || p(x.Value)→x is not { } v || p(v)(F#:Option.exists/forallover the fabricated lambda). Only the OUTERMOST chain node fires. ASpan/byref-like local inside the predicates cannot be captured by a lambda in F#; in C# the pattern variable is a plain local, so this veto is n/a. - port An else-less
ifgains noelse(unit); theIsNone/negated forms swap branches. - port A
matchortryopening theSomearm would take theNoneclause in F#; C#'s braces make this n/a, but aswitchstatement body whose pattern variable name collides with the derived binder is the C# reading of the same collision — covered by the "nowhere in the expression" rule. - port Inside an expression tree the
HasValue/Valueshape IS what the provider translates: no rewrite there.
- Matches the design. port the "same else on both levels" check is
TEXTUAL identity of the two
elseblocks, comments included.
- port Flipping across an
else ifchain is a different rewrite: the rule needs a plainif/elsepair. - port Both branches must sit on their own lines at the same depth so the blocks swap verbatim. C#: both branches are blocks, or both are single statements; a mixed pair stands down.
- port A CALL as the kept operand may owe its
booltype to the literal beside it (F#: an SRTP function's return pinned by&& true). C# reading: an operand of typedynamic—d && trueisboolwheredalone isdynamic— stands the rule down; outside a bool-pinning context (if,while, a guard, another&&/||,!) any call operand keeps its literal. - port Runs inside expression trees and query lambdas DELIBERATELY: removing a node leaves a strictly simpler tree of shapes the translator already accepted.
- port The purity allowlist: operators, property chains, indexing and
comparisons pass; ANY call disqualifies, with a tiny allowlist (
not,isNull; C#:!,is null,string.IsNullOrEmpty-class BCL predicates bycallsOnlyCore). C# indexing must be an array or BCL indexer: a user-defined indexer is a call. - port Runs inside expression trees deliberately, as CR0007.
- port An arm that carries a COMMENT is an arm the author considered a
distinct case: each merged arm's comment travels with its own pattern
(C#:
case 1: // whykeeps its trailing comment on its label;orpatterns in aswitchexpression take the comment between alternatives). A comment BETWEEN arms belongs to neither and holds the fix (the comment guard). A comment inside the pattern or the surviving body is spliced verbatim and never hoisted twice. - port Bodies compared as TEXT, single-line; guards refused; a lone
lowercase identifier is a binder and refused (C#:
case var x:and declaration patterns bind,case Foo:does not).
- port Either operand order (
x == "A"and"A" == x). - port The guard must be EXACTLY the equality (no
&&); constants a pattern can spell exclude what only expressions can (F#:nan,+expressions; C#: a non-constantstatic readonly, anew, anameofis fine). - port Works on
switchstatements and expressions alike (F#: match, match!, function).
- Read separately below (the engine is 1.4k lines); see §"CR0011 engine".
- port The phrase list: "not supported", "not implemented", "unsupported",
"not yet", "nyi", "stub", "placeholder", "unfinished"…; bare
TODO/FIXMEare deliberately absent (they mark future work of every kind). - port Commented-OUT code is not a note: a comment opening with an identifier applied to a string or a parenthesised argument, or carrying a format hole or a print call, reads as code and does not accuse.
- port A
null/defaultreturn of a method whose declared return type makes it the legitimate "no result" — F#: a declaredoptionreturn or a partial active pattern. C#: abool Try…(out T)returningfalse, a method declaredT?returningnull, adefaultin aFirstOrDefault- shaped method stays; the placeholder set isnull,default,false,0,-1,""/string.Empty, an empty collection expression,Array.Empty<T>(). - port Only where sibling arms actually COMPUTE: a table of constants is data, not a stub.
- port Inside an iterator or async body the raise rides the siblings'
keyword (F#:
return raise …in a CE). C#:throwis a statement and needs nothing; in aswitchEXPRESSION the arm becomesthrow new …(a throw expression is legal there).
- port Every explicit arm must cover its case TOTALLY (no
when, no literal payload); the wildcard is a plain_/default, is LAST, and hides at most two members. Enums are open sets in F# too — ExpandWildcard never fires on them, which is why the design keeps CR0013 note-only in the sweep and has the editor keep a throwingdefault:. - port A hidden member whose bare name another type in scope also
declares is written QUALIFIED (
Color.Blue); C# enum members are always qualified, so n/a — but ausing staticon the enum makes bare names legal and ambiguous, so spellColor.Bluealways. - port Two short cases share the wildcard's line; past 100 columns each takes its own line under the arm.
- port Guarded arms must still be PLAIN case patterns, or coverage of
the whole match is unknowable; any total pattern (
_,var x) completes the match and stands the rule down. - port Every covered name must belong to THIS type (a same-named member of another enum must not count).
- port Multi-line matches only, each arm starting its own line, nothing
trailing the last arm; new arms adopt the last arm's
|/casecolumn. - port The added arm's keyword follows the siblings (F#:
return raisein a CE). C#:case M: throw new NotImplementedException();in a statement,M => throw new …in an expression.
- read below (§"loops").
- read below (§"loops").
- port (CR0015) The bound is literally
0 .. xs.Length - 1(F#) — C#:i < xs.Length/i < xs.Count/i <= xs.Length - 1,i++/i += 1, start0, over the SAME path the body indexes; aSeq.length-style spelling counts (C#:xs.Count()on a list is CA1829's, leave it). - port Nothing in the body may REBIND either name: a nested
for i, a lambda parameter, a local, a pattern shadowingimakes the innerxs[i]a different index; and no name bound on the path to the loop (a parameter, an outer loop, a local) may clash with the chosen element name, which isitem, elseitem2,item3… (Mibo: an outerfor x in 0..4was shadowed by the chosenx). - port The body may not take the ADDRESS of the element:
ref xs[i],&xs[i](C#ref var e = ref xs[i],Span<T>slicing byi) wants an lvalue, and aforeachelement is a copy (Nu's Renderer2d). - port The alias line:
var e = xs[i];as the body's first statement and the index's only use → the loop variable takeseand the line goes; the binder must be a plain name, unannotated (var), nothing around the loop already binds it. - port A string source: on .NET a string enumerates its characters, so
for (int i…) s[i]→foreach (var c in s)is fine; F#'s Fable gate is n/a. - port (CR0026) Constant indexes (
xs[0]) are a deliberate head access; a receiver bound inside the loop (a fresh short sequence per iteration) is not the quadratic; a SMALL BOUND keeps the walk constant —xs[i % 13], a loopfor i in 0..3— and stands the rule down (F#smallBound = 64). - port (CR0026) A
whilecondition IS per iteration and counts as body; aforheader's bound evaluates once (i < xs.Count()is per iteration in C# — the note fires there).
- port The flag must be RAISED in the body (an assignment of
true), and named negated in the condition (!done, also!(a || b)naming two). - port A name only WRITTEN in the loop is a result being filled in, not
state; a
let mutableinside the body dies each round and is not carried. - port Any carried value whose every assignment is
x = x + <literal>(a stride,low = mid + 1) is an INDEX, and the loop is the search loop: no note (measured 12× faster than the LINQ spelling on an early hit). - port The note counts the statements after the flag-raising one; zero
means no note. A
letcontributes its right-hand side AND what follows. - n/a Silence inside
task/asyncbuilders (no recursion there): the C# remedy isbreak, which is legal in anasyncmethod.
The engine's safety rules beyond FSharpLint, all of which port:
- port A right side that drops or duplicates a metavariable fires only
on pure atoms; substituted bindings are parenthesised unless atomic; the
whole replacement is parenthesised when the matched expression was an
operand of an enclosing application; an operand of
&&/||is bracketed by PRECEDENCE, not like an argument (!(a && b), never!((a) && (b))); equal precedence on the LEFT is the grammar's own grouping and goes unbracketed, on the right the brackets stay. - port Bool-literal rules (
x == true) need typed proof the binding isbool(F#:objsubsumes the literal; C#:dynamic, and a user-defined==(T, bool)operator). - port NaN-sensitive rules — an ordering flip (
!(a > b)→a <= b), aCompareTocollapse, a sort-to-min — need typed proof the operands are notfloat/double(a unit-of-measure float is a float too; C#:decimalis fine,double/float/Halfare not). - port Every non-metavariable name a side spells must resolve to the BCL
(or
Enumerable) at the site — a repository's ownIsNullOrEmpty, a shadowing extension method — or the hint stands down; without a clean typed tree, the untyped path stands down only inside a query expression (F#: a computation expression's custom operation is the one shape a bare core name can be mistaken for). Custom hints from the config name the repository's own functions and are its author's to aim. - port Names a file puts in scope that a right side might spell — a
local, a parameter, a pattern binder, a
using staticmember, an extension method in an imported namespace — make the hint fail closed. - port An
=directly inside a call's argument list may be a NAMED ARGUMENT (F#:Timer(period, AutoReset = true)); C#:Foo(flag: true)is unambiguous, but an=inside an object initialiser or an attribute argument IS an assignment — equality-headed hints never fire inside an attribute or an initialiser. - port No hint fires inside an attribute argument, an expression tree, or a quotation.
- port Map fusion (
xs.Select(f).Select(g)→xs.Select(x => g(f(x)))) fuses only mappers whose calls are provably effect-free: BCL/Enumerablefunctions, constructors of records/tuples, lambdas that call nothing but those, read no property declared outside the BCL (a user getter runs its body;Lazy<T>.Valueforces), hold no interpolated string with a hole (formatted by a ToString the type chooses), no statement, assignment, loop, handler,newof a class,await; a mapper that THROWS by design is an effect (a different exception can escape once the sweeps interleave); the in-placeArrayoperations are effects. (This is CR0029's guard list; the design's "provably purefst/snd/id" is the F# FR0137 fixed list, and the engine's richer proof supersedes it.) - port An overloaded METHOD GROUP used as a first-class value resolves
only because a pipe pins its argument type first; a hint must never move
such a binding to a position checked before the element type is known
(C#:
xs.OrderByDescending(File.GetLastWriteTime).First()→xs.MaxBy(File.GetLastWriteTime)is fine in C# since type inference sees the receiver first — n/a, but a method group whose overload the target delegate type picks must keep a target of the same delegate type). - port Nested matches keep only the OUTERMOST; unification sees through parentheses, and a parenthesised node is not matched twice.
- port Rules deliberately ABSENT and why:
Aggregate((a, b) => a + b)→Sum()(unchecked wrap vs checked throw; Mibo);First(p)forWhere(p).First()is fine, butWhere(p).First()→First(p)keeps the same exception; F#'s head-of-filter →findis absent because the empty-input exception types differ — C#'sWhere(p).First()andFirst(p)both throwInvalidOperationException, so n/a. - port A hint whose left side is a pipeline renders its result back as a pipeline so the receiver is typed before the lambda (F#-specific inference; in C# the receiver is always first — n/a).
- port Refuse outright any operation that MUTATES, and read the
callback for it: the eager copy is what keeps enumeration and mutation
apart (SQLProvider lost 19 tests to
Seq.toList |> List.iter (fun k -> dict[k] <- v)). The callback may not: assign; call a mutating METHOD on ANY receiver (Add,Remove,Insert,Clear,Push,Enqueue,Set…,RemoveAt… — an alias of the source is indistinguishable from a stranger); call a LOCAL function that assigns; or MENTION the collection itself (a lambda as much as a named function handed over,List.iter (register es)). The source must be OWNED by the enclosing method (a local, parameter, loop or pattern variable): a field or a captured outer collection can be written by anything the callback names, and stands the rule down. - port
mutatesSomethingreads the TEXT for<-(C#:=,+=,++,--inside the callback's span), over-approximating in the safe direction. - port A source that is ALREADY the target kind gains nothing from the
lazy detour: an array literal,
Split,ToArray,GetFiles,ToListfeedingToList()— no move, not even for a consuming drop (Count()over an array walks whatLengthreads in O(1)). C#:xs.ToList().Counton aList<T>source,arr.ToArray().Length— stand down; CA1829/CA1860 own the rest. - port Movable operations are the ORDER-PRESERVING element transforms
whose variants agree once the trailing conversion forces evaluation;
groupByis absent (the element type changes);skip/takeare absent (List and Seq variants throw different exception types on short inputs — C#:Skip/Takenever throw, so n/a);itemis absent (exception types differ — C#ElementAtvs indexer:ArgumentOutOfRangevsIndexOutOfRange, so keep it absent); the SORT family never crosses an Array boundary (Array sorts are unstable; C#:Array.Sortis unstable whereOrderByis stable — never rewriteOrderBytoArray.Sort). - port Consuming operations may short-circuit source enumeration
(
Any,First,Contains) — the point of the rewrite, identical for pure sources only; so the source must be pure (noyield-based generator with effects the shortened enumeration would skip) — the samecallsOnlyCorequestion on the source expression. - port Both stages single-line in F#; C#: the two stages keep the LAYOUT they had (one call per line stays one per line).
- port Moving INTO the eager kind is measured per operation
(
filterinto Seq −4%/−13%,mapinto Seq +35% time — never offered; into Array always wins). C# PerfClaims must measureToList().Where→Where().ToList()andToArray().Select→Select().ToArray()per operation before shipping each pair.
- port
Sumonly for a FLOATING accumulator (F#:sumis checked where the loop wrapped) — the design has this; add:decimalis checked in both spellings and qualifies; a STRING accumulator (s = s + piece) becomesstring.Concat(xs)/string.Join(F#:String.concat), and a LAZY source gets materialised first (String.concatover a lazy seq hit the slow IEnumerable path, 16× slower). - port The source must be a real generic
IEnumerable<T>(typed): aforeachalso accepts the non-genericIEnumerableand duck-typedGetEnumeratorsources, which no LINQ operator does. - port The accumulator must not be re-assigned in the continuation;
an annotated declaration keeps its annotation on the folded binding
(Mibo inferred a different type once it was lost — C#: a declared type
stays declared,
varstaysvar). - port When the loop is followed by nothing but the accumulator
itself, the fold expression IS the result: binding and trailing use
collapse (F#) — C#:
var total = 0; foreach… ; return total;→return xs.Sum();. - port A fold that lands as a 150-character line is not a cleanup:
the general
Aggregateform is not emitted (design agrees); F# emits the fold, C# does not. - n/a The
foldlambda is checked BEFOREinitin F# (member lookup on the accumulator meets an indeterminate type).
- port A prefix of PURE single-line immutable
letbindings folds into the lambda (var t = f(l); if (t == "x") found = true;→xs.Any(l => f(l) == "x")); each must be effect-free and silent about the flag. - port The purity test FOLLOWS a same-file function three declarations
deep (
if (IsValid(x)) found = truewith a same-fileIsValidwhose body passes) and takes a function already under test (recursion) as pure; a callee declared elsewhere, a user method of another type, a constructor, any other .NET method stands the rule down; naming a function without applying it counts too (xs.Any(validate)hands the effect to a core function). - port The predicate must fit ONE line.
- port The assigned literal must be the initializer's OPPOSITE.
- port
Setaskscomparisonwherecontainsaskedequality: a[<NoComparison>]record or a function-typed field takes the HashSet companion instead of the in-place conversion. C#:HashSet<T>asks only equality, so the in-placeFrozenSet/HashSetconversion needs a T with value equality (record,struct,string, enums, a class withIEquatable<T>); a class with reference equality still converts (the probe was reference-equality already). - port The in-place conversion changes the binding's TYPE and is an API
change on a PUBLIC static field (fsharplint's public list in a NuGet
library was converted without
--api-changes): public → companion set beside it, never in place; private/internal → in place when EVERY use is a probe; a LATER file of an executable reading the binding at its list type keeps it a companion too. - port Any OTHER binder of the same name anywhere (a parameter, a loop local, a lambda argument) makes the name ambiguous to the scan — no fix.
- port A
letbetween the loop and the probe, or a match-arm pattern, may rebind the collection per iteration — loop-local, not loop-invariant; a lambda handed to a collection function is a loop. - port The ROOT identifier of a dotted path is what loop-invariance is
judged on (
config.Excludedvaries per iteration exactly whenconfigdoes); a dotted path's storage is not this file's to shadow, so it gets the note, never the fix. - port Probes under one
#ifget a companion under the same#if; probes under different conditions get none. - port One companion for the whole group, the edit set carried by the FIRST probe only, so the group applies once.
- port The RECEIVER must be the same list on every iteration:
columns[tile.X].Add(tile)picks a list per element (Nu's 2048) and stands down. - port A projected body stays a loop:
AddRange(xs.Select(f))measured no faster and read worse (suave). - n/a the F# range-source spelling (
AddRange(a .. b)parses as an indexer); C#:Enumerable.Rangeis a normal source.
- port The ref-cell form
acc.Value <- acc.Value @ [x]: C# analogue is a captured local or a field (this.items = this.items.Append(x).ToArray()). - port The appended operand must not be a NUMERIC literal (
i = i + 1is the commonest statement in any loop, and resolving it put the rule at the top of the slow-analyzer list): string-ness is checked FIRST, being the selective test. - port FR0050's fix already rewrites the exact string-accumulator shape
into one
String.concat: no note on a site the fix is about to remove. - port Recursive form (FR0104): only a SINGLETON literal appended in a
SELF-CALL argument (
Collect(acc.Append(x).ToArray(), rest)); a generala @ bmerge runs once per call and stays.
- port
mapandignoretyped-gated against shadowing (C#: the call must resolve toEnumerable, not a user extension namedSelect). - port The DIRECT form (
Seq.map f xs |> ignoreandModule.map f xsunpiped) is the one that runs nothing; C#:xs.Select(f);andEnumerable.Select(xs, f);both._ = xs.Select(f);is a decision (design has it).
- port The element type must be CLOSED — a value type, record, tuple,
string, function or
sealedclass:Addupcasts its argument to an interface or base class where the collection expression fixes the type at the first element; a delegate is not closed either (Addconverted a lambda). C#:new List<T>()declaresT, andxs.Select(x => e).ToList()infers frome— aList<IShape>filled withCircles becomesList<Circle>; the rewrite must spellSelect<Circle, IShape>orCast, or stand down. - port Every OTHER statement of the loops must be unit-typed (typed): a
discarded non-unit call (
d.TryAdd(x, x)) would become a yield in F#; C#: the rewrite is a LINQ pipeline, so any statement other thanif/foreach/theAddstands the rule down (design says this). - port An empty construction only:
new List<T>(xs)starts full. - port The declared type argument becomes the list's annotation (
Addconverted anintliteral tolong); C#:Selectmust yield the declared element type, so a literalAdd(1)into aList<long>needsSelect(x => (long)…)— stand down unless the projected type equals the declared type exactly. - port The loops read no
Span/byref-like value (cannot be captured by the lambda) — this one IS C#-relevant for the LINQ rewrite (a lambda cannot capture aref struct). - port The declaration alone on its line goes, but not from between two
#ifdirectives; the loops span no#ifand no multi-line literal. - port A drain whose parentheses were an application's own keeps a
pair (
Some(List.ofSeq acc)→Someaccwas the defect). - port Knobs:
arrays(array-shaped drains, slower, off) andexplicitYield(older compilers) — C#:csharp_refactor.CR0028.arraysforToArray()/index/Countdrains, measured separately. - port A
whileloop feeding the accumulator qualifies in F# (a list expression hosts it); C#: no LINQ shape for awhile— stand down.
Superseded by the engine's purity proof (see CR0011); keep "both stages
the SAME module's map" (C#: both Enumerable.Select, never an
IQueryable stage) and "same line" as layout only.
The C# rule is CA1851's shape, but the F# module's measurements bear on CR0021/CR0031:
- port
iter/iteriare absent (a wash);containson a REFERENCE array is a small LOSS for the array module;containsonint/longhas TWO answers (vectorisedEnumerable.Contains5.4× is the CLI's, the idiomatic one is editor-only); numeric aggregates are FR0041's. C#:EnumerableIS the vectorised path, so CR0021'sSum/Max/Minclaims forint[]/long[]/List<int>are measured there; ondoublethe NaN semantics differ between a>loop andMax().
- port The outer loop may be a COLLECTION-FUNCTION CALLBACK
(
customers.ForEach(c => db.Orders…), aSelectlambda), not only aforeach; the chunking suppressor is read anywhere in the outer pipeline, and by NAME when the chunking was bound first (var pages = ids.Chunk(200); foreach (var page in pages)). - port Inside a query expression a nested
fromis a JOIN the provider translates into one statement — but only when the OUTER source is itselfIQueryable(an in-memory outer sequence runs the inner query per element, query syntax or not). - port A query under a loop that PAGES (
Skip/Takeof the outer element) or filters by the outer element's BATCH (chunk.Contains(o.Id)) runs one statement per batch on purpose — not N+1. - port Emits nothing when the file has type errors.
- port A
yield!in TAIL position of the body (the last step, reached through sequencing, bindings,if,match) is turned into a jump by the F# compiler and does not count; C#:foreach (var c in Walk(child)) yield return c;always nests — no tail-call form exists, so every self-entry counts, butreturn Walk(child)(noyield) is a redirect and never fires. - port Only a DIRECT self-call is the nested enumerator;
Seq.collect walk xsnests one per level insidecollectand counts too (C#:children.SelectMany(Walk)inside the iterator counts).
- port The bind fix is legal only on the CE's own STATEMENT SPINE: a
blocking call nested inside ANOTHER binding's right-hand side sits inside
the body's range but not on its spine (
var pair = (t.Result, 1); F#'slet pair = let x = t.Result in …was 21 rollbacks in one repo). C#:awaitis legal in any expression of anasyncmethod, so the spine restriction is n/a — but NOT inside alock, acatchfilter (when), afinally, anunsafeblock, a lambda that is not itselfasync, or a local function body (the local function is its own boundary; F# names local functions and object expressions as closures the Lambda-node scan misses). - port A
trybody whose handler namesAggregateException:.Wait(),.ResultandWaitAllthrow the wrapper, a bind throws the inner exception, and the handler would go dead (WaitAll's other failures with it).GetResult()already unwraps and is unaffected. - port Completion proofs: under the receiver's own
IsCompleted/IsCompletedSuccessfullyin thethenbranch (conjoined with anything, or negated in theelse); complete from birth (Task.FromResult,CompletedTask,ValueTask.FromResult, the exception/cancellation siblings, also through a localvar t = Task.FromResult(1)or a static readonly); the antecedent inside its ownContinueWithcontinuation (the lambda's parameter, or a named function's); after the receiver's ownWait(timeout)above;t.Wait(timeout)itself is the bounded idiom; a.Resultread afterproc.WaitForExit()in the same body (the Process stdout pattern, forty times over in one repo). - port
Task.WaitAll(tasks, timeout|token): the final argument is proven not a task, so the pair is not params-style and stays. - port The console's blocking point: the spine of
Main, a runner ending in an exit-code literal, top-level statements — no boundary note; anything behind a lambda or nested function is a boundary of its own. - port A thread-choreographed body (a signal, a
Thread,Interlocked) gets the note but never the fix: a bind moves the continuation off the thread the wait kept it on.Thread.Sleepalone is a pause. - port Synchronisation-primitive waits inside an async method
(
ManualResetEventSlim.Wait,SemaphoreSlim.Wait,WaitHandle.WaitOne,Barrier.SignalAndWait,Thread.Join,Monitor.Wait) are advice only (C#:SemaphoreSlim.WaitAsyncexists — CR0042's twin logic can offer it). - port
ContinueWithreading.Result: only the PLAIN shape rewrites — one lambda, no scheduler/options, a single-line body whose every use of the antecedent isa.Result, a value-returning continuation, the call closing its line, the binder name free in the body; a body testingIsFaulted/Statushandles the antecedent itself and stays a note. - port The sync-sibling swap requires the SIBLING to be a method with the same argument count (a PROPERTY named like the sibling would turn a call into a value read).
- port
Task.Run(() => c.Wait())-style: the one fix inside a lambda is the one that DELETES the lambda (F#:Task.Run(fun () -> c |> Async.RunSynchronously)→Async.StartAsTask). C#:Task.Run(() => t.Result)→twhen the lambda is exactly the drain; the cancelled-vs-faulted difference the F# comment records (a cancelled computation gives a Cancelled task, not a Faulted one) applies to C# too and is the more correct of the two. - port The replacement is spelled as an infix pipe / an
awaitexpression, which is atomic only in a bind's RHS or a statement: as the receiver of.ConfigureAwait(false), an argument or under any other parent it takes parentheses ((await t).Length). - port A
let x: T = <blocking>with an annotation is not a shape to gamble on (F#:let! x : T =); C#:T x = await t;is fine — n/a. - port The last statement of a block cannot be
let! _ =(F#); C#:await t;as the last statement is fine — n/a. But a value-returning test's final blocking VALUE (NUnit'sExpectedResult) has no bind shape: the rewrite stops (CR0045). - port
ValueTask: a struct with no upcast toTask—.AsTask()is the spelling where aTaskis expected (aFunc<Task>delegate). - port Only the INNERMOST enclosing async body attributes a site.
- port
Assert.Throws<AggregateException>(() => t.Wait())asserts the WRAPPER throws; awaited, the inner exception escapes and the assertion fails — stays as written.
- port STRICTLY file-private in the editor (every use is in this file,
so
FindReferencesis authoritative);internalwidens to project-wide callers under--api-changesonly;InternalsVisibleTobreaks "internal ⇒ every caller is in this project" and vetoes; a script or linked file compiled elsewhere vetoes; public stays out. - port Every blocking site in the body is either the RHS of a simple
var x = <blocking>(→var x = await …) or a TAIL terminal (→return await …); every other tail terminal isreturn-prefixed (C# already has explicit returns — n/a); a site inside a lambda,try, nested async or any other shape vetoes; a parenthesised tail is one value; statement-shaped tails (while, an assignment) cannot take a return prefix (n/a in C#). - port Every CALLER must be a full application forming the RHS of a
simple
letor areturnpayload, inside an async body, outside lambdas, nested CEs and no-bind zones; one unconvertible caller vetoes everything. - port No return-type annotation (F#: needs a
Task<_>rewrite; C#: the return type must be rewrittenT→Task<T>,void→Task— a fix the design must spell out), notinline(n/a), no mutual recursion, no self-recursion (F#); C#: a self-recursive method can become async, but the recursive call site must be awaited — keep the veto for v1. - port A thread-choreographed body vetoes; a
Span/byref-like value in the body cannot become a state-machine field (C#:ref structlocals cannot cross anawait— the compiler errors, so the speculative check catches it; keep the explicit veto). - port No two edits may share a position (the
task {line and the first bind).
- port NEVER
Dispose→DisposeAsync: aValueTasktwin with nothing to await behind it (fantomas'sFile.Create(f).Dispose()was rewritten todo! File.Create(f).DisposeAsync()). - port Statement position takes
do!only when the twin returns the NON-generic Task; C#:await x.FlushAsync();is fine either way — n/a, but a twin returningTask<T>in statement position discards a value the sync call also discarded — fine. - port The twin's return must WRAP the original's, compared
STRUCTURALLY (
T→Task<T>/ValueTask<T>,void→Task/ValueTask), never by formatted name. - port Control flow whose branches are statement positions of the same
body (a
switcharm, anifbranch, atrybody, a loop body) qualify; acatchhandler andfinallydo not. - port The juxtaposed-argument spelling keeps its argument shape (F#);
C#: only the name gains its suffix and
awaitis prefixed.
- port (FR0017 half,
ValueTaskdiscarded) The head must be FULLY applied — a partial application ignores a function, a different mistake; a function-typed PARAMETER reports zero parameter groups and is not trusted. C#: a method group discarded (_ = Foo;) is a compile error — n/a;xs.ForEach(Foo)with aValueTask-returningFooIS the shape. - port (FR0149 half) Handled means: the started body IS a
try/catchcovering everything it does (not a fragment), orAsync.Catchappears AND a match consumes bothChoice1Of2andChoice2Of2(producing the Choice is not handling it). C#:Task.Run(async () => { try { … } catch { … } })covering the whole body; a.ContinueWith(…, OnlyOnFaulted); a stored task; an explicit discard. - port Only a body this file can SEE is judged: an inline lambda, or a
one-hop binding in the same file (
var listener = …; Task.Run(listener)); a computation built elsewhere stays quiet. - port A
try/catcharound the START catches nothing of the work and reads as protection — the note says so explicitly; when thattrywraps the start and NOTHING else, the handler was written for this work and the EDITOR offers moving it inside verbatim (every clause, filters included); a token argument would be lost by the move, so only the single-argument start gets it; a rethrow inside the moved handler is a different rethrow (F#:reraise ()is FS0413 inside a closure; C#:throw;inside the lambda's catch is fine — n/a); the rewrite is rebuilt from body and handler alone, so a comment elsewhere in thetryholds it (comment guard). - port The body LOOPS: a handler around the whole computation ends the loop on the first failure, inside the loop it keeps polling — the note names that choice.
- port The starters differ in C#:
Task.Run(...)discarded,ThreadPool.QueueUserWorkItem, anasync voidlambda handed to avoiddelegate (CR0053), and — the one the F# side measures — an unobserved faulted task does NOT kill a .NET Core process (it did on .NET Framework 4.0 only); the note's weight is "silently lost", not "process dies". CR0044's message must say that.
- port SHARED STATE vetoes the conversion: a test that reads or writes
state outliving it — a
staticmutable of another class or a module, a process-global setter (Environment.CurrentDirectory,Environment.SetEnvironmentVariable,Thread.CurrentThread.CurrentCulture), a settable static property of the library under test (resolved through the typed tree; an unresolvable assignment target counts as shared) — keeps its blocking shape, since an awaited test may overlap another. Astaticof the test's OWN class is fine: xUnit, NUnit and MSTest run one class's tests one after another (CarmelNet writes a payment id in one test and reads it in the next) — UNLESS the file opts into method-level parallelism ([Parallelizable(ParallelScope.All|Children)],[Parallelize(Scope = ExecutionScope.MethodLevel)], read off the text at assembly, class or method). - port A file that installs global state by REFLECTION (
BindingFlagsin the file: a mock harness swapping a library's private static holders) converts NO test in it. - port
obj.Property = von a local the test just built is not shared state (flagging everysb.Capacity = 10costs more than it saves). - port The awaiting FRAMEWORKS are proven by the attribute's declaring assembly (xUnit, NUnit, MSTest, TUnit); a same-named home-grown attribute with a reflection runner would get a Task nobody awaits.
- port The body's FINAL blocking result:
do!when the test returns unit; a final VALUE of a non-unit test is its result (NUnit'sExpectedResult) — no bind shape carries it, the rewrite stops. Alet mutable x = <blocking>has nolet! mutableform (C#:var x = awaitis assignable — n/a). - port A prefix in front of a multi-line expression moves its first line; continuation lines (a pipe opening a line) must follow (F# offside; C# n/a).
- port The body is not already async; no return-type annotation
(C#:
void→async Task,T→async Task<T>; aTask-returning non-async test that blocks inside is also a shape).
- port
lock (Console.Out)/stdout/stderr/stdin: a process-wide singleton from another module gets the note alone — its other lockers are not here to fix; the lock-object fix is offered only when the locked thing belongs to this file by nature (a literal, a type object,this, a value this file defines). - port The lock object lands after the locked value's own declaration
at its indentation when this file defines it, else before the enclosing
member; a member of a type has no module-level slot in F# (C#: a
private static readonly objectfield of the type, or an instance field when the lock guards instance state). - port
lock x <| …andlock x (fun () -> …)both; C#: only thelockstatement — butMonitor.Enter(this)is the same shape and CR0048's business.
- port The body wraps in a LAMBDA in F#, so computation binds
(
do!/let!) and a local mutable declared outside stop compiling (C#: thelockstatement is a block, andawaitinsidelockis a compile error — anawaitin the body vetoes; ayieldtoo). - port The
try/finallymay be the FIRST statement after theEnterwith more following (FCS'sInlineDelayInit), not only the rest of the block. - port The
finallyholds NOTHING but theExit; own-line statements; a directive in the region vetoes. - port A bare
Enterwith no guardingtryis the leak note; the(x, ref taken)overload carries protocol and is never rewritten.
- port The
out-parameter spellingTryGetValue(key, out var v)is the C# shape (F#'s tuple return is the match); the miss arm is!d.TryGetValue(k, out var v) { v = …; d[k] = v; }or theif (d.TryGetValue(k, out var v)) return v; … d[k] = …split — both shapes in the design, plus theTryAdd(k, v)(discarded) andAddOrUpdate(k, v, (_, _) => v)stores. - port A
Lazy<T>value type is refused (CR0050's subject behindGetOrAdd), a delegate value type is refused (the lambda argument would be ambiguous with the plain-value overload). - port The key is a pure atom, or a TUPLE of atoms spelled the same in
lookup and store; the hit arm does nothing but return the binder; the
miss arm's several
lets become the lambda's body with the store line dropped; the store shares its line with nothing. - port A miss arm reading a mutable local or byref of the enclosing
scope (FS0407), holding a
Spanor taking an address, or containingreraise, stands down (C#: a lambda capturing aref structor anout/refparameter is a compile error — keep the veto;throw;inside the lambda is n/a). - port The factory hint: a factory that CALLS something (
Compute(),Load(key); notkey * 2) carries theLazyhint; aTask/ValueTaskvalue type gets the note alone (the value type would change). - port (FR0014, deferred to CA1854 in C#) Map's
TryFindoption idiom; the elif-chain peel (one level per pass) — n/a. - port (FR0018, deferred to CA1864)
TryAddevaluates the value ALWAYS where the original evaluated it only on absence: the value must be a pure atom — worth knowing when the CA rule is off and CR0049's sibling shape is wanted.
- port Gated on
GetOrAdd's RETURN type (the dictionary's value type) — no receiver-generics reconstruction;Task,ValueTask,Lazy; a factory that throws is not reported. Matches the design.
- port The capture is IMPLICIT too: a lambda referencing an instance
field or property compiles to an access through
this; a METHOD GROUP (src.Changed += this.OnChanged) and one wrapped in a delegate constructor (new FileSystemEventHandler(this.OnCreated)) pinthisjust as hard. - port A publisher the object OWNS — its own event, or one held in its
own field (
x.Disposing += … x …) — cannot outlive the object: a cycle inside one lifetime, not a leak; a localEvent<_>/newevent source in the same scope neither. - port Lambda parameters SHADOWING the captured name suppress the note.
- port Sinks are typed:
+=on anevent,SubscribeonIObservable<T>,AddHandler; aList<T>.Addof a delegate is not a sink.
- port Only LITERAL one-element collections match (
new[] { t },[t]); a variable holding one task is out of scope. - port
Task.WaitAll(new[] { t })is a blocking unit statement: its element alone would DROP the wait, so the editor's fix keeps one (t.Wait()); the awaiting combinators unwrap to the element itself. - port The editor's fix changes the result type (
Task<T[]>→Task<T>): editor-only, never the sweep.
- port
Task.RunandTask.Factory.StartNewtake the token as a SCHEDULING condition: with an already-cancelled token the delegate never runs and its side effects silently never happen (suave binds a listening socket inside one) — never injected there, and an explicitCancellationToken.Noneon them is the author choosing to always start the work. - port The token may already BE one of the arguments as PAYLOAD
(
CreateLinkedTokenSource(ct)); a params/two-token sibling overload would happily compile(ct, ct)— no injection where the token is already passed. - port A NAMED argument in the call (
cancellationToken: ct) makes positional counting meaningless — stand down (C#: the token can be appended by name instead:, cancellationToken: ct). - port A trailing lambda/
switch/conditional argument runs to the closing parenthesis in F# (, ctjoined its body as a tuple); C# argument lists are unambiguous — n/a. - port A stored
Nonebinding's RHS is never rewritten (intent this scan cannot see) — only an argument position. - port Handlers and
finallyblocks are cleanup:tx.RollbackAsync()after a cancelledCommitAsync(ct)must not throwOperationCanceledExceptionon the way out — no token injected there.
The design gives eight guards; the F# module is a three-tier ownership
model. The full model, which ports as is (C#: using var / using (...)
for the fix, IDisposable and IAsyncDisposable both):
- port THREE TIERS decided by where the binder's bare mentions send the
value. FIX when the value provably stays inside the scope: every mention
is an INVOKED member (
x.Read(...)) or a comparison operand, never inside a lambda, local function, object expression,lazy, or a computation that starts after the binding; no RESULT position mentions it (a plain-valued call excepted); no local bound to a value reached THROUGH it escapes either (var cmd = conn.CreateCommand();— aliases are followed, and through those in turn: a task, a command, a reader, a method group still needs the binder behind it; a plain-valued local (var b = stream.ReadByte()) is evaluated and done). NOTHING when an escape is an OWNERSHIP TRANSFER: the scope's result (also inside a tuple, record, upcast, wrapper case), an argument to another disposable's constructor (new StreamReader(stream)— the wrapper adopts it,leaveOpen/disposeHandlerdefault to owning), or stored where a holder beyond the scope keeps it (a field, a property, a collection insertAdd/TryAdd/Enqueue/Push/Insert, an indexer set, a static, an outer ref cell); the owner is decided whatever else the scope did on the way. NOTE ONLY when a mention could move the value somewhere whose ownership is unknown, and the note NAMES the destination: handed to a function by name (a same-file function is read ONE HOP: disposing the parameter —using,.Dispose(), handing it to another disposable's constructor — is a transfer, keeping it is the leak; the parameter is located by curried index or tuple element, and a tuple handed to a non-tuple parameter is unreadable); stored in a mutable local; captured by a closure; read by a result that may outlive the scope. - port A method-group mention that is not the function of an
application (
xs.Select(c.Convert),changed += c.Refresh) is a method group handed on: it runs after the scope on a disposed receiver. - port A member access in RESULT position may hand out something still
tied to the object (
client.GetAsync(url)as the value); a PLAIN value (md5.ComputeHash(bytes),reader.ReadToEnd()) — primitives, strings, arrays/tuples/immutable containers of those; aseq/IEnumerableis NOT plain (it runs when enumerated) — is computed before the scope exits; only a property read or an INVOKED member counts, a method group's return type says nothing about when it runs. - port SELF-ACTIVE objects are owned by whoever stops them, never by
the scope that started them: a timer, a watcher, a listener, anything
constructed with a CALLBACK, an event of it the scope subscribes to, a
token registration, a
Start()/Enable…call —usingwould stop them on the way out. - port PENDING WORK on the receiver: a
Task/ValueTask/Async-returning member called and its result DROPPED (discarded, a bare statement of task type,Async.Start) or handed on as an ARGUMENT to anything (tasks.Add(client.GetStringAsync(u)), a constructor, an unreadable function; the aliasedvar t = client.GetStringAsync(u); tasks.Add(t)the same) is in flight past the scope; an awaited, bound,.Wait()ed or.Resulted one finished before the scope ends. - port A
CancellationTokenSourcebinder: the scope KEEPS the token only when.Token(or the source, or a local alias) goes to an argument of a BCL operation whose pending result is awaited on the statement spine (Task.Delay(ms, ct),GetAsync(url, ct)awaited), a synchronous blocking wait (Wait,WaitOne,Join,Sleep,WaitAll), or a local alias followed in turn; EVERY other position hands it on — a user function (opaque), a starter (Task.Run(work, ct)), an unawaited pending call, a synchronous BCL call that may store it (tokens.Add(ct),CreateLinkedTokenSource(ct)registers on it), a constructor argument (new Worker(cts.Token): the worker's timer dies with the source), a field, a property set, a tuple/option built from it, a return. - port WRAPPERS over a foreign resource are not the scope's to dispose:
a
StreamReader/BinaryWriter/HttpClientover a resource the scope did not create (a parameter, a field, a captured local, a property read), or over a local that itself ESCAPES the scope (Giraffe's tests: aMemoryStreamwrapped in aStreamWriter, stored inctx.Request.Body, read by a returned task —usingon the writer closed the request body). Only a resource the SAME scope constructed and keeps is the scope's own; a construction outside a lambda is shared by every call of it and counts as foreign inside it. - port Manual management exempts:
x.Dispose(),x.Close()whereCloseISDispose(streams, writers, readers, sockets,MemoryStreams the compiler writes into),((IDisposable)x).Dispose()(the upcast hides the receiver). - port
File.OpenRead(path),MD5.Create(),SHA256.Create(),Aes.Create(),RandomNumberGenerator.Create()and the other BCL FACTORIES whose result the caller owns count as constructions; a cheap PascalCase prefilter runs before symbol resolution (resolving every lowercasevar x = Load(y)put the rule at the top of the slow list). - port SCOPE CONTEXT changes the weight: under the entry point (
Main, top-level statements) a leaked FLUSH-SENSITIVE type (a buffered writer or stream, a transaction) is lost work — .NET runs no finalizers at exit — and only such types are reported there (a handle the OS reclaims is no loss); in an ASP.NET action ([HttpGet]…, aControllerBase/Hubbase) the leak is per request and carries warning weight. - port Inside a computation whose builder has no
Usingtheusecannot bind (FS0708) — n/a in C#, but an iterator (yield) orasyncmethod with ausingis fine; ausingdeclaration inside aswitchsection needs braces — the fix must add them. - port
using varneeds C# 8 (design has it); the capability gate is the language version, not the framework.
- port The computation must be the scope's RESULT (returned directly,
or through a single binding of it), it must MENTION the binder, and
nothing between the
usingand the computation may touch the binder — otherwise the note stands without the fix. G-Research's analyzer flags the shape whether or not the workflow reads the disposable; this one requires the mention. C#: the design's fix (make the methodasyncandawaitthe returned task) differs from the F# move-inside fix; both are legitimate — the F# one keeps the signature and is the editor-only offer, the C#asyncone changes the exception timing and must say so.
- port A disposable built WITH the object itself (
new GraphicsDeviceManager(this)) registers with it: the base or the framework owns and disposes it. - port A DISPOSABLE BASE class makes an added
IDisposablea duplicate: the note then talks about overriding the base'sDispose(bool)(Kasino's MonoGameGamesubclass); an unresolved base is not worth the guess. - port A member that calls
field.Dispose()itself — aClose/Unsubscribe/ref-count protocol — is manual management, not an ownerless resource. - port The editor's fix appends the plain
IDisposableimplementation disposing every created field — deliberately noDispose(bool), no finalizer, noGC.SuppressFinalize(a type holding managed disposables needs none of that; CA1063's pattern is for unmanaged handles). One fix per type, carried by its first field. - port A
Disposethat delegates toDisposeAsyncdisposes through the async body; the interfaceDisposeis followed one hop intothis.Dispose()/Dispose(bool)or a let-bounddispose(). - port
MemoryStreamwith a CAPACITY owns its buffer (and is not exempt); one over the caller's buffer is.
- port RELEASE vs TOUCH:
cts.Cancel()mentions the field and frees nothing; releasing meansDispose/DisposeAsync/Close, directly or through an upcast. A field passed AS AN ARGUMENT leaves the body's sight (cleanup(cts),owned.Add(cts)) and whatever received it may release it; being the RECEIVER is different. - port The editor's fix puts
field.Dispose();FIRST in theDisposebody — unless the body still USES the field (cts.Dispose(); cts.Cancel()throwsObjectDisposedExceptionand compiles), then LAST, and only after a body whose closing statement is a plain call or assignment. - port A
System.Reactive/Rxfile:Disposethat unsubscribes rather than releases is the design.
- port Implemented "through a base type" too (the entity's own interface list, typed). Matches the design.
- port A COMMENT on the handler is the author acknowledging the swallow
(
catch { } // best-effort icon) — a decision, not an accident, and not worth a note. (The F# side's comment-based acknowledgement; keep it — it is not a suppression comment, it is the author's own prose.) - port A
whenfilter that never looks at the exception (catch when (watch)) still swallows every one; a filter on the exception itself is a decision. - port Value fallbacks: a VARIABLE (
catch { return path; }returns the input as if the work succeeded), a tuple or record carrying a default in one slot, aMaxValuesentinel; a union case that CARRIES the failure (Error "x",Failure, a userParseError) — C#: returning aResult/OneOferror, anExceptionobject, abool falsefrom aTry…probe — is quiet. - port The
boolprobe idiom is checked against the try BODY: the body must answer with the OPPOSITE literal (try { ping(); return true; } catch { return false; });try { return Parse(s); } catch { return false; }disguises the failure. - port The GUARD offer: a body of pure arithmetic over names and
literals with exactly one non-literal INTEGER or DECIMAL divisor — wait:
decimal
+/*//throwOverflowException, so the catch guarded more than the division and no zero check can replace it — INTEGER only (the design says "integer or decimal": correct it); float division never throws; a dotted operand is only as pure as the typed tree proves (opt.Value,lazy.Value,s.Lengthare getters and throw); undercheckedcontext every+/-/*throws and no guard is offered; the zero is spelled in the divisor's own type (0,0L,(byte)0). - port The IO-only narrowing needs the typed tree to agree that every
CALL on the line is
System.IO's: the text smell alone narrowedSome(Path.GetFileName d, Checkpoint.loadMetadata p)and a JSON exception escaped (Fuuga); assembly-loading and font-lookup probes were put back by hand. - port The LOG LINE offer needs a logger REACHABLE from the catch: a
parameter of the enclosing method, a field, a local whose scope holds
the site — never one from another method (a
loggerfrom one function was written into six that had none); the exception name is the handler's binder or a freshex(unless the enclosing declaration already bindsex); the logger itself is not a parameter worth logging. - port Teardown idiom: one
Dispose/Close/Shutdown/Cancel/Complete/Delete/Resetcall, optionally followed byx = null— a lower note. - port Probe APIs that answer for a missing path instead of throwing
(
File.Exists,Directory.Exists,File.GetLastWriteTime) — the advice is to delete the try. - port A catch-all after an earlier arm that RETHROWS cancellation, or
followed by an unconditional failure (
try { Environment.Exit(n); } catch { } throw …;), is a decision. - port The catch-all patterns are
catch,catch (Exception), a bare binder;catch (SystemException)is not a catch-all.
- port (CR0066) Raises the
finallyitself catches (a nested try inside it) stay quiet. - port (CR0068) The fault-injection dispatch table: a
switchwhose sibling arms raise three or more DISTINCT exception types (FCS'sSimulateException) stays quiet — the design has it; addAccessViolationException,ExecutionEngineExceptionto the list, andthrow new Exception(…)itself is CA2201's; the F# rule does not report plainException(the design's CR0068 does — decide: CA2201 covers it, so CR0068 yields there).
- port The members are
Equals,GetHashCode,ToString,Dispose(and, for C#, a static constructor,Finalize, an implicit conversion,==/!=— the CA1065 list); raises inside the member's owntrystay quiet;throwthroughraise <| X()/X() |> raisespellings — C#: athrowexpression (?? throw) inside these members counts too.
- port The parameter's TYPE must print usefully: primitives, strings, enums, records/tuples of those, options and lists of them; a class, an array, a function, a generic parameter, a compiler-tree node prints its type name — a method with no such parameter gets NO note at all.
- port The message mentions a parameter as a WORD (
xinside "no text property" is not a mention); the message is not the method's own name (fslex's fallthrough); not an invariant ("unreachable", "not possible", "NYI", "internal error", "invalid case"); no{,}(or%in F#) in the literal; no verbatim/raw strings; 1–4 parameters; a secret-smelling name on the method, its type, its namespace or a parameter (auth, session, crypt, token, password, secret, credential) — Suave threw on freshly decrypted session data. - port The rewrite puts argument VALUES into the message: the hint says so (a PII decision on personal data).
- port
let f = function … | _ -> failwith— the wildcard arm is named to be quoted; C#: aswitchexpression's_ => throw …inside a method quotes the method's parameters — n/a. - port Never in a test file (the runner names the test and inputs).
- port A NESTED handler inside the clause may bind the same name to a different exception: reads inside it are never fixed (a fix that does not compile).
- port A
.Messageread inside an INTERPOLATED string hole is reported but never fixed (F#: the replacement's quotes cannot sit in a hole; C#:$"{string.Join("; ", …)}"is legal since C# 11 raw/nested quotes — still keep it note-only inside a hole for C# 10 and below). - port The chain must STOP at
.Message:e.Message.Lengthcovers the whole chain and replacing it would drop.Length. - port The rethrow the carry-on replaces must be
throw;orthrow e;— NOTthrow new Wrap("…", e): a deliberate wrap changes the thrown type; and only in a TAIL position of the handler (athrowinside a unitiffollowed by more statements is not a value position). - port The tested type is resolved by ENTITY, so a user type of the
same short name never matches; reading the informative member in the
clause's
whenfilter counts as informed. - port The carrier table:
ReflectionTypeLoadException→LoaderExceptions/Types,WebException→Response; the design addsAggregateException→InnerExceptions/Flatten()andSqlException→Errors/Number(F# lists them as future slots "once each has a real site to verify against") — mark those two as unverified in C# too, plusFileNotFoundException→FusionLog.
- port Beside a SIGNATURE-like contract only a private declaration may
change shape (F#: a
.fsi; C#: a PUBLIC API baseline —PublicAPI.Shipped.txtof the PublicApiAnalyzers, or a reference assembly project — is the C# analogue; when one is present, aninternal/publicshape change stands down). - port "Nothing outside the assembly can see it" is true of an
executable, but a LATER FILE of the same executable can, and consumes
the declaration at its current shape: a rule whose in-place rewrite
changes a binding's TYPE (CR0023's set conversion) must ask the other
files too. C# has no file order, so the question is "any other file of
the compilation", answered by
FindReferences— the same all-or-nothing edit set. - port A script (F#) is the ultimate leaf; C#: top-level statements make the compilation an Exe — same answer.
- port
--api-changesis held back, flag or no flag, when a consumer of another language references the compilation and no verification of this run can build it (PublicSurfaceHeld).
- port A record whose fields are READ inside an expression tree
(
Expression<Func<…>>lambdas, query expressions overIQueryable) stays a class: a struct local captured in a quotation cannot have a field read (that takes its address, which a quotation may not do — Linq.Expression.Optimizer'squery { … sl.x = j.x … }). C#: an expression tree CAN read a struct's field, but areadonly record structcaptured in a closure inside an expression tree copies — behaviour change on mutation only, and the record is immutable; keep the veto forIQueryablelambdas since providers translate struct members differently (EF Core does not support struct entities). - port (FR0016) 2–3 cases, every payload a whitelisted small immutable value type spelled as a PLAIN identifier — no strings (reference type is legal in a struct union but signals a bigger payload), no generics, no options, no recursion; when more than one case carries fields all fields must be NAMED and same-named fields across cases must agree on TYPE (FS3585). C#: no unions yet — n/a until C# unions land, then port.
- port The attribute goes below any XML doc, so it sits against the
type it marks (C#:
readonly record structis a keyword change, but a[StructLayout]-style attribute insert would follow the same rule). - port Only the TYPE's own visibility counts (a private representation still leaves a public class-vs-struct type visible).
- port ALL-OR-NOTHING over the typed uses: every construction assigns
a LITERAL tuple (an arbitrary expression of tuple type would change type
under it), every read destructures into a literal tuple pattern or
compares against a literal tuple;
Item1/a binder/the field passed along whole starts dataflow the scan does not follow and keeps the field a note; a field with ZERO uses stays a note (nothing proves the shape); a#loading script is a call site the project cannot see (C#: a linked file compiled into another project — the design's linked file rule). - port Capped at four elements (a struct tuple is copied by value); already-struct tuples and unit-of-measure segments are left alone.
- port (CR0084) The accessibility of
let mutable private xparses onto the pattern, not the binding (F# quirk — n/a); the uppercase no-argument binder shape counts too (n/a); assigned at most once in this file and never from itself → quiet (the design has it).
- port
x.GetType().FullName == "…"is the same shape as.Name. - port Quiet inside a
whenguard of a:? T as xclause (C#: acase T x when x.GetType() == typeof(T)narrows to exactly T on purpose — FCS retries a locked file only on a plainIOException); the guard may sit deeper than the top-level comparison.
- port Every
this.<slot>reference inside a CONSTRUCTOR-TIME expression counts — assignment right-hand sides, loops, try blocks, field initialisers (C#: field initialisers run before the base constructor; a virtual call in one is the same hazard). - port Scoped to the members declared in the SAME type definition
(shadowing-proof, single-file); C#: partial classes span files —
FindReferenceson the type's members instead.
summary of the flow proof is faithful. Extra conditions worth carrying:
- port A
Result<_, string>'sError "…"exits are sources and itsError "…"arms the consumer; theOkside is not followed (C#: aOneOf/Resulterror string, or anout string error). - port A variable pattern spelling a module-level constant's name
beside later arms (
| us -> 2underlet us = "…") is treated as the comparison the author meant; C#:case var us:under aconst string us— same trap, same reading. - port The union's name gets
Kindappended where the project already has the type; two unions in one file never share a name (a second choice carries the record's name first). - port A union added by the rule carries the WIDEST visibility of the slots it types — never public unless a public slot is among them.
- port The serializer guard reads the VALUE handed to a reflective
head, not only a type argument: a record (or a collection of one)
passed to
JsonSerializer.Serialize, behind a field or property, or anywhere along a curried call. - port A sentence of more than four spaces keeps its words behind
double backticks in F#; C#: an enum member cannot be a sentence — a
literal that makes no identifier (spaces, punctuation, a leading digit)
stands the rule down or gets a
[Description]-style attribute (a design decision to make at v2). - port The
ToStringoverride returns the original text so logs read as before; C#: an enum cannot overrideToString— the design'sToText()extension, and every print site ($"{x}",x.ToString(),string.Concat) must call it explicitly, which is a larger edit than the F# one.
- port The
DateTimeprefix must REALLY beSystem.DateTime: a shadowing fake-clock type would take the rewrite, compile, and switch to the real clock; the field is confirmed by SYMBOL, not name (a same-named field on another type must not vouch for it). - port At least one real write pins the clock;
NowandUtcNowmust not mix across the WHOLE migration;.Dateescapes (returnsDateTime),ToStringformats differently — bail. - port File-private types only in this first cut.
- port At least THREE operands — a two-term
path + ".bak"reads fine as it is — and at least one literal AND one non-literal. - port Cheap syntactic pre-gates run before symbol resolution.
- port An UNANNOTATED parameter the chain alone typed as a string (F# inference): n/a in C#.
- port String
+translates in query expressions;string.Concat/ interpolation may not: stand down inside an expression tree. - port The editor's alternative is the explicit
string.Concatcall; the interpolation is the primary because it reads better and compiles to the sameConcatat the rule's hole cap.
- port An even run of
%before a specifier means the leading one is escaped (F#%%); C#:{{/}}in astring.Formattemplate stay doubled in the interpolation — same escape, n/a for%. - port Parentheses that only WRAPPED the call go with it (
(sprintf …)became($"…")), but stay where they may be doing more — a method's argument list, a receiver, an indexer; and an operator touching the paren would swallow the$(~~$"…"is an operator name in F# — n/a, butx+$"…"reads fine in C#). - port One SIMPLE argument per specifier: an identifier, a dotted path, a non-string constant — an argument holding braces or nested quotes stays.
- port A fill under a TYPED hole (
%s{x.ToString()}) is left alone — the specifier pins the type; C#: a hole with a format ({x.ToString():N2}) is already excluded by the design; a hole whose type isobjectand whoseToString()is the only conversion the target-typed handler would not do differently — n/a.
- port A
FormattableString/IFormattableEXPECTED at the site keeps the$: a type annotation, or a method parameter of that type (Fable'slet s: FormattableString = $"…"lost its$and stopped compiling; Ionide'sLog.setMessageI $"…"). With the typed tree the callee's signature answers; WITHOUT it any application argument keeps its$. C#:FormattableString,IFormattable, and a customInterpolatedStringHandlerparameter (ILogger's,Debug.Assert's handlers!) — an interpolated string handed to one is NOT a plain string conversion; the speculative check catches the conversion error, and the typed rule must check the target parameter type. This is a live defect in the shipped CR0103: it is parse-only and never checks the target type. - port A
%%in the text (F#) — n/a;$$"""…"""raw with no hole loses every$(F#); C#: a raw interpolated string$"""…"""with no hole is skipped by the shipped rule — fine, but$$"""…"""(C# 11) should be treated the same.
- port Operand ORDER decides exactness:
isNull x || x = ""(null check LEADS) is exact;x = "" || isNull xis exact only while the leading test cannot throw —x.Trim() == "" || x == nullthrows on null in the original, so the Trim spellings in that order ride editor-only. - port
x.Trim().Length == 0is a Trim spelling too;string.IsNullOrEmpty(x.Trim())→IsNullOrWhiteSpace(x)(editor). - port A backticked/escaped identifier subject is respelled from its
source text (C#:
@namekeeps its@). - port Inside a query expression/expression tree the whole rule stands
down (the translator may know
||and==but notIsNullOrEmpty).
- port Inside an expression tree the WHOLE suggestion stands down, note
included: a LINQ provider resolves
Parseby signature and the two-argument overload can turn a translatable call into a runtimeNotSupportedExceptionthat compiles clean. - port The short
CultureInfo.Xspelling under an existingusing System.Globalization, fully qualified otherwise; a juxtaposedParse sgains parentheses (n/a).
- port
dt.Date != DateTime.Today— a same-day test against a date THIS MACHINE produced — is the same clock on both sides, not the calendar-cut bug. - port An expression-tree TRANSLATOR reproduces the clock on purpose:
the arm that maps a member NAMED
Now/Todayto the call (SQLProvider's evaluator) is a translation table, not a clock read — the nearest enclosingswitch/ifnames the member in its condition. - port
DateTimeOffset.Nowstays quiet entirely (it carries its offset);Nowread as an INSTANT (.Ticksas a version number goes backwards at DST fall-back,.ToBinary,.ToFileTime) gets the rewrite;Now.ToString(…)renders the local calendar and gets the note only. - port Only a clock read pays for the scan of its enclosing arm (performance of the rule itself).
of the pattern with the call's own RegexOptions (a pattern legal under
IgnorePatternWhitespace may be illegal without it).
- port ANY string literal spelling qualifies (
@"\d+"is the ordinary way to write a regex); the literal is re-emitted VERBATIM, so a pattern carrying a quote, a control character or a backslash is refused for the string-operation rewrite (the decoded text would need re-escaping). - port A
Replacewith a$anywhere in the replacement, an empty pattern, an anchored pattern, a backslash in either, or aRegexOptions/MatchEvaluatorargument is refused (design has most; add backslash and the verbatim re-emission rule). - port
StartsWith(string)is CURRENT-CULTURE and differs on ligatures, ignorable characters and Turkish i — theOrdinaloverload says what the regex did;Contains(string)is ordinal already.
- port A hoisted binding lands above the enclosing declaration's
comment block (contiguous
//lines at the declaration's column, never a comment trailing the declaration above), and under the same#ifas the call; the name is derived from the pattern text and a second hoist deriving the same NAME collides (only the first keeps its fix); a bareRegexresolves only under ausingthat precedes the insertion point (ausingfurther down or in a sibling scope is no help). - port Only a parenthesised method call hoists (
Regex.Match(x, "p").Successis the call's receiver; a juxtaposed F# spelling would hand the continuation to the argument — n/a). - port A construction spanning lines carries its indentation into the
binding: single-line only; a
let regex = azAZRegexalias left behind is harmless. - port The string-operation rewrite SUBSUMES the hoisting advice on the same site; a construction the hoist declines is FR0037's note (CR0110), and one it fixes silences that note.
- port Hoistable methods:
IsMatch,Match,Matches,Split(Replacetoo in C#).
- port The set:
ConcurrentDictionary,HttpClient,JsonSerializerOptions,Regex,SearchValues.Create; a probe of the loop variable itself never fires; a lambda handed to a collection function is a loop; aletbetween the loop and the site may rebind per iteration.
- port BOTH separators need positive evidence now (a lone backslash
used to be path-ish on its own until FsAutoComplete's escape-sequence
building —
result + "\\" + c— showed where that goes wrong); the design says\\fires alone: correct it. - port A separator only JOINS when the chain has text on BOTH sides:
dir + "/"appends a marker and"/" + nameprefixes a root — neither is aPath.Combine; dot-segments ("./" + p,p + "../") are relative-path notationPath.Combinecannot spell. - port A chain opening with a forward-slash literal (
"/img/" + id) is as likely a web route and needs the STRONGER evidence (a rooted or extension-bearing literal, or one that exists on disk); a path-flavoured NAME is too weak there (fileIdmatches "file"). - port The file's own name says what it builds (
JsonRuntime.csjoins JSON pointers); a name bound one hop away to something URL-shaped (gitHome = "https://…" + owner) makes the chain a URL; a chain compared or searched for ("content/" + n.file == page,set.Contains(chain)) is a key. - port Contexts that must stay compile-time constants —
constinitialisers, attribute arguments — never get the note (Path.Combineis a call). - port
Path.Combinetreats a ROOTED second argument as absolute (the first is discarded) — the concatenation does not; hence note-only.
a REGULAR string literal (comments, identifiers, verbatim and raw strings where escapes do not exist stay notes).
- port
int64within a factor of SIXTEEN of the ceiling (ten-digit int64s are ids, eighteen-digit ones are magnitudes);MaxValue + e/MinValue - eoverflow for every e but zero, whileMaxValue - eis the sentinel arithmeticRandomdoes on purpose and stays quiet. - port The widening offer casts EVERY operand to
long, spells every literal withL, runs the arithmetic wide and narrows back withchecked((int)…); thechecked(…)offer second.
- port The template may be a
"…" + "…"chain of literals; a trailing array LITERAL is the params array spelled out; one trailing IDENT argument may be the params ARRAY passed whole — its count is invisible, so no arity claim; a hole-free$"…"compiles to a constant and is not the interpolation defect; placeholder syntax{@Name},{$Name},{Name:format},{Name,align},{{literal. - n/a Logary pipelines.
- port The exception-first overload only pairs with a template in
FIRST position —
LogError(eventId, "msg")wants the exception SECOND (insert after theEventId); Serilog'sError(ex, …)and the Microsoft.Extensions.Logging methods by their own level names.
- port The text is followed ONE HOP through the nearest enclosing local or a static field of this file; a parameter resolves to nothing — the caller is where the string was built and the caller's site is the one reported.
- port Sinks named for SQL (
executeSql,runQuery,sqlExec,queryDb) count; theFormattableStringAPIs never fire (design has it).
plain literal with no parameter marker in ANY dialect (@name, :name,
?, $1).
- port The editor's alternative splits an interpolated template into
the ARGUMENT LIST a shell would see — whitespace separates, a quote pair
keeps its contents together and is dropped (
+x "{path}"is two arguments); a format specifier in a hole ({n:N2}) is not followed; a SHELL executable (cmd,cmd.exe,sh,bash,zsh) takes a command line by design, and an argument list would change what runs — note only there.
- port The pattern set includes Stripe/Svix (
sk_live_,whsec_), a three-segment JWT (eyJ….eyJ….sig),Bearer eyJ…, an Azure storageAccountKey=, and a connection string only when another connection KEY sits beside the password; placeholder passwords (password,test,changeme,<…>,{…},%…%,$(…)) are samples; the literal parts of an interpolated string are scanned (a key with a hole in its middle is still a key); C#:const stringis the[<Literal>](CR0124), and a source-generator/analyzer attribute argument the type-provider static argument analogue.
the sibling-arm SHA-256 exemptions are in the design; add: SHA-1 in one
arm of a switch whose sibling constructs SHA-256 or stronger is a format
option the caller chose (the F# compiler's --checksumalgorithm).
- port The factories return the BASE type (
SHA256.Create()isSHA256, notSHA256Managed): any OTHER mention of the obsolete name in the file — a type annotation, anistest,typeof, a generic argument — can break the build or change a type test's meaning; each rewrite site mentions the name exactly once, and any surplus textual mention VETOES that name.
- port A type declared in THIS FILE under the short name would win the
attribute lookup after trimming (attribute resolution tries the exact
name before appending
Attribute) — the speculative check covers it; the syntactic guard is cheaper.
- port Knobs
maxAttributes(4) andwrapColumn(110): past either the rule stands down rather than inventing a wrapped layout; a comment between the brackets suppresses; attributes with a TARGET ([assembly: …],[return: …],[field: …]) keep their own brackets.
underscore-only name stays quoted (@_? — C# _ is a discard: keep @_).
- port The namespace comes from the ENTITY at each qualified name, so
the longest namespace wins by construction and a module/type prefix is
never mistaken for a namespace (toro's
Toro.noGrad— the moduleToroof namespaceToro, already open — was once left a barenoGrad); a constructor is spelled as its type; an ASSIGNMENT TARGET is a spelling too (System.Diagnostics.Trace.AutoFlush = truekept its prefix while the reads lost theirs); a pattern head that stopped resolving would silently become a binder — only a spelling that resolves is shortened. - port Every top-level namespace block of the file has its own usings
and its own place for a new one; the insert goes among the file's
usings in alphabetical order within its family (
System.Collections.GenericafterSystem.Collections,Systemabove both), else after the last using, else under the namespace header, never between a declaration's doc comment and the declaration; a file-scoped namespace andglobal usings are the C# wrinkles. - port A namespace the file ALREADY opens shortens at any count (that case is IDE0001's in C# — the design defers it).
- port Early-out before the typed check: a namespace can only qualify when its first segment recurs at least as often as the smaller threshold; one typed lookup per DISTINCT spelling, not per occurrence.
- port The clash check is by MECHANISM against every namespace alike
(the file's own definitions, every name it uses unqualified, other
opened namespaces and modules, an extension method the new namespace
exports named like a method the file calls); every prefix of the file's
own namespace is "own" too (a file in
Company.Product.Dataneed not openCompany.Product).
- port A trailing note must READ as a summary: a punctuation marker
(
// ^ index,// -- node), a single word (// unused), fewer than 12 characters, or a code fragment (// fun x -> x) is a margin annotation, and a doc line made of it is worse than none;<and&are XML syntax (escaping would break the contains-the-original comment-loss proof). - port The comment must END its line, real code must precede it on the
line, and it must sit on the HEADER line (the one the declaration
keyword starts); with attributes above, the insert lands at the keyword
line and a
///between an attribute line and its declaration is a misplaced-doc warning (C#:CS1587). - port Test files: a fixture's trailing note labels the fixture and documents nothing.