-
Notifications
You must be signed in to change notification settings - Fork 76
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
Type.Is Nullable Type Rule Clarification #200
Open
bgribaudo
wants to merge
3
commits into
MicrosoftDocs:main
Choose a base branch
from
bgribaudo:patch-7
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not true. By passing a nullable primitive type as the second arg, you can use Type.Is to check for both the nullable and non-nullable version of that type. But that's just one use of the function.
Here's another way it can be used, which doesn't involve nullable types at all:
Type.Is(Int64.Type, type number)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ehrenMSFT,
Thanks for this feedback.
I'm puzzled. Isn't
type number
a nullable primitive type (where nullable primitive type = all primitive types + their nullable counterparts)?In the language spec, operators
as
andis
are described as only accepting "nullable primitive types as their right operand," andValue.Is
's second argument is described as accepting "an arbitrary type value as its first and a nullable primitive type value as its second argument." Examples are given likeType.Is(type number, type text)
and1 is number
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure about the spec. I'm just basing my comments on how things actually seem to work.
Type.IsNullable(type number) returns false. You'd have to say "type nullable number" to make it nullable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @ehrenMSFT!
Just opened a PR raising the question of how to best address the "nullable primitive type" terminology used in the spec.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ehrenMSFT, just edited this to reflect the terminology that #203 has moved to. Does this look good to you now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where are you getting the limitation that the second type must be a primitive or nullable primitive type? I don't see any limitation like this in our code. The logic seems more involved than that.
For example, the following returns true, even though Int64.Type isn't a primitive type.
Type.Is(type number, Int64.Type)
To give other examples, this returns false:
Type.Is(type [a=number], type [a=number])
while this returns true:
let recordType = type [a=number] in Type.Is(recordType, recordType)
How does the info you added account for these examples?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @ehrenMSFT!
Happy New Year!
The spec mentions this limitation—https://learn.microsoft.com/en-us/powerquery-m/m-spec-types:
I'd assumed that the above quote from the spec is correct, and so assumed that if
Type.Is
seems to work when its second argument is not a primitive type or a nullable primitive type, its behavior shouldn't be relied on.If that is inaccurate, can you advise on what is allowed as the second argument? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, thanks for clarifying I think I understand now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you planning to also update m-spec-types to mention that both nullable and non-nullable primitive types are supported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! That's addressed here: https://github.com/MicrosoftDocs/query-docs/pull/203/files#diff-a63ce61286e5545a92608330795d3427bb807bc7cd0b9277a9f651b00efc5507R368