Skip to content

Read a covariant return override as an override - #98

Merged
Mpdreamz merged 1 commit into
mainfrom
covariant-overrides
Nov 14, 2026
Merged

Mpdreamz merged 1 commit into
mainfrom
covariant-overrides

Conversation

@Mpdreamz

Copy link
Copy Markdown
Contributor

Generating the libraries' own .api files turned up a reader bug: on net10.0, the records' <Clone>$ showed as public virtual ApiArrayType <Clone>$() instead of an override.

C# emits an override with a covariant return type as a new virtual slot. It marks the slot with PreserveBaseOverridesAttribute so the runtime still treats it as overriding the base method. The reader took the new slot at face value. Roslyn reads it as an override, and now so does the reader:

  public class Dog : Animal
    public override Dog Clone()

  public sealed record Employee : Person, IEquatable<Employee>
    public override Employee <Clone>$()

The Roslyn oracle missed it because none of the six framework assemblies has a covariant override in its public API. The samples now include a covariant override and a sealed record deriving from another record. Without the fix, the oracle fails on them:

roslyn: public [override] Lib.Drawing.Employee()
ours:   public [virtual] Lib.Drawing.Employee()

The JustAssembly-compatible reports are unchanged: all 617 tool tests pass.

🤖 Generated with Claude Code

C# emits an override with a covariant return type as a new virtual slot marked with PreserveBaseOverridesAttribute,
so the reader showed it as virtual. Roslyn reads it as an override, and so does the reader now; the comparison then
treats it as one too, such as an override that is removed being still found through the base.

The samples gain a covariant override and a sealed record that derives from another, which the Roslyn oracle checks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Mpdreamz Mpdreamz added the bug A defect fixed (patch) label Nov 14, 2026
@Mpdreamz
Mpdreamz merged commit 345a83a into main Nov 14, 2026
6 of 7 checks passed
@Mpdreamz
Mpdreamz deleted the covariant-overrides branch November 14, 2026 19:37
Mpdreamz added a commit that referenced this pull request Nov 14, 2026
The libraries now use their own feature. `api/` holds the public API of
`Nullean.PublicApi` and `Nullean.PublicApi.Diff` as `.api` files,
written by the tool built from this checkout. So from now on, a change
to either library's API shows up in its pull request as a diff of those
files.

- **Two files for `Nullean.PublicApi`:** its API differs between
netstandard2.0 and net10.0. Covariant return types need .NET 5 or later,
so on netstandard2.0 the records' `<Clone>$` returns the base type
(`public override ApiTypeReference <Clone>$()` instead of `public
override ApiArrayType <Clone>$()`). Generating these files is how #98
was found.
- **`./build.sh ci` and CI's build job run `verifyapi`:** CI calls the
targets one by one, so `verifyapi` is its own step there, and the run on
this branch printed `[api] api matches the build: 3 files` on Linux. The
target fails when the build no longer matches `api/`. `mise run api`
regenerates the files after an intended change, and AGENTS.md says to
commit them with that change. CI runs the tool from the checkout,
because the released `verify-api` action can't run `api` until the next
release.
- **The update command `--verify` prints** now carries the `--project`,
`--include-tests` and `--include-unpackable` options it was run with.

Checked locally: `verifyapi` passes on this branch. With a public method
added to `ApiWriter` it fails with exit 5:

```
[api] Nullean.PublicApi.net10.0: 1 change since the committed files, suggested version change: Minor
  api/Nullean.PublicApi.net10.0.api:457  Nullean.PublicApi › ApiWriter › Probe()  added public static int Probe()  [minor]
[api] Nullean.PublicApi.netstandard2.0: 1 change since the committed files, suggested version change: Minor
  api/Nullean.PublicApi.netstandard2.0.api:457  Nullean.PublicApi › ApiWriter › Probe()  added public static int Probe()  [minor]
[api] api does not match the build. Suggested version change: Minor
```

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug A defect fixed (patch)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant