Skip to content

Conversation

@Remscar
Copy link
Contributor

@Remscar Remscar commented Jan 28, 2026

Summary

Fixes two distinct issues of nullable compiler warnings in the code generator by adding null-forgiving operators (!) in several places.

Issue 1

If you had a sbox project with nullables enabled then whenever you use a [Sync] attribute you'd get warnings in console.

Issue 2

If you are using a nullable type Type? and [Sync] you will get warnings. This issue describes the initial problem #215

Motivation & Context

For awhile now if you used a nullable type Type? with [Sync] you'd get a warning.

Since 26.01.28 update's network optimization warnings appear with nullables enabled in project settings if you use [Sync].

01:39:48   Compiler CS8618 Non-nullable field '__WishVelocity_SyncAttribute__CachedSetter' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
01:39:48   Compiler CS8618 Non-nullable field '__WishVelocity_SyncAttribute__CachedSetterGetter' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
01:39:48   Compiler CS8618 Non-nullable field '__WishVelocity_SyncAttribute__CachedGetter' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Nullables is an option in Project Settings, i personally prefer having them enabled and I think you should be able to use them without being penalized by having compiler warnings.

Fixes: #215

Implementation Details

There were two ways this could be solved, I used the less invasive approach of essentially doing value! which will silence any null warnings.

The alternative way would be to properly type things as nullable type? myVariable = etc
This alternative though require us to wrap all generated code with #nullable enable/disable and would require more invasive changes.

Tests

Some tests were updated as a result of the changes.

Checklist

  • Code follows existing style and conventions
  • No unnecessary formatting or unrelated changes
  • Public APIs are documented (if applicable)
  • Unit tests added where applicable and all passing
  • I’m okay with this PR being rejected or requested to change 🙂

Copilot AI review requested due to automatic review settings January 28, 2026 21:45
@Remscar Remscar changed the title [CodeGen] Fix compiler warnings related to [Sync] when using nullable [CodeGen] Fix compiler warnings related to [Sync]/[Property] when using nullable Jan 28, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes nullable compiler warnings in the code generator by adding null-forgiving operators (!) in strategic locations throughout the generated code. The changes address CS8618, CS8601, and CS8603 warnings that occur when projects have nullable reference types enabled and use attributes like [Sync] that trigger code generation.

Changes:

  • Added = null! initialization to cached delegate field declarations to suppress CS8618 warnings
  • Added null-forgiving operators to value assignments, return statements, and null literal expressions in generated code to suppress CS8601 and CS8603 warnings
  • Applied null-forgiving operator conditionally to getter lambda bodies when they are expressions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@Remscar Remscar changed the title [CodeGen] Fix compiler warnings related to [Sync]/[Property] when using nullable [CodeGen] Fix compiler warnings related to [Sync] when using nullable Jan 28, 2026
@kurozael kurozael added the triaged triaged pull-requests are replicated on the internal sbox repo label Jan 28, 2026
@kurozael kurozael self-assigned this Jan 28, 2026
@kurozael kurozael removed the triaged triaged pull-requests are replicated on the internal sbox repo label Jan 28, 2026
@Remscar
Copy link
Contributor Author

Remscar commented Jan 28, 2026

Fixed tests and updated description

@kurozael kurozael added the triaged triaged pull-requests are replicated on the internal sbox repo label Jan 30, 2026
@sboxbot sboxbot added the accepted this pull request was accepted, hurrah! label Feb 2, 2026
@sboxbot
Copy link
Contributor

sboxbot commented Feb 2, 2026

This PR has been merged upstream.

@sboxbot sboxbot closed this Feb 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

accepted this pull request was accepted, hurrah! triaged triaged pull-requests are replicated on the internal sbox repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Sync] emits warnings when using a nullable type

3 participants