question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Assignment of $NULL to a BOOL variable does not work

See original GitHub issue

Prerequisites

Steps to reproduce

[BOOL] $X = $NULL

Expected behavior

-NOT $X

Actual behavior

MetadataError

Error details

Cannot convert value "" to type "System.Boolean". Boolean parameters accept only Boolean values and numbers, such as $True, $False, 1 or 0.

Environment data

System.Management.Automation.PSVersionHashTable

Visuals

No response

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
237dmitrycommented, Nov 1, 2021

It’s the same behavior on PowerShell 7.1.x and even Windows PowerShell 5.1

No. In pwsh 7.1.5 and in powershell 5.1 there are not any errors:

7 5

1reaction
daxian-dbwcommented, Nov 1, 2021

No, this is not a regression. It’s the same behavior on PowerShell 7.1.x and even Windows PowerShell 5.1

Read more comments on GitHub >

github_iconTop Results From Across the Web

A value of type 'bool?' can't be assigned to a variable of ...
1 Answer. You are getting that error because the getter isDialogOpen returns an Optional. This means the return value can either be a...
Read more >
Can bool variable be NULL
In C++, null is defined as "an integer literal with value zero". So, if you were to assign null to a bool ,...
Read more >
Nullable value types - C# reference
As a value type is implicitly convertible to the corresponding nullable value type, you can assign a value to a variable of a...
Read more >
Booleans - Manual
The bool type only has two values, and is used to express a truth value. ... which won't work in JavaScript where you...
Read more >
Avoid Null Booleans in Java. Do you prefer boxed primitives?
A null Boolean means that the variable has no reference assigned, so it is neither true nor false, it is “nothing”.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found