Skip to content

Update 'SaveError' in 'Parser.cs' to not depend on LINQ expression tree to get the error id #6444

@daxian-dbw

Description

@daxian-dbw

Quote Jason's comment at https://github.com/PowerShell/PowerShell/pull/6434/files/5b5be3122971552d2ce208858ac84868954b841c#r175933192

I'd suggest removing my ugly hack of using LINQ expression trees in SaveError and related helper methods, and replace with nameof(ParserStrings.MissingEndCurlyBrace).

When that code was written, nameof was not in C#, so the ugly and inefficient code was used because:

  • It ensured no typos in the FullyQualifiedErrorId.
  • It was easy to search for all references to an error message via the property.
  • Performance was not deemed important because they were errors.

Performance might matter more than I originally assumed given editor scenarios - and given the nameof language feature, it's reasonable (but annoying and a little verbose) to change error reporting to look more like:

ReportIncompleteInput(lCurly.Extent, rCurly.Extent,
    ParserStrings.MissingEndCurlyBrace, nameof(ParserStrings.MissingEndCurlyBrace));

In other words, pass the error text and the error id.

Alternatively you could just pass the error id and use reflection of some sort to load the error string, but that would not be good for performance.

Metadata

Metadata

Assignees

Labels

Issue-Code Cleanupthe issue is for cleaning up the code with no impact on functionalityResolution-FixedThe issue is fixed.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions