zompinc/sync-method-generator

Generator crashes when a method contains multiple preprocessor directives with curly brackets

Closed this issue · 5 comments

Consider the following code

        [Zomp.SyncMethodGenerator.CreateSyncVersion(OmitNullableDirective = true)]
        public async Task Foo1Async()
        {
            await Task.Delay(100);
#if DEBUG
            {
#endif

#if DEBUG
            }
#endif
        }

        [Zomp.SyncMethodGenerator.CreateSyncVersion(OmitNullableDirective = true)]
        public async Task Foo2Async()
        {
            await Task.Delay(100);
#if DEBUG
            {
            }
#endif
        }

        [Zomp.SyncMethodGenerator.CreateSyncVersion(OmitNullableDirective = true)]
        public async Task Foo3Async()
        {
            await Task.Delay(100);
#if DEBUG
            {
            }
#endif

#if DEBUG
            {
            }
#endif
        }

Foo2Async and Foo3Async generates and compiles fine, however Foo1Async crashes with the message 1>CSC : warning CS8785: Generator 'SyncMethodSourceGenerator' failed to generate source. It will not contribute to the output and compilation errors may occur as a result. Exception was of type 'InvalidOperationException' with message 'Stack empty.'.

This also fails with the same error message, might be related, or might be a different issue

        [Zomp.SyncMethodGenerator.CreateSyncVersion(OmitNullableDirective = true)]
        public async Task FooAsync()
        {
            await Task.Delay(100);

            var bar =
#if DEBUG
                true;
#else
                false;
#endif
        }

Looking at this on the weekend. Thanks so much for all the issues! Makes the project better.

Fixed in version 1.4.13

Actually, the second test hasn't been fixed

Second test is a different issue now tracked in #85