Skip to content

Commit 687b3f5

Browse files
committed
Downgrade redeclaration with value generic arg to warning right now
1 parent a9df0bd commit 687b3f5

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

include/swift/AST/Decl.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,9 @@ struct OverloadSignature {
310310
/// Whether this is a macro.
311311
unsigned IsMacro : 1;
312312

313+
/// Whether this is a generic argument.
314+
unsigned IsGenericArg : 1;
315+
313316
/// Whether this signature is part of a protocol extension.
314317
unsigned InProtocolExtension : 1;
315318

@@ -323,8 +326,10 @@ struct OverloadSignature {
323326
OverloadSignature()
324327
: UnaryOperator(UnaryOperatorKind::None), IsInstanceMember(false),
325328
IsVariable(false), IsFunction(false), IsAsyncFunction(false),
326-
IsDistributed(false), InProtocolExtension(false),
327-
InExtensionOfGenericType(false), HasOpaqueReturnType(false) { }
329+
IsDistributed(false), IsEnumElement(false), IsNominal(false),
330+
IsTypeAlias(false), IsMacro(false), IsGenericArg(false),
331+
InProtocolExtension(false), InExtensionOfGenericType(false),
332+
HasOpaqueReturnType(false) { }
328333
};
329334

330335
/// Determine whether two overload signatures conflict.

lib/AST/Decl.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3859,6 +3859,13 @@ bool swift::conflicting(ASTContext &ctx,
38593859
if (sig1.IsFunction != sig2.IsFunction)
38603860
return true;
38613861

3862+
// Gracefully handle the case where value generic arguments were introduced
3863+
// as a conflicting value with static variables of the same name.
3864+
if (sig1.IsGenericArg != sig2.IsGenericArg) {
3865+
*wouldConflictInSwift5 = true;
3866+
return true;
3867+
}
3868+
38623869
// Variables always conflict with non-variables with the same signature.
38633870
// (e.g variables with zero argument functions, variables with type
38643871
// declarations)
@@ -4037,6 +4044,7 @@ OverloadSignature ValueDecl::getOverloadSignature() const {
40374044
signature.IsNominal = isa<NominalTypeDecl>(this);
40384045
signature.IsTypeAlias = isa<TypeAliasDecl>(this);
40394046
signature.IsMacro = isa<MacroDecl>(this);
4047+
signature.IsGenericArg = isa<GenericTypeParamDecl>(this);
40404048
signature.HasOpaqueReturnType =
40414049
!signature.IsVariable && (bool)getOpaqueResultTypeDecl();
40424050

0 commit comments

Comments
 (0)