You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
keywords in class method names meaningless error message #9106
If one currently uses practically any keyword (even in) in classes as method names, a meaningless error is displayed.
PS C:\> class crazy { param($a) {} }
At line:1 char:14
+ class crazy { param($a) {} }
+ ~
Missing closing '}' in statement block or type definition.
At line:1 char:28
+ class crazy { param($a) {} }
+ ~
Unexpected token '}' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : MissingEndCurlyBrace
See #2217. I really think there is no reason these are reserved from method names.
While the error message could be improved, this is inconsistent behavior from other parts of the PowerShell language. For instance, while CATCH is prevented as a method name, I can use CATCH as a function name, because CATCH is only a keyword in certain context's. CATCH will never likely be a keyword in the context of class definitions, and is not a keyword for the purpose of method invocations.
Yes, I understand that one would need to make that declaration, in documentation, so it would be final.
Furthermore, some items, namely the param keyword, are treated different inside a method than it is inside some other blocks. In a function's 'BEGIN' / 'END' / 'PROCESS' block, param is treated as a function, while in the main body, its a keyword. In a method, its an error. (at least its got a meaningful error message at this point, thank-you.)
Activity