csharpc

15 — Conformance corpus 2 (adversarial edge cases)

The first corpus (09-conformance.md, 195 programs) reached 100 % — but it was written alongside the compiler, so it mostly tested what we already thought of. tests/conformance2/ is a second, deliberately adversarial corpus: 258 short programs aimed at C# spec corners and BCL edge cases where a compiler can silently get the semantics wrong.

Methodology

  • One program per edge case, grouped by spec area (tests/conformance2/<area>/NNN_name.cs).
  • Expected stdout and exit code are recorded from real .NET 11 (dotnet run file.cs), exactly like corpus 1. Programs that did not compile under .NET were fixed (never the expectation).
  • tests/conformance2.sh is tests/conformance.sh pointed at the second corpus (CONF_CORPUS=conformance2); same flags (--regen, -j, --opt, area filters).
  • Failures are triaged by root cause; wrong output (silent miscompilation) is fixed first, then “not supported” diagnostics. Every wrong-output bug got a regression sample in tests/samples/ (140-149, 177-178).

Results

programs passing
first run (241 compiled under .NET; 17 needed fixing) 241 190 (78.8 %) — 14 wrong-output
after fixes 258 256 (99.2 %)
delegate thunks for library method groups 258 257 (99.6 %)

The one failure was filter ordering, which is fixed since: filters run in the first pass, before any finally (04-runtime.md). This corpus is run by hand (tests/conformance2.sh), not by CI; its last full run was at the 99.6 % above.

Merge onto the C# corelib

The corpus was written while string/number formatting still lived in the C runtime. When it was merged after formatting, parsing and the string/char surface moved to the C# corelib, its fixes were carried over there instead of reviving C: the formatting fixes (exact integer digits, custom-format literals/escapes/scaling, invariant currency negatives, -0) and Replace("")/Unicode char classes were already correct in corelib/Number.Formatting.cs / StringOps.cs. The remaining C helpers (strings2.c) became C#: string members with StringComparison, Split(char, count, options), StartsWith/EndsWith(char), string.Equals(object) (StringOps.cs), StringBuilder.AppendFormat, Console.Write(char[]), Math.IEEERemainder; primitive hashes reuse the compiler’s HashOf, and boxed-primitive IComparable/IFormattable slots are generated thunks. The merge also fixed CreateSaturating between integers (it truncated) and compound assignment to an interface property through an interface-typed receiver (N++ in a default interface method crashed); regression sample 179_conformance2_merge_fixes.

Areas: evalorder, overloads, conversions, interpolation, switches, structs, boxing, dispatch, interfaces, generics, generics2, exceptions, closures, lambdas2, iterators, async, linq, records, tuples, nullable, strings, formatting, collections, spans, operators, misc, misc2, patterns, members, numerics, inheritance, initializers.

Wrong-output bugs found and fixed

Bug Regression sample
c[i++] += v evaluated the indexer arguments twice (once for get, once for set) 140_indexer_compound_eval_once
Calling a mutating method on an in / ref readonly struct mutated the caller’s value (no defensive copy) 141_in_param_defensive_copy
long.MaxValue.ToString("N0") went through double (lost precision); -0.0 lost its sign in G17/E 142_numeric_format_exact_integers
Custom numeric formats ignored quoted literals, \ escapes, , scaling, interleaved literals ((###) ###-####) 143_custom_format_literals_scaling
Negative currency used ¤-3 instead of the invariant pattern (¤3) 144_currency_negative_pattern
Type.Name of generic types printed Int32]; typeof(List<string>) dropped type arguments 145_generic_type_names
Static field initializers in interfaces never ran 146_interface_static_initializers
x is IComparable / x is IEnumerable<int> were false for boxed primitives, strings and typed arrays 147_is_interface_on_builtins
char.IsDigit('٣'), char.IsUpper('Ω') and case mapping beyond Latin-1 were wrong 148_unicode_char_classes
Runtime-raised ArgumentOutOfRangeExceptions had no ParamName 149_argument_exception_paramname
"x".Replace("", "y") threw ArgumentNullException instead of ArgumentException 177_replace_empty_argument_exception
Arrays of different tuple types shared one method table (cache keyed by System.ValueTuple2[]`), breaking interface casts 178_tuple_array_method_tables

Other fixes (previously “not supported”): generic virtual methods (closed-world type-switch dispatch), static abstract interface properties (T.Zero on user types), tuple Equals/CompareTo/GetHashCode and boxing, nested tuple deconstruction, Nullable<T>.Equals/GetHashCode, user-defined ++/--, sizeof(T) in generic code, type tests against arrays/tuples, list[^1] on any countable type, StringBuilder.Append($"…") (the interpolated-string handler is represented by the builder itself), generic variance through builtin types, interface dispatch on boxed primitives (IComparable, IComparable<T>, IEquatable<T>, IFormattable), Delegate.GetInvocationList, Environment.ExitCode, StringComparer, MemoryExtensions.Min/Max (what .NET 11 binds for int[].Max()), and a long tail of string/char/Math/BitConverter/generic-math members. Span lowering is now substitution-aware (spans of T inside generic methods).

Remaining failures

Program Root cause Plan
exceptions/003_filter_side_effect_order (at the time) Exception filters ran during the second (unwinding) pass, after inner finally blocks; .NET runs all filters in the first pass. Fixed: filters run from the personality routine’s search phase.

Intentional deviations (documented, not counted as failures)

  • Static initialization is lazy per type with CoreCLR’s triggers, as .NET’s, for the program’s own types; the corelib’s types still initialize eagerly at startup (03-lowering.md).
  • Culture follows the user’s culture like .NET (19-globalization.md); the tests pin the invariant one.
  • Reflection works over compile-time metadata (ADR 0018); FullName of generic types is not assembly-qualified.
  • Threading semantics follow 14-threading.md.