dotnet/roslyn

False positive CS8619 warning using `-=` with `byte?`

Open

#82552 opened on Feb 26, 2026

View on GitHub
 (1 comment) (0 reactions) (0 assignees)C# (20,414 stars) (4,257 forks)batch import
Area-CompilersBugFeature - Nullable Reference Typeshelp wanted

Description

Version Used: 9.0.205

Steps to Reproduce:

Compile a file a file containing

byte? b = 1;
b -= 1;

.NET Lab link: https://lab.razor.fyi/#41Li4gooyk8vSszVSy4WEkmqLEm1V0hSsFUwtOZKUtAF0V5MycVRnByXPn05NTldgCWBsYIRAA

Diagnostic Id:

Nullability of reference types in value of type 'int?' doesn't match target type 'byte?'.CS8619

Expected Behavior: No warning, since subtracting 1 from a nullable byte is fine.

Actual Behavior: CS8619 warning appears.

Note: Even if somehow there should be a warning since -= should never be used with byte? types, there still is a bug here in that the warning message is incorrect, since the nullablility of int? does match the nullability of byte?.

Contributor guide