-
Prompted by this Stack Overflow question: https://stackoverflow.com/q/66581096/70345 (please read the answers for additional context/speculation). The tl;dr is that Roslyn does not allow defining extension methods as top-level functions. The relevant spec does not appear to define any special behaviour around top-level functions that would preclude them from being extension methods, however the extension methods spec states that:
Since a top-level function is not technically defined in a class, even though it's compiled to a method inside a static Alternatively, should Roslyn be allowing extension methods as top-level functions, i.e. is there a bug in Roslyn's implementation of the top-level statements spec? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 9 replies
-
Yes. (emphasis mine):
|
Beta Was this translation helpful? Give feedback.
-
IIRC top-level functions are really just local functions declared within the implicit |
Beta Was this translation helpful? Give feedback.
IIRC top-level functions are really just local functions declared within the implicit
Main
method, and local functions can't be extension methods.