-
Notifications
You must be signed in to change notification settings - Fork 8.3k
TokenTraits.HasTrait gives unexpected results with Precedence flags #13820
Copy link
Copy link
Closed
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aNeeds-TriageThe issue is new and needs to be triaged by a work group.The issue is new and needs to be triaged by a work group.Resolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Languageparser, language semanticsparser, language semantics
Metadata
Metadata
Assignees
Labels
Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aNeeds-TriageThe issue is new and needs to be triaged by a work group.The issue is new and needs to be triaged by a work group.Resolution-No ActivityIssue has had no activity for 6 months or moreIssue has had no activity for 6 months or moreWG-Languageparser, language semanticsparser, language semantics
Type
Fields
Give feedbackNo fields configured for issues without a type.
The function
TokenTraits.HasTrait(TokenKind, TokenFlags)gives strange results for the BinaryPrecedence values ofTokenFlagsFor example,
returns
BinaryPrecedenceBitwise, BinaryOperator, CanConstantFold. The documentation onTokenTraits.HasTraitsays: "Return true if the TokenKind has the given trait." Therefore I would expectHasTraitto returntrueonly for those three values ofTokenFlags. However:Steps to reproduce
Expected behavior
Actual behavior
Environment data
Discovered this while trying to work out why the PSScriptAnalyzer rule UseConsistentWhitespace seems to apply to some random set of operators and not to others. After really digging in, it appears the author of the logic for operators in this rule only intended to implement logic for assignment or arithmetic operators. However it appears that person made the same assumption I would that
HasTraitought to work on the BinaryPrecedence flags and therefore used it in attempt to detect all operators with equal precedence to Add or Multiply.