Merge pull request #17392 from huonw/redefinition-swift-4-compat

Swift 4 compatibility hack for redeclaration of properties in generic type and extension
This commit is contained in:
Huon Wilson
2018-06-22 11:22:51 +10:00
committed by GitHub
7 changed files with 54 additions and 9 deletions

View File

@@ -1747,7 +1747,30 @@ bool swift::conflicting(ASTContext &ctx,
}
// Otherwise, the declarations conflict if the overload types are the same.
return sig1Type == sig2Type;
if (sig1Type != sig2Type)
return false;
// The Swift 5 overload types are the same, but similar to the above, prior to
// Swift 5, a variable not in an extension of a generic type got a null
// overload type instead of a function type as it does now, so we really
// follow that behaviour and warn if there's going to be a conflict in future.
if (!ctx.isSwiftVersionAtLeast(5)) {
auto swift4Sig1Type = sig1.IsVariable && !sig1.InExtensionOfGenericType
? CanType()
: sig1Type;
auto swift4Sig2Type = sig1.IsVariable && !sig2.InExtensionOfGenericType
? CanType()
: sig1Type;
if (swift4Sig1Type != swift4Sig2Type) {
// Old was different to the new behaviour!
if (wouldConflictInSwift5)
*wouldConflictInSwift5 = true;
return false;
}
}
return true;
}
static Type mapSignatureFunctionType(ASTContext &ctx, Type type,