-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[CS] Don’t fail constraint generation for ErrorExpr or if type fails to resolve #60062
Conversation
@swift-ci Please smoke test |
@swift-ci Please SourceKit stress test |
lib/Sema/CSSimplify.cpp
Outdated
@@ -11208,8 +11208,17 @@ ConstraintSystem::simplifyApplicableFnConstraint( | |||
if (shouldAttemptFixes()) { | |||
if (auto *typeVar = type2->getAs<TypeVariableType>()) { | |||
auto *locator = typeVar->getImpl().getLocator(); | |||
if (typeVar->isPlaceholder() || hasFixFor(locator)) | |||
if (typeVar->isPlaceholder() || hasFixFor(locator)) { |
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.
Could you please do a couple of things here:
- Remove
typeVar->isPlaceholder()
check since it's always false because type variable cannot be a placeholder anymore - Move whole
if (shouldAttemptFixes())
to just beforeTypeMatchOptions subflags = getDefaultDecompositionOptions(flags);
- use
desugar2
instead ofsimplifyType(type2);
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.
use
desugar2
instead ofsimplifyType(type2);
We need to simplify the type because getFixedTypeRecursive
doesn’t simplify AnyMetatypeType
s that have a type variable as instance type, so in desugar2
the type variable won’t have been replaced by a placeholder yet. The alternative would be to add handling for AnyMetatypeType
in getFixedTypeRecursive
. Do you have a preference what would be the better solution?
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.
Hm I keep forgetting about all the nuances of getFixedTypeRecursive vs. simplifyType. Maybe we should just call getFixedTypeRecursive on an instance type if type2 was a metatype for this new check.
6eb3603
to
a9514f9
Compare
@swift-ci Please smoke test macOS |
@swift-ci Please SourceKit stress test |
d3a70ab
to
95abc5b
Compare
@swift-ci Please smoke test macOS |
test/Parse/matching_patterns.swift
Outdated
if case let .Naught(value1, value2, value3) = n {} // expected-error{{pattern with associated values does not match enum case 'Naught'}} | ||
// expected-note@-1 {{remove associated values to make the pattern match}} {{20-44=}} | ||
// expected-error@-2 {{could not infer type of variable 'value1'}} |
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 is actually a regression of sorts - the main problem here is described by the first error and problems with value1..3
are just a consequence...
test/stmt/foreach.swift
Outdated
|
||
for (x, y, _) in arr2 {} | ||
// expected-error@-1 {{pattern cannot match values of type '(a: Int, b: String)'}} | ||
// expected-error@-2 {{could not infer type of variable 'x'}} |
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.
Here is the same, maybe we could somehow coalesce fixes
95abc5b
to
27ce696
Compare
@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.
Looks great, thank you! I have left a couple more minor comments inline.
27ce696
to
88fc983
Compare
@swift-ci Please smoke test |
…to resolve Instead of failing constraint generation by returning `nullptr` for an `ErrorExpr` or returning a null type when a type fails to be resolved, return a fresh type variable. This allows the constraint solver to continue further and produce more meaningful diagnostics. Most importantly, it allows us to produce a solution where previously constraint generation for a syntactic element had failed, which is required to type check multi-statement closures in result builders inside the constraint system.
…nside a named pattern We need this to resolve a test failure in optional.swift.
The issue has been fixed by allowing holes for variables in paterns.
88fc983
to
5ba66aa
Compare
@swift-ci Please smoke test |
Resolves: #60485 |
…rExpr It appears like this was missed in swiftlang#60062.
…rExpr It appears like this was missed in swiftlang#60062.
…rExpr It appears like this was missed in swiftlang#60062.
Instead of failing constraint generation by returning
nullptr
for anErrorExpr
or returning a null type when a type fails to be resolved, return a fresh type variable. This allows the constraint solver to continue further and produce more meaningful diagnostics.Most importantly, it allows us to produce a solution where previously constraint generation for a syntactic element had failed, which is required to type check multi-statement closures in result builders inside the constraint system.
Resolves: #60029
Resolves: #60485