mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Strongly prefer available declarations to unavailable ones in type checking.
Fixes rdar://problem/18847642, rdar://problem/16554496, and the current 1_stdlib/Array.swift. Swift SVN r25212
This commit is contained in:
@@ -37,6 +37,10 @@ void ConstraintSystem::increaseScore(ScoreKind kind) {
|
||||
log.indent(solverState->depth * 2);
|
||||
log << "(increasing score due to ";
|
||||
switch (kind) {
|
||||
case SK_Unavailable:
|
||||
log << "use of an unavailable declaration";
|
||||
break;
|
||||
|
||||
case SK_Fix:
|
||||
log << "attempting to fix the source";
|
||||
break;
|
||||
@@ -671,17 +675,6 @@ SolutionCompareResult ConstraintSystem::compareSolutions(
|
||||
}
|
||||
}
|
||||
|
||||
// If one declaration is available and the other is not,
|
||||
bool unavail1 = decl1->getAttrs().isUnavailable(cs.getASTContext());
|
||||
bool unavail2 = decl2->getAttrs().isUnavailable(cs.getASTContext());
|
||||
if (unavail1 != unavail2) {
|
||||
if (unavail1)
|
||||
++score2;
|
||||
else
|
||||
++score1;
|
||||
continue;
|
||||
}
|
||||
|
||||
// If both declarations come from Clang, and one is a type and the other
|
||||
// is a function, prefer the function.
|
||||
if (decl1->hasClangNode() &&
|
||||
|
||||
@@ -1311,6 +1311,11 @@ void ConstraintSystem::resolveOverload(ConstraintLocator *locator,
|
||||
refType = ImplicitlyUnwrappedOptionalType::get(refType->getRValueType());
|
||||
}
|
||||
|
||||
// If the declaration is unavailable, note that in the score.
|
||||
if (choice.getDecl()->getAttrs().isUnavailable(getASTContext())) {
|
||||
increaseScore(SK_Unavailable);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -705,6 +705,8 @@ struct SelectedOverload {
|
||||
enum ScoreKind {
|
||||
// These values are used as indices into a Score value.
|
||||
|
||||
/// A reference to an @unavailable declaration.
|
||||
SK_Unavailable,
|
||||
/// A fix needs to be applied to the source.
|
||||
SK_Fix,
|
||||
/// An implicit force of an implicitly unwrapped optional value.
|
||||
|
||||
@@ -104,3 +104,12 @@ __weak id globalWeakVar;
|
||||
@protocol FooDelegate <NSObject>
|
||||
@property (nonatomic, assign, readonly, getter=isStarted) BOOL started;
|
||||
@end
|
||||
|
||||
// rdar://problem/18847642
|
||||
@interface NonNullDefaultInit
|
||||
-(nonnull instancetype)init;
|
||||
@end
|
||||
|
||||
@interface NonNullDefaultInitSub : NonNullDefaultInit
|
||||
+ (null_unspecified instancetype)sub;
|
||||
@end
|
||||
|
||||
@@ -144,3 +144,10 @@ class View: NSView {
|
||||
var p = MyViewController.init()
|
||||
}
|
||||
}
|
||||
|
||||
// rdar://problem/19726164
|
||||
class NonNullDefaultInitSubSub : NonNullDefaultInitSub {
|
||||
func foo() {
|
||||
var x: NonNullDefaultInitSubSub? = NonNullDefaultInitSubSub()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,3 +106,11 @@ struct HasX1aProperty {
|
||||
write(prop) // no error, not ambiguous
|
||||
}
|
||||
}
|
||||
|
||||
// rdar://problem/16554496
|
||||
@availability(*, unavailable)
|
||||
func availTest(x: Int) {}
|
||||
func availTest(x: Any) { println("this one") }
|
||||
func doAvailTest(x: Int) {
|
||||
availTest(x)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user