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

GeneratorDriver.GetRunResult() should not throw #74033

Closed
chsienki opened this issue Jun 17, 2024 · 1 comment · Fixed by #74034
Closed

GeneratorDriver.GetRunResult() should not throw #74033

chsienki opened this issue Jun 17, 2024 · 1 comment · Fixed by #74034
Assignees
Labels
Area-Compilers New Feature - Source Generators Source Generators untriaged Issues and PRs which have not yet been triaged by a lead
Milestone

Comments

@chsienki
Copy link
Contributor

chsienki commented Jun 17, 2024

If you call .GetRunResult() on a driver that hasn't run, but has generators in it, we null-ref.

        [Fact]
        public void RunResults_Are_Empty_Before_Generation_With_Generators()
        {
            var generator = new SingleFileTestGenerator("public class D {}", "source.cs");

            GeneratorDriver driver = CSharpGeneratorDriver.Create([generator], parseOptions: TestOptions.Regular);
            var results = driver.GetRunResult();

            Assert.Empty(results.GeneratedTrees);
            Assert.Empty(results.Diagnostics);
            Assert.Empty(results.Results);
        }

See internal link

@chsienki chsienki self-assigned this Jun 17, 2024
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Issues and PRs which have not yet been triaged by a lead label Jun 17, 2024
@jaredpar jaredpar added this to the 17.11 milestone Jun 17, 2024
@Peter-Juhasz
Copy link

Is this the same as this one I encountered in VS 17.11.0 P2?

StreamJsonRpc.RemoteInvocationException: Object reference not set to an instance of an object.
   at StreamJsonRpc.JsonRpc.<InvokeCoreAsync>d__154`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at Microsoft.CodeAnalysis.Remote.BrokeredServiceConnection`1.<TryInvokeAsync>d__18`1.MoveNext()
RPC server exception:
System.NullReferenceException: Object reference not set to an instance of an object.
      at Microsoft.CodeAnalysis.GeneratorDriver.<GetRunResult>g__getGeneratorSources|15_1(GeneratorState generatorState)
      at Microsoft.CodeAnalysis.GeneratorDriver.<>c.<GetRunResult>b__15_0(ISourceGenerator generator, GeneratorState generatorState)
      at Microsoft.CodeAnalysis.ImmutableArrayExtensions.ZipAsArray[T1,T2,TResult](ImmutableArray`1 self, ImmutableArray`1 other, Func`3 map)
      at Microsoft.CodeAnalysis.GeneratorDriver.GetRunResult()
      at Microsoft.CodeAnalysis.SolutionCompilationState.CompilationTracker.GetSourceGeneratorDiagnosticsAsync(SolutionCompilationState compilationState, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteDiagnosticAnalyzerService.<>c__DisplayClass4_0.<<GetSourceGeneratorDiagnosticsAsync>b__0>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.<>c__DisplayClass7_0`1.<<RunWithSolutionAsync>g__ProcessSolutionAsync|1>d.MoveNext()
   --- End of stack trace from previous location ---
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteWorkspace.RunWithSolutionAsync[T](AssetProvider assetProvider, Checksum solutionChecksum, Boolean updatePrimaryBranch, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.BrokeredServiceBase.RunWithSolutionAsync[T](Checksum solutionChecksum, Func`2 implementation, CancellationToken cancellationToken)
      at Microsoft.CodeAnalysis.Remote.RemoteDiagnosticAnalyzerService.GetSourceGeneratorDiagnosticsAsync(Checksum solutionChecksum, ProjectId projectId, CancellationToken cancellationToken)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers New Feature - Source Generators Source Generators untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants