dotnet/roslyn

Nullability warning is missing on the lock statement

Open

#76,597 opened on Jan 2, 2025

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

Repository metrics

Stars
 (20,414 stars)
PR merge metrics
 (Avg merge 6d 17h) (256 merged PRs in 30d)

Description

Version Used: 17.13.0 Preview 2.1

There is no nullability warning for lock (null) { } or lock (maybeNullExpr) { }, even though a null at runtime throws ArgumentNullException.

Expected

A nullability warning such as:

  • CS8604 - Possible null reference argument for parameter.

    • More literal, similar to how await or foreach simply reflect the warning you'd get if you had manually called GetAwaiter()/GetEnumerator().
  • CS8602 - Dereference of a possibly null reference.

    • A step back, if calling expr in lock (expr) a "parameter" is leaking too much information about how lock is being lowered.

Or, one in the same vein as "CS8597 Thrown value may be null."

Contributor guide