File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed
Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change 1- using System ;
1+ using System ;
22using System . Collections ;
33using System . Collections . Generic ;
44using System . Globalization ;
@@ -488,6 +488,14 @@ public object VisitForStatement(ForStatementAst forStatementAst)
488488
489489 public object VisitHashtable ( HashtableAst hashtableAst )
490490 {
491+ if ( hashtableAst . KeyValuePairs . Count == 0 )
492+ {
493+ return New (
494+ ReflectionCache . Hashtable_Ctor ,
495+ Constant ( 0 ) ,
496+ Property ( null , ReflectionCache . StringComparer_CurrentCultureIgnoreCase ) ) ;
497+ }
498+
491499 var elements = new ElementInit [ hashtableAst . KeyValuePairs . Count ] ;
492500 for ( var i = 0 ; i < elements . Length ; i ++ )
493501 {
Original file line number Diff line number Diff line change @@ -6,6 +6,9 @@ Import-Module $manifestPath -Force
66Describe ' Misc Language Features' {
77 It ' Hashtable expression' {
88 $delegate = New-PSDelegate {
9+ Context ' hashtable tests' {
10+ It ' handles varied types of values' {
11+ $delegate = New-PSDelegate {
912 return @ {
1013 ' string' = ' value'
1114 string2 = 10
@@ -20,6 +23,11 @@ Describe 'Misc Language Features' {
2023 $hashtable [' object' ] | Should - BeOfType object
2124 }
2225
26+ It ' can initialize an empty hashtable' {
27+ (New-PSDelegate { @ {} }).Invoke().GetType() | Should - Be ([hashtable ])
28+ }
29+ }
30+
2331 Context ' array literal' {
2432 It ' int' {
2533 $result = (New-PSDelegate { 1 , 2 , 3 }).Invoke()
You can’t perform that action at this time.
0 commit comments