Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6636,8 +6636,12 @@ static ConstraintFix *maybeWarnAboutExtraneousCast(
}

// Except for forced cast expressions, if optionals are more than a single
// level difference, we don't need to record any fix.
if (!isExpr<ForcedCheckedCastExpr>(anchor) && extraOptionals > 1)
// level difference or there is a single level between the types but an extra
// level of optional is added to subexpr via OptionalEvaluationExpr, we don't
// need to record any fix.
if (!isExpr<ForcedCheckedCastExpr>(anchor) &&
(extraOptionals > 1 ||
isExpr<OptionalEvaluationExpr>(castExpr->getSubExpr())))
return nullptr;

// Always succeed
Expand Down
14 changes: 14 additions & 0 deletions test/Constraints/casts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -535,3 +535,17 @@ protocol PP2: PP1 { }
extension Optional: PP1 where Wrapped == PP2 { }

nil is PP1 // expected-error {{'nil' requires a contextual type}}

// SR-15039
enum ChangeType<T> {
case initial(T)
case delta(previous: T, next: T)
case unset

var delta: (previous: T?, next: T)? { nil }
}

extension ChangeType where T == String? {
var foo: String? { return self.delta?.previous as? String } // OK
var bar: String? { self.delta?.next }
}