Skip to content

+semver:minor Migrate core library to use nullable reference types - #169

Open
imnasnainaec wants to merge 7 commits into
masterfrom
enable-nrt-core-merge-in-master
Open

+semver:minor Migrate core library to use nullable reference types #169
imnasnainaec wants to merge 7 commits into
masterfrom
enable-nrt-core-merge-in-master

Conversation

@imnasnainaec

@imnasnainaec imnasnainaec commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Supersedes #157, merging in master (conceptually applying NRT to all new code, not just mechanically resolving the 3 files with merge conflicts).

Devin review: https://app.devin.ai/review/sillsdev/l10nsharp/pull/169


This change is Reviewable

hahn-kev and others added 7 commits July 9, 2026 13:26
…o 9, and add PolySharp to be able to use nullible attributes.
* Address NRT review feedback and clear remaining warnings

- MapToExistingLanguageIfPossible now returns the empty string (not null)
  for empty input, honoring its [return: NotNullIfNotNull] contract.
- Removed the incorrect [MemberNotNullWhen(false, Id, Source, Target)] from
  XLiffTransUnit.IsEmpty: IsEmpty is a conjunction, so !IsEmpty does not
  imply all three members are non-null. Adjusted ToString and
  XLiffBody.AddTransUnitRaw, which relied on that bogus guarantee.
- DefaultInstalledStringFilePath now throws a clear InvalidOperationException
  instead of passing a possibly-null folder to Path.Combine.
- StringCache is backed by a nullable field and throws a clear
  InvalidOperationException instead of being `null!` and NREing when the
  minimal constructor was used.
- MergeXliffDocuments hoists the trans-unit id once per iteration and skips
  units without one, replacing ten null-forgiving `tu.Id!` uses.
- Fixed the four remaining warnings: CS8604 in XLiffBody (hoisted documented
  locals) and CS8618 for DefaultStringFilePath (defaults to string.Empty).

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Bring in the pseudolocalization (qps-ploc) support and the BingTranslator
replacement, and give the code they added the same nullable-reference-type
treatment as the rest of the core project:

- PseudoLocalization.Transform / LocalizationManager.PseudoLocalize are
  annotated string? -> string? with NotNullIfNotNull, matching what they
  already do (and what PseudoLocalize_NullOrEmpty_ReturnedAsIs asserts).
- The pseudo-locale paths that must return non-null now say what they fall
  back to when neither the caller nor the English cache has any text, using
  the same fallback the surrounding non-pseudo path uses: string.Empty in
  GetDynamicStringOrEnglish and XliffLocalizationManager.GetLocalizedString.
  Previously these returned null from methods declared to return a string.
  GetStringFromStringCache / GetTooltipFromStringCache keep returning null,
  which is how the WinForms localizers know to leave the designer text alone.
- The translators moved into the core project are annotated for the nulls
  they already produce and consume: TranslateText / InternalTranslate /
  PostTranslateProcess return string?, RemoveAcceleratorAmpersands is
  NotNullIfNotNull, MicrosoftTranslator's key/region config is string?
  (Environment.GetEnvironmentVariable can return null), and the members
  deserialized from the Azure and MyMemory JSON payloads are all nullable.

Conflict resolutions of note:

- MapToExistingLanguageIfPossible keeps the branch's null/empty handling and
  adds master's pseudo-locale bail-out.
- GetDynamicStringOrEnglish takes master's EnglishTextOrFallback helper,
  which subsumes the branch's inline englishText handling; the helper's
  englishText parameter is nullable, as its callers' is.
- L10NSharp.csproj keeps PolySharp alongside master's dependency upgrades.
- The CHANGELOG entry for NRT moves to [Unreleased], since master has since
  cut 11.0.0, and now names the public annotation change (GetLocalizedString)
  rather than implying the internal interfaces affect consumers.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Sep 9, 2026

Copy link
Copy Markdown

Test Results

    7 files  ±0  148 suites  ±0   23s ⏱️ -1s
230 tests +1  225 ✔️ +1    5 💤 ±0  0 ±0 
886 runs  +4  871 ✔️ +4  15 💤 ±0  0 ±0 

Results for commit 025aa76. ± Comparison against base commit 74fddd7.

@imnasnainaec
imnasnainaec marked this pull request as ready for review September 9, 2026 13:20
@imnasnainaec imnasnainaec changed the title Migrate core library to use nullable reference types +semver:minor Migrate core library to use nullable reference types Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants