Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
3 tasks done
notatechproblem opened this issue Dec 31, 2024 · 1 comment

Comments

@notatechproblem
Copy link

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.

@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Triage 🔍 It's a new issue that core contributor team needs to triage. label Dec 31, 2024
@daxian-dbw
Copy link
Member

The exception is thrown by PowerShell when parsing the input script and it's a legit error to be thrown because it's invalid to use System.Void for a parameter type, or variable type. It's only used to represent the absence of a return value for a method.

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs-Triage 🔍 It's a new issue that core contributor team needs to triage. label Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants