Skip to content

Commit 6a0a1de

Browse files
Suyash SrijanSuyash Srijan
authored andcommitted
[cs] use anchor instead of locator, etc
1 parent 5b7fd8c commit 6a0a1de

File tree

6 files changed

+14
-8
lines changed

6 files changed

+14
-8
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,9 +591,10 @@ bool MissingOptionalUnwrapFailure::diagnoseAsError() {
591591

592592
auto *tryExpr = dyn_cast<OptionalTryExpr>(unwrapped);
593593
if (!tryExpr) {
594-
auto resolvedBaseTy = BaseType ? resolveType(BaseType) : BaseType;
594+
auto resolvedBaseTy =
595+
resolveType(BaseType)->reconstituteSugar(/*recursive=*/true);
595596
auto resolvedUnwrappedTy =
596-
UnwrappedType ? resolveType(UnwrappedType) : UnwrappedType;
597+
resolveType(UnwrappedType)->reconstituteSugar(/*recursive=*/true);
597598
return diagnoseUnwrap(getConstraintSystem(), unwrapped, resolvedBaseTy,
598599
resolvedUnwrappedTy);
599600
}

lib/Sema/CSSimplify.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5409,7 +5409,12 @@ bool ConstraintSystem::recordFix(ConstraintFix *fix) {
54095409
// This situation might happen when the same fix kind is applicable to
54105410
// different overload choices.
54115411
auto *loc = fix->getLocator();
5412+
auto *anchor = loc->getAnchor();
54125413
auto existingFix = llvm::find_if(Fixes, [&](const ConstraintFix *e) {
5414+
if (e->getKind() == FixKind::ForceOptional &&
5415+
e->getLocator()->getAnchor() == anchor) {
5416+
return true;
5417+
}
54135418
// If we already have a fix like this recorded, let's not do it again,
54145419
return e->getKind() == fix->getKind() && e->getLocator() == loc;
54155420
});

test/ClangImporter/cfuncs_parse.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func test_cfunc2(_ i: Int) {
1717

1818
func test_cfunc3_a() {
1919
let b = cfunc3( { (a : Double, b : Double) -> Double in a + b } )
20-
_ = b(1.5, 2.5) as Double // expected-error{{value of optional type 'Optional<double_bin_op_block>' (aka 'Optional<(Double, Double) -> Double>') must be unwrapped to a value of type 'double_bin_op_block' (aka '(Double, Double) -> Double')}}
20+
_ = b(1.5, 2.5) as Double // expected-error{{value of optional type 'double_bin_op_block?' (aka 'Optional<(Double, Double) -> Double>') must be unwrapped to a value of type 'double_bin_op_block' (aka '(Double, Double) -> Double')}}
2121
// expected-note@-1{{coalesce}}
2222
// expected-note@-2{{force-unwrap}}
2323
_ = b!(1.5, 2.5) as Double
@@ -26,7 +26,7 @@ func test_cfunc3_a() {
2626

2727
func test_cfunc3_b() {
2828
let b = cfunc3( { a, b in a + b } )
29-
_ = b(1.5, 2.5) as Double // expected-error{{value of optional type 'Optional<double_bin_op_block>' (aka 'Optional<(Double, Double) -> Double>') must be unwrapped to a value of type 'double_bin_op_block' (aka '(Double, Double) -> Double')}}
29+
_ = b(1.5, 2.5) as Double // expected-error{{value of optional type 'double_bin_op_block?' (aka 'Optional<(Double, Double) -> Double>') must be unwrapped to a value of type 'double_bin_op_block' (aka '(Double, Double) -> Double')}}
3030
// expected-note@-1{{coalesce}}
3131
// expected-note@-2{{force-unwrap}}
3232
_ = b!(1.5, 2.5) as Double
@@ -35,7 +35,7 @@ func test_cfunc3_b() {
3535

3636
func test_cfunc3_c() {
3737
let b = cfunc3({ $0 + $1 })
38-
_ = b(1.5, 2.5) as Double // expected-error{{value of optional type 'Optional<double_bin_op_block>' (aka 'Optional<(Double, Double) -> Double>') must be unwrapped to a value of type 'double_bin_op_block' (aka '(Double, Double) -> Double')}}
38+
_ = b(1.5, 2.5) as Double // expected-error{{value of optional type 'double_bin_op_block?' (aka 'Optional<(Double, Double) -> Double>') must be unwrapped to a value of type 'double_bin_op_block' (aka '(Double, Double) -> Double')}}
3939
// expected-note@-1{{coalesce}}
4040
// expected-note@-2{{force-unwrap}}
4141
_ = b!(1.5, 2.5) as Double

test/ClangImporter/objc_parse.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ extension Wobbler2 : NSMaybeInitWobble { // expected-error{{type 'Wobbler2' does
290290

291291
func optionalMemberAccess(_ w: NSWobbling) {
292292
w.wobble()
293-
w.wibble() // expected-error{{value of optional type 'Optional<() -> Void>' must be unwrapped to a value of type '() -> Void'}}
293+
w.wibble() // expected-error{{value of optional type '(() -> Void)?' must be unwrapped to a value of type '() -> Void'}}
294294
// expected-note@-1{{coalesce}}
295295
// expected-note@-2{{force-unwrap}}
296296
let x = w[5]!!

test/Constraints/fixes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func extraCall() {
9393
var i = 7
9494
i = i() // expected-error{{cannot call value of non-function type 'Int'}}{{8-10=}}
9595

96-
maybeFn()(5) // expected-error{{value of optional type 'Optional<((Int) -> Int)>' must be unwrapped to a value of type '(Int) -> Int'}}
96+
maybeFn()(5) // expected-error{{value of optional type '((Int) -> Int)?' must be unwrapped to a value of type '(Int) -> Int'}}
9797
// expected-note@-1{{coalesce using '??' to provide a default when the optional value contains 'nil'}}
9898
// expected-note@-2{{force-unwrap using '!' to abort execution if the optional value contains 'nil'}}
9999
}

test/expr/delayed-ident/static_var.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ struct HasClosure {
4646
var _: HasClosure = .factoryNormal(0)
4747
var _: HasClosure = .factoryReturnOpt(1)!
4848
var _: HasClosure = .factoryIUO(2)
49-
var _: HasClosure = .factoryOpt(3) // expected-error {{value of optional type 'Optional<((Int) -> HasClosure)>' must be unwrapped to a value of type '(Int) -> HasClosure'}}
49+
var _: HasClosure = .factoryOpt(3) // expected-error {{value of optional type '((Int) -> HasClosure)?' must be unwrapped to a value of type '(Int) -> HasClosure'}}
5050
// expected-note@-1{{coalesce}}
5151
// expected-note@-2{{force-unwrap}}
5252
var _: HasClosure = .factoryOpt!(4) // expected-error {{type of expression is ambiguous without more context}}

0 commit comments

Comments
 (0)