microsoft / microsoft/Power-Fx
Uninitialized record member not behaving as expected in Boolean context
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 3.4k
- Forks
- 358
- Avg merge
- 10h 34m
- Merged PRs (30d)
- 3
Description
We're seeing some odd behavior in Power FX where a record member that hasn't yet taken on a value (so, it's Blank()) is not behaving as expected when we're using it in a Boolean context.
For example, we've got a conditional expression that returns true whenever both conditions are true (or truthy):
// gblSelectedPREntry is a record. has_guard is a 0 or 1, IsBlank() will be true or false
(gblSelectedPREntry.has_guard && IsBlank(gblSelectedPREntry.infopath_number))
When the app loads, the has_guard member of the gblSelectedPREntry has yet to be set, as it is set when a user clicks a checkbox. So, it returns Blank():
The infopath_number is also Blank(), so the IsBlank() returns true:
So, it would seem that this:
(gblSelectedPREntry.has_guard && IsBlank(gblSelectedPREntry.infopath_number))
Should equal this:
Blank() && true
But it doesn't!
Our users figured out that if they toggle the checkbox where has_guard gets set to a 1 or 0, it starts behaving as expected.
So, before anything has been clicked, for some reason we're seeing true here instead of false:
Once the has_guard box is clicked, we see true, which is what we would expect:
If we uncheck has_guard, we see false, which is what we would have expected before checking the box, as well as after unchecking it:
The issue started a few days ago. Looking at your commit history, this looks like it adjusted your Type system: https://github.com/microsoft/Power-Fx/commit/2403e3998c97640bd18f84fd0fc85d688e15db5c. Maybe that's the culprit? Or are we misunderstanding how the Type system is supposed to work in Power FX on our side?
We're going to file an issue with our internal Power Apps Microsoft representatives as well, but I figured I'd reach out here in the meantime. To mitigate the issue in the short term, casting to Boolean when a value may be Blank() seems to work.
// This __always__ works
(Boolean(gblSelectedPREntry.has_guard) && IsBlank(gblSelectedPREntry.infopath_number))
If that's the expected behavior, please close this issue!
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the reported Power Fx expressions with an uninitialized record member, then compare the Boolean and Blank() behavior around commit 2403e3998c97640bd18f84fd0fc85d688e15db5c. Determine whether Blank() && true should evaluate as reported and verify the result with the existing test suite; done means the semantics are confirmed or a regression test and fix are identified.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100