JetBrains / resharper-unity

Unity support for both ReSharper and Rider
Apache License 2.0
1.21k stars 134 forks source link

Can not resolve symbol method when using System.Diagnostics.Conditional #2415

Closed ffbh123456 closed 1 year ago

ffbh123456 commented 1 year ago

version: JetBrains Rider 2023.2

  1. If I defined the "SOME_DEFINE", no error showed.
  2. Removed the scripting define symbol of "SOME_DEFINE" and the error occurred which I think is a bug because the invocation of the DoMethod was removed by the compiler so what matters if it can not find the symbol of "DoABC"?
截屏2023-08-28 上午11 54 20
#if SOME_DEFINE
        private void DoABC()
        {
        }
#endif
        [Conditional("SOME_DEFINE")]
        private void DoMethod(Action action)
        {
            action();
        }

        public void Test()
        {
            DoMethod(DoABC);
        }

For now, I have to add duplicate #if SOME_DEFINE for each function call like this to avoid the error which is annoying.

#if SOME_DEFINE
        private void DoABC()
        {
        }
#endif
        [Conditional("SOME_DEFINE")]
        private void DoMethod(Action action)
        {
            action();
        }

        public void Test()
        {
#if SOME_DEFINE
            DoMethod(DoABC);
#endif
        }
van800 commented 1 year ago

This is core functionality of Rider and Re#, we can't alter it from this plugin. Please report with Help->Report a Bug. Thank you!

citizenmatt commented 1 year ago

I'm not sure this is a bug - does the code compile when you don't have the symbol defined? I would expect the compiler to still require DoABC to exist in this scenario - you might have an overload of this method that takes a different type as an argument and the compiler wouldn't know which overload to use if the argument doesn't resolve.