Skip to content

Conversation

T-Gro
Copy link
Member

@T-Gro T-Gro commented Feb 24, 2025

Fixes #17988

In the object model, overrides for originally nullable slots can narrow the return type from nullable to not-null.
This was added especially in the context of ToString(), which is by default nullable, but most common implementation just return string.

However, the relaxation from a Withnull return type to a nullness inference variable has been done even for generic code, one that has been explicitely instantiated with a nullable type in place for T.

This changes the "nullable relaxation for overrides" to stop applying in the case of generic return types (i.e. it will not attempt to relax those, and instead keep the exact type which was passed in.).

@T-Gro T-Gro linked an issue Feb 24, 2025 that may be closed by this pull request
7 tasks
@T-Gro T-Gro changed the title 17988 nullness not correctly inferred for returned value Nullness :: Improvement :: Overrides of generic methods with nullable type instantiations Feb 24, 2025
Copy link
Contributor

github-actions bot commented Feb 24, 2025

❗ Release notes required


✅ Found changes and release notes in following paths:

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/9.0.300.md

@T-Gro T-Gro marked this pull request as ready for review February 24, 2025 17:17
@T-Gro T-Gro requested a review from a team as a code owner February 24, 2025 17:17
@abonie abonie merged commit 1e244bd into main Feb 25, 2025
33 checks passed
@T-Gro T-Gro deleted the 17988-nullness-not-correctly-inferred-for-returned-value branch February 25, 2025 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

nullness not correctly inferred for returned value

3 participants