-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[CSGen] Allow _
pattern to be a hole
#60203
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
Conversation
@swift-ci please 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.
The code completion failure might be related to the comment I put inline regarding the anchor. If not, I can take a look at it if you like.
I just looked at the code completion failure and the problem is that in this test case we fail to resolve the type for struct MyStruct<T> {
static subscript(x: Int, static defValue: T) -> MyStruct<T> {
fatalError()
}
subscript(x: Int, instance defValue: T) -> Int {
fatalError()
}
}
func test1() {
let _ = MyStruct<Int>()[#^INSTANCE_INT_BRACKET^#
} We don’t have this problem because it cannot be bound to a hole since the type variable is created by varType = CS.getType(boundExpr)->getRValueType(); AFAICT the solution to this problem is to make variables at pattern decls as potentially incomplete, i.e. add // Delay resolution of pattern decls because we prefer to determine its type
// based on the expression it is assigned from. Also, if there is an error
// in the expression, we want to prefer creating the direct hole inside the
// expression, not at the pattern decl.
if (locator->isLastElement<LocatorPathElt::PatternDecl>()) {
return true;
} inside the |
I think it makes sense to do for |
@swift-ci please test |
The fix should support both named (i.e. `test(a)` and "any" patterns i.e. `test(_)`.
In cases like `case .test(_)` it might not be possible to establish a type of `_` and hole cannot be propagated to it from context if condition of switch is incorrect, so `_` just like a named pattern should be allowed to become a hole. Resolves: rdar://96997534
Instead of `CTP_Initialization` transform should use `CTP_CaseStmt` to identify the root correctly.
`_` pattern doesn't have a type, it's always contextual, so let's allow it to assume a type of initializer expression instead of creating a new type variable. This helps to makes sure that initializer would never get a placeholder type from `_` pattern it's associated with.
In cases like `.<name>(_)`, the `_` sub-pattern should not assume locator of the parent paren, just like it doesn't in case of tuple i.e. `.<name>(_, ...)` where each element gets a `PatternMatch(<elt>)` locator.
@swift-ci please test |
@swift-ci please test source compatibility |
2 similar comments
@swift-ci please test source compatibility |
@swift-ci please test source compatibility |
In cases like
case .test(_)
it might not be possible toestablish a type of
_
and hole cannot be propagated toit from context if condition of switch is incorrect, so
_
just like a named pattern should be allowed to becomea hole.
Resolves: rdar://96997534