-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
Related: #3483
Preference variable [This has been fixed]$ErrorView, despite only supporting 2 values - NormalView and CategorizedView - is defined as a [string] and therefore quietly accepts any value (and falls back to NormalView).
It should probably be an enumeration type, as similar preference variables are (e.g., $ErrorActionPreference -is [enum] returns $true)
Similarly, the fact that some preference variables aren't predefined altogether allows their creation with inappropriate types.
Note that this problem exists separately from the fact that creating preference variables in child scopes never enforces their intended types, even if they're appropriately type-constrained in the global scope.
Steps to reproduce
$LogCommandHealthEvent = 'I should be a Boolean'Expected behavior
(Statement-terminating) errors complaining about the inappropriate values.
Actual behavior
The invalid values are quietly accepted.
Currently, the following preference variables aren't predefined:
-
[bool]:LogCommandHealthEvent LogCommandLifecycleEvent LogEngineHealthEvent LogEngineLifecycleEvent LogProviderLifecycleEvent LogProviderHealthEvent -
[int]:MaximumAliasCount, MaximumDriveCount, MaximumErrorCount, MaximumFunctionCount, MaximumVariableCount- these are predefined in Windows PowerShell v5.1, however. -
enum
[PSModuleAutoLoadingPreference]:PSModuleAutoLoadingPreference -
[string]:OFS, but given that it is conceptually[string]and that any value can be converted to a string, that is less of an issue. -
Others?
Environment data
PowerShell Core v6.0.0-alpha (v6.0.0-alpha.18) on Darwin Kernel Version 16.5.0: Fri Mar 3 16:52:33 PST 2017; root:xnu-3789.51.2~3/RELEASE_X86_64