Skip to content

Using System.Void as a type argument in class constructor makes PSReadLine throw an exception #4324

@notatechproblem

Description

@notatechproblem

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues, especially the pinned issues.

Exception report

### Environment
PSReadLine: 2.3.5+2cc85806c561a9395751a96a818e8ff1592d19f7
PowerShell: 7.4.6
OS: Microsoft Windows 10.0.19045
BufferWidth: 150
BufferHeight: 300

Last 54 Keys:

 c l a s s Spacebar M y C l a s s Enter
 { Enter
 Spacebar Spacebar h i d d e n Spacebar M u C l a Backspace Backspace Backspace Backspace y C l a s s ( [ V o i d ] $ V o i d ) {

### Exception

System.ArgumentException: The type 'System.Void' may not be used as a type argument.
   at System.RuntimeType.SanityCheckGenericArguments(RuntimeType[] genericArguments, RuntimeType[] genericParameters)
   at System.RuntimeType.MakeGenericType(Type[] instantiation)
   at System.Management.Automation.Language.VariableAnalysis.FinishAnalysis(Boolean scriptCmdlet)
   at System.Management.Automation.Language.VariableAnalysis.AnalyzeMemberFunction(FunctionMemberAst ast)
   at System.Management.Automation.Language.SemanticChecks.VisitFunctionMember(FunctionMemberAst functionMemberAst)
   at System.Management.Automation.Language.FunctionMemberAst.InternalVisit(AstVisitor visitor)
   at System.Management.Automation.Language.TypeDefinitionAst.InternalVisit(AstVisitor visitor)
   at System.Management.Automation.Language.NamedBlockAst.InternalVisit(AstVisitor visitor)
   at System.Management.Automation.Language.ScriptBlockAst.InternalVisit(AstVisitor visitor)
   at System.Management.Automation.Language.Parser.ParseTask(String fileName, String input, List`1 tokenList, Boolean recursed, ParseMode parseMode)
   at System.Management.Automation.Language.Parser.Parse(String fileName, String input, List`1 tokenList, ParseError[]& errors, ParseMode parseMode)
   at System.Management.Automation.Language.Parser.ParseInput(String input, String fileName, Token[]& tokens, ParseError[]& errors)

Screenshot

image

Environment data

PS Version: 7.4.6
PS HostName: ConsoleHost
PSReadLine Version: 2.3.5
PSReadLine EditMode: Windows
OS: 10.0.19041.1 (WinBuild.160101.0800)
BufferWidth: 150
BufferHeight: 300

Steps to reproduce

While defining a custom class from the command line, specifying [System.Void] as a constructor type argument causes PSReadLine to throw an exception.

Expected behavior

PowerShell to throw a System.ArgumentException and PSReadLine functionality to remain available in the current PS session.

Actual behavior

PSReadLine throws a System.ArgumentException. PowerShell is still running, but PSReadLine functionality is not until a new PS session is started.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions