SourceGenerators & partial methods #69387
-
Writing a source generator I've come across a situation with partial methods where I am not sure if my scenario is just Imagine a source generator which outputs source that contains partial method stubs:
/// <autogenerated />
public partial class Foo {
public partial object Bar(int wiz, string bang);
} Since that is partial method with both a visibility modifier and a return type (either would suffice) it must have an implementation part. (See https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/partial-classes-and-methods#partial-methods). Now imagine a second manually written source file containing said implementation: public partial class Foo {
public partial object Bar(int wiz, string bang) {
return $"{wiz}-{bang}";
}
} If both files were part of a regular project this would compile fine. If the manually written implementation was missing, you would get a nice compiler error for that. Now if the defining declaration comes out of a source generator the compiler may error with I've specifically had those errors when using a non incremental I'm assuming that combining my value providers with the Now my question is: Is this intentional? Shouldn't roslyn only give diagnostic errors for potentially multi-file issues once it has all files ? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Yes. If you are seeing otherwise, it is a bug. We'd need a repro case demonstrating the issue so someone could investigate. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Okay, that's rather good news (and bad). 😅 I was having significant issues getting the source generator to work in all build situations due to FileNotFound exceptions with (transitive) assembly dependencies. The missing definition errors may just have coincided with those initialization errors (and at those times been correct from a compiler perspective). I'll give it another look and maybe put in an issue or two regarding dependencies (and any other weird behavior I've seen). |
Beta Was this translation helpful? Give feedback.
Yes.
If you are seeing otherwise, it is a bug. We'd need a repro case demonstrating the issue so someone could investigate. Thanks!