Skip to content

Commit a9514f9

Browse files
committed
PR feedback + failed test adjustments
1 parent 1bee2a8 commit a9514f9

File tree

9 files changed

+32
-34
lines changed

9 files changed

+32
-34
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4796,9 +4796,7 @@ bool MissingArgumentsFailure::diagnoseClosure(const ClosureExpr *closure) {
47964796

47974797
auto *locator = getLocator();
47984798
if (locator->isForContextualType()) {
4799-
if (auto type = getContextualType(locator->getAnchor())) {
4800-
funcType = type->getAs<FunctionType>();
4801-
}
4799+
funcType = getContextualType(locator->getAnchor())->getAs<FunctionType>();
48024800
} else if (auto info = getFunctionArgApplyInfo(locator)) {
48034801
auto paramType = info->getParamType();
48044802
// Drop a single layer of optionality because argument could get injected

lib/Sema/CSFix.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -602,10 +602,6 @@ bool AllowTupleTypeMismatch::coalesceAndDiagnose(
602602
purpose = cs.getContextualTypePurpose(locator->getAnchor());
603603
}
604604

605-
if (!getFromType()->is<TupleType>() || !getToType()->is<TupleType>()) {
606-
return false;
607-
}
608-
609605
TupleContextualFailure failure(solution, purpose, getFromType(), getToType(),
610606
indices, locator);
611607
return failure.diagnose(asNote);

lib/Sema/CSGen.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,7 @@ namespace {
890890
// that member through the base returns a value convertible to the type
891891
// of this expression.
892892
auto baseTy = CS.getType(base);
893-
if (auto error = dyn_cast<ErrorExpr>(base)) {
893+
if (isa<ErrorExpr>(base)) {
894894
return CS.createTypeVariable(
895895
CS.getConstraintLocator(expr, ConstraintLocator::Member),
896896
TVO_CanBindToHole);
@@ -2327,8 +2327,9 @@ namespace {
23272327
}
23282328

23292329
if (!varType) {
2330-
varType = CS.createTypeVariable(CS.getConstraintLocator(locator),
2331-
TVO_CanBindToNoEscape);
2330+
varType =
2331+
CS.createTypeVariable(CS.getConstraintLocator(locator),
2332+
TVO_CanBindToNoEscape | TVO_CanBindToHole);
23322333

23332334
// If this is either a `weak` declaration or capture e.g.
23342335
// `weak var ...` or `[weak self]`. Let's wrap type variable

lib/Sema/CSSimplify.cpp

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11201,18 +11201,32 @@ ConstraintSystem::simplifyApplicableFnConstraint(
1120111201
// following: $T1 -> $T2.
1120211202
auto func1 = type1->castTo<FunctionType>();
1120311203

11204+
// Before stripping lvalue-ness and optional types, save the original second
11205+
// type for handling `func callAsFunction` and `@dynamicCallable`
11206+
// applications. This supports the following cases:
11207+
// - Generating constraints for `mutating func callAsFunction`. The nominal
11208+
// type (`type2`) should be an lvalue type.
11209+
// - Extending `Optional` itself with `func callAsFunction` or
11210+
// `@dynamicCallable` functionality. Optional types are stripped below if
11211+
// `shouldAttemptFixes()` is true.
11212+
auto origLValueType2 =
11213+
getFixedTypeRecursive(type2, flags, /*wantRValue=*/false);
11214+
// Drill down to the concrete type on the right hand side.
11215+
type2 = getFixedTypeRecursive(type2, flags, /*wantRValue=*/true);
11216+
auto desugar2 = type2->getDesugaredType();
11217+
1120411218
// If a type variable representing "function type" is a hole
1120511219
// or it could be bound to some concrete type with a help of
1120611220
// a fix, let's propagate holes to the "input" type. Doing so
1120711221
// provides more information to upcoming argument and result matching.
1120811222
if (shouldAttemptFixes()) {
1120911223
if (auto *typeVar = type2->getAs<TypeVariableType>()) {
1121011224
auto *locator = typeVar->getImpl().getLocator();
11211-
if (typeVar->isPlaceholder() || hasFixFor(locator)) {
11225+
if (hasFixFor(locator)) {
1121211226
recordAnyTypeVarAsPotentialHole(func1);
1121311227
}
1121411228
}
11215-
Type underlyingType = simplifyType(type2);
11229+
Type underlyingType = simplifyType(desugar2);
1121611230
while (auto *MT = underlyingType->getAs<AnyMetatypeType>()) {
1121711231
underlyingType = MT->getInstanceType();
1121811232
}
@@ -11222,20 +11236,6 @@ ConstraintSystem::simplifyApplicableFnConstraint(
1122211236
}
1122311237
}
1122411238

11225-
// Before stripping lvalue-ness and optional types, save the original second
11226-
// type for handling `func callAsFunction` and `@dynamicCallable`
11227-
// applications. This supports the following cases:
11228-
// - Generating constraints for `mutating func callAsFunction`. The nominal
11229-
// type (`type2`) should be an lvalue type.
11230-
// - Extending `Optional` itself with `func callAsFunction` or
11231-
// `@dynamicCallable` functionality. Optional types are stripped below if
11232-
// `shouldAttemptFixes()` is true.
11233-
auto origLValueType2 =
11234-
getFixedTypeRecursive(type2, flags, /*wantRValue=*/false);
11235-
// Drill down to the concrete type on the right hand side.
11236-
type2 = getFixedTypeRecursive(type2, flags, /*wantRValue=*/true);
11237-
auto desugar2 = type2->getDesugaredType();
11238-
1123911239
TypeMatchOptions subflags = getDefaultDecompositionOptions(flags);
1124011240

1124111241
SmallVector<LocatorPathElt, 2> parts;
@@ -12907,7 +12907,6 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1290712907
case FixKind::SpecifyLabelToAssociateTrailingClosure:
1290812908
case FixKind::AllowKeyPathWithoutComponents:
1290912909
case FixKind::IgnoreInvalidResultBuilderBody:
12910-
case FixKind::IgnoreInvalidASTNode:
1291112910
case FixKind::IgnoreResultBuilderWithReturnStmts:
1291212911
case FixKind::SpecifyContextualTypeForNil:
1291312912
case FixKind::AllowRefToInvalidDecl:
@@ -12927,6 +12926,9 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1292712926
case FixKind::RenameConflictingPatternVariables: {
1292812927
return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved;
1292912928
}
12929+
case FixKind::IgnoreInvalidASTNode: {
12930+
return recordFix(fix, 10) ? SolutionKind::Error : SolutionKind::Solved;
12931+
}
1293012932

1293112933
case FixKind::ExplicitlyConstructRawRepresentable: {
1293212934
// Let's increase impact of this fix for binary operators because

test/Constraints/diagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ func badTypes() {
11371137
// rdar://34357545
11381138
func unresolvedTypeExistential() -> Bool {
11391139
return (Int.self==_{})
1140-
// expected-error@-1 {{type of expression is ambiguous without more context}}
1140+
// expected-error@-1 {{could not infer type for placeholder}}
11411141
// expected-error@-2 {{type placeholder not allowed here}}
11421142
}
11431143

test/Parse/switch.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,8 @@ func f1(x: String, y: Whichever) {
336336
break
337337
case Whichever.buzz: // expected-error {{type 'Whichever' has no member 'buzz'}}
338338
break
339-
case Whichever.alias: // expected-error {{referencing operator function '~=' on 'RegexComponent' requires that 'Whichever' conform to 'RegexComponent'}}
340-
break
339+
case Whichever.alias: // expected-error {{expression pattern of type 'Whichever' cannot match values of type 'String'}}
340+
// expected-note@-1 {{overloads for '~=' exist}}
341341
default:
342342
break
343343
}

test/StringProcessing/Parse/forward-slash-regex.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ _ = /x/!.blah
9494
// expected-error@-2 {{value of type 'Regex<Substring>' has no member 'blah'}}
9595

9696
do {
97+
// expected-error@+2 {{cannot find operator '/?' in scope}}
98+
// expected-error@+1 {{'/' is not a prefix unary operator}}
9799
_ = /x /?
98100
.blah
99-
// expected-error@-2 {{cannot find operator '/?' in scope}}
100-
// expected-error@-3 {{'/' is not a prefix unary operator}}
101+
// expected-error@-1 {{cannot infer contextual base in reference to member 'blah'}}
101102
}
102103
_ = /x/? // expected-error {{cannot use optional chaining on non-optional value of type 'Regex<Substring>'}}
103104
.blah // expected-error {{value of type 'Regex<Substring>' has no member 'blah'}}
@@ -418,6 +419,7 @@ do {
418419
// expected-error@-1 {{'/' is not a prefix unary operator}}
419420
// expected-error@-2 {{consecutive statements on a line must be separated by ';'}}
420421
// expected-error@-3 {{expected expression}}
422+
// expected-error@-4 {{cannot call value of non-function type '()'}}
421423
}
422424
do {
423425
_ = /[x])/

test/stmt/if_while_var.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,7 @@ guard let _ = nonOptionalEnum() else { fatalError() } // expected-error{{initial
5151
let optional: String? = nil
5252
if case let optional? { _ = optional } // expected-error{{variable binding in a condition requires an initializer}}
5353
if case let .some(optional) { _ = optional } // expected-error{{variable binding in a condition requires an initializer}}
54-
// expected-error@-1 {{type of expression is ambiguous without more context}}
5554
if case .some(let optional) { _ = optional } // expected-error{{variable binding in a condition requires an initializer}}
56-
// expected-error@-1 {{type of expression is ambiguous without more context}}
5755

5856
if case let x? = nonOptionalStruct() { _ = x } // expected-error{{'?' pattern cannot match values of type 'NonOptionalStruct'}}
5957
if case let x? = nonOptionalEnum() { _ = x } // expected-error{{'?' pattern cannot match values of type 'NonOptionalEnum'}}

validation-test/compiler_crashers_2_fixed/0180-rdar45557325.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@ class MyClass: NSObject {
88
func f() {
99
let url = URL(url) // expected-error{{use of local variable 'url' before its declaration}}
1010
// expected-note@-1 {{'url' declared here}}
11+
// expected-error@-2 {{missing argument label 'string:' in call}}
1112
}
1213
}

0 commit comments

Comments
 (0)