Skip to content

Are all TokenKind.Generic tokens actually StringToken? #10581

@msftrncs

Description

@msftrncs

The following definition of TokenKind.Generic would indicate that all tokens of TokenKind.Generic should be a StringToken. (or specifically either StringLiteral or StringExpandable)

/// <summary>
/// A token that is only valid as a command name, command argument, function name, or configuration name. It may contain
/// characters not allowed in identifiers.
/// Tokens with this kind are always instances of <see cref="System.Management.Automation.Language.StringLiteralToken"/>
/// or <see cref="System.Management.Automation.Language.StringExpandableToken"/> if the token contains variable
/// references or subexpressions.
/// </summary>
Generic = 7,

However, the method Token.SetIsCommandArgument does not guarantee that. This method is used to revert the TokenKind of special tokens when they appear as command names or arguments. Most all the special tokens that receive this treatment are not StringTokens.

internal void SetIsCommandArgument()
{
// Rather than expose the setter, we have an explicit method to change a token so that it is
// considered a command argument. This prevent arbitrary changes to the kind which should be safer.
if (_kind != TokenKind.Identifier)
{
_kind = TokenKind.Generic;
}
}

Should the documentation above TokenKind.Generic be reworded?

Reference PR #10295.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-No ActivityIssue has had no activity for 6 months or moreWG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions