Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MemberNotNull not works for local functions #71092

Closed
GF-Huang opened this issue Dec 5, 2023 · 5 comments
Closed

MemberNotNull not works for local functions #71092

GF-Huang opened this issue Dec 5, 2023 · 5 comments
Labels
Area-Compilers Resolution-Duplicate The described behavior is tracked in another issue untriaged Issues and PRs which have not yet been triaged by a lead

Comments

@GF-Huang
Copy link

GF-Huang commented Dec 5, 2023

Version Used:

Microsoft Visual Studio Community 2022
版本 17.8.2
VisualStudio.17.Release/17.8.2+34322.80
Microsoft .NET Framework
版本 4.8.09032

已安装的版本: Community

Visual C++ 2022   00482-90000-00000-AA567
Microsoft Visual C++ 2022

ASP.NET and Web Tools   17.8.358.6298
ASP.NET and Web Tools

Azure Functions and Web Jobs Tools   17.8.358.6298
Azure Functions and Web Jobs Tools

Azure 应用服务工具 3.0.0 版   17.8.358.6298
Azure 应用服务工具 3.0.0 版

C# 工具   4.8.0-7.23572.1+7b75981cf3bd520b86ec4ed00ec156c8bc48e4eb
IDE 中使用的 C# 组件。可能使用其他版本的编译器,具体取决于你的项目类型和设置。

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Dotfuscator Community Edition   6.5.3+7f0b0a9d18
PreEmptive Protection - Dotfuscator CE

Extensibility Message Bus   1.4.39 (main@e8108eb)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Mono Debugging for Visual Studio   17.8.17 (957fbed)
Support for debugging Mono processes with Visual Studio.

NuGet 包管理器   6.8.0
Visual Studio 中的 NuGet 包管理器。有关 NuGet 的详细信息,请访问 https://docs.nuget.org/

Razor (ASP.NET Core)   17.8.3.2353105+f0a326f3e15b2370371693a76fd379635387c74d
提供 ASP.NET Core Razor 的语言服务。

ResX Resource Manager   ResXManager
Manage localization of all ResX-based resources in one place. Shows all resources of a solution and lets you edit the strings and their localizations in a well-arranged data grid.

SQL Server Data Tools   17.8.119.0
Microsoft SQL Server Data Tools

TypeScript Tools   17.0.20920.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic 工具   4.8.0-7.23572.1+7b75981cf3bd520b86ec4ed00ec156c8bc48e4eb
IDE 中使用的 Visual Basic 组件。可能使用其他版本的编译器,具体取决于你的项目类型和设置。

Visual F# Tools   17.8.0-beta.23475.2+10f956e631a1efc0f7f5e49c626c494cd32b1f50
Microsoft Visual F# Tools

Visual Studio IntelliCode   2.2
Visual Studio 的 AI 协助开发。

Visual Studio Tools for Unity   17.8.2.0
Visual Studio Tools for Unity

VisualStudio.DeviceLog   1.0
有关我的包的信息

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

Xamarin   17.8.0.155 (d17-8@7042beb)
用于启用 Xamarin.iOS 和 Xamarin.Android 的开发的 Visual Studio 扩展。

Xamarin Designer   17.8.3.6 (remotes/origin/d17-8@eccf46a291)
用于在 Visual Studio 中启用 Xamarin Designer 工具的 Visual Studio 扩展。

Xamarin.Android SDK   13.2.2.0 (d17-5/45b0e14)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: d9a6e87
    Java.Interop: xamarin/java.interop/d17-5@149d70fe
    SQLite: xamarin/sqlite/3.40.1@68c69d8
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@ca1552d


适用于 Google Test 的测试适配器   1.0
启用带有针对 Google Test 编写的单元测试的 Visual Studio 测试工具。扩展安装目录中提供了使用条款和第三方通知。

用于 Boost.Test 的测试适配器   1.0
通过针对 Boost.Test 编写的单元测试启用 Visual Studio 测试工具。扩展安装目录中提供用户条款和第三方通知。

Steps to Reproduce:

class MyClass {
    private object? _obj;

    public void Method() {
        LocalFunction();

        Console.WriteLine(_obj.ToString()); // CS8602 _obj may be null here!!!!!!!!

        [MemberNotNull(nameof(_obj))]
        void LocalFunction() {
            _obj = new object();
        }
    }
}

image

Diagnostic Id:

If this is a report about a bug in an analyzer, please include the diagnostic if possible (e.g. "IDE0030").

Expected Behavior:
No CS8602.

Actual Behavior:
There is CS8602.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Dec 5, 2023
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@huoyaoyuan
Copy link
Member

I believe MemberNotNull is only expected to work on member functions/properties instead of local functions, but there's no documentation says that, nor analyzer indicates that.

@GF-Huang
Copy link
Author

GF-Huang commented Dec 5, 2023

I believe MemberNotNull is only expected to work on member functions/properties instead of local functions, but there's no documentation says that, nor analyzer indicates that.

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-9.0/local-function-attributes

@huoyaoyuan
Copy link
Member

That's unrelated. Attributes can be applied onto local functions doesn't mean NRT analysis will follow it.

@jcouv
Copy link
Member

jcouv commented Dec 7, 2023

Closing as duplicate of #56256 (which states that LDM agreed this should work).

@jcouv jcouv closed this as not planned Won't fix, can't repro, duplicate, stale Dec 7, 2023
@jcouv jcouv added Resolution-Duplicate The described behavior is tracked in another issue Area-Compilers labels Dec 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Resolution-Duplicate The described behavior is tracked in another issue untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

No branches or pull requests

3 participants