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
fix issue 20138 - is expression not evaluating correctly? #10317
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
$(I IsExpression)s now correctly match combinations of `const`, `inout`, and `shared`. | ||
|
||
With $(BUGZILLA 20138) fixed, | ||
$(LINK2 $(ROOT_DIR)spec/expression.html#is_expression, $(I IsExpression)s) now | ||
correctly match combinations of the qualifiers `const`, `inout`, and `shared`. | ||
|
||
Examples that failed previously but pass now: | ||
|
||
---- | ||
static assert(is(shared(const int) U == shared U) && is(U == const int)); | ||
static assert(is(shared(inout int) U == inout U) && is(U == shared int)); | ||
---- | ||
|
||
Note that the behavior of code like the following changes: | ||
|
||
---- | ||
static if (is(T U == const U) { ...} | ||
else static if (is(T U == shared const U)) { ... } | ||
---- | ||
|
||
The second case will never be reached, because the first one now matches when | ||
`T` is `shared const`. To get the old behavior, switch the order. |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
alias C = const int; | ||
static assert(is(shared(C) U == shared U) && is(U == C)); | ||
static assert(is(shared(C) == shared U, U) && is(U == C)); | ||
|
||
alias I = inout int; | ||
static assert(is(shared(I) U == shared U) && is(U == I)); | ||
static assert(is(shared(I) == shared U, U) && is(U == I)); | ||
|
||
alias IC = inout const int; | ||
static assert(is(shared(IC) U == shared U) && is(U == IC)); | ||
static assert(is(shared(IC) == shared U, U) && is(U == IC)); | ||
|
||
alias S = shared int; | ||
static assert(is(const(S) U == const U) && is(U == shared int)); | ||
static assert(is(inout(S) U == inout U) && is(U == shared int)); | ||
static assert(is(inout(const S) U == inout(const U)) && is(U == shared int)); | ||
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.
Suggest adding
static assert(is(inout const S U == inout U) && is(U == const shared S));
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.
I'd rather leave that out for now, because it's less obvious how to handle it.
For the others, I just changed
MATCH.constant
toMATCH.exact
. For this combination,deduceTypeHelper
currently returnsMATCH.nomatch
. But it works in IFTI, so there must be something else going on. My guess is that it's handled bydeduceTypeHelper
, which isn't even called foris
expressions.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.
That was supposed to be: My guess is that it's handled by
deduceWildHelper
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.
I was gonna say we could do something like this:
However, apparently calling
sharedOf()
on aconst
type doesn't return aconst shared
type, and likewise for the other*Of()
s. This somewhat disappoints me.