-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Correctly distinguish between tuple fields and associated values in patterns #26357
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
Correctly distinguish between tuple fields and associated values in patterns #26357
Conversation
@swift-ci please smoke test |
Skimming through the failure logs, I think the only failure is because of SwiftPM where they're relying on buggy behavior. 😢 Looking at this line and this one:
should compile fine for source compat but it doesn't now. There is a similar problem with this I'm trying to think of how we could make the fix without breaking them... |
cc @aciidb0mb3r |
I am fine with fixing the SwiftPM code but the source compatibility probably needs to be discussed somewhere ~ |
@aciidb0mb3r thanks! Actually, I think it is a blessing in disguise -- we caught this sooner rather than later thanks to SwiftPM 😅. I've added this hazard to SR-11212. |
Current status: we have a couple of cases failing on master (non-exhaustive match) thanks to SR-11212. Everything else still works. |
Also fixes rdar://problem/53312914. The fact that ParenType is being used to distinguish the two cases makes me uncomfortable but I don't have better ideas. Related: - Fixed a bug in pattern projection which I encountered once I fixed SR-11160. This is the 3 line change around conArgSpaces. - Opened SR-11212 for ill-typed patterns that are permitted to compile. Unrelated cleanup: - Removed a redundant switch case in 'isSubspace'. - Added names for referenced papers for faster lookup.
@swift-ci please smoke test |
Notes for reviewer(s):
|
@swift-ci please smoke test |
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 think this looks great, @varungandhi-apple! I have left a small comment about Type
usage.
lib/Sema/TypeCheckPattern.cpp
Outdated
// 2. pat ~ (P1, ..., Pm) (m >= 2) | ||
void implicitlyUntuplePatternIfApplicable(TypeChecker *TC, | ||
Pattern *&enumElementInnerPat, | ||
const Type &enumPayloadType) { |
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.
Just an FYI - Type
is an immutable word sized container for TypeBase *
so there is no need to pass it by const &
@varungandhi-apple I think exhaustiveness checker should be consistent with SE-0110 so we should consider these source breaks as fixing invalid implementation behavior. It still needs to be discussed on the forums though. |
Make sure that we still emit warnings even if the let bindings are in different positions.
There is a small chance that codegen and everything works fine, but the generated code is wrong because of mismatched expectations on two sides, so we have some tests to catch that.
@swift-ci please smoke test |
That's not a sufficient reason for a source-break these days. Remember, we're not just talking about a developer's code; we're also talking about the packages they are using, and starting with Swift 5.1 any already-compiled binary frameworks with inlinable code as well. |
I'm trying to say that we should, I'm simplify pointing out my opinion on the matter. |
Since the introduction of swiftlang#26357/SR-11160 the TestJSONEncoder seems to have been emitting the new warnings related to tuples being incorrectly pattern matched. The changes remove the incorrect code (removing the parenthesis around the pattern). Should not have any other effect (and the effect was not normally visible if the test was successful, anyway).
See the second commit message for more details.
I'm not sure whether I should've broken things up into multiple commits, since there are couple of unrelated things that I noticed and cleaned up, but they're not really related to the main content of the PR.
Fixes SR-11160 and related rdar://problem/53312914.