dotnet/roslyn

Nullability warning is missing on the lock statement

Open

#76,597 建立於 2025年1月2日

在 GitHub 查看
 (1 留言) (0 反應) (0 負責人)C# (4,257 fork)batch import
Area-CompilersFeature - Nullable Reference Typeshelp wanted

倉庫指標

Star
 (20,414 star)
PR 合併指標
 (平均合併 6天 17小時) (30 天內合併 256 個 PR)

描述

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."

貢獻者指南