Skip to content

GSB: Refactor diagnostics for redundant and conflicting superclass requirements #36712

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
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
15 changes: 8 additions & 7 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -2412,16 +2412,17 @@ NOTE(same_type_redundancy_here,none,
"same-type constraint %1 == %2 %select{written here|implied here|"
"inferred from type here}0",
(unsigned, Type, Type))
ERROR(requires_superclass_conflict,none,
"%select{generic parameter %1 cannot|protocol %1 cannot require 'Self' to|"
"%1 cannot}0 be a subclass of both %2 and %3",
(unsigned, Type, Type, Type))
ERROR(conflicting_superclass_constraints,none,
"type %0 cannot be a subclass of both %1 and %2",
(Type, Type, Type))
NOTE(conflicting_superclass_constraint,none,
"constraint conflicts with %0 : %1",
(Type, Type))
WARNING(redundant_superclass_constraint,none,
"redundant superclass constraint %0 : %1", (Type, Type))
NOTE(superclass_redundancy_here,none,
"superclass constraint %1 : %2 %select{written here|implied here|"
"inferred from type here}0",
(unsigned, Type, Type))
"superclass constraint %0 : %1 implied here",
(Type, Type))

ERROR(conflicting_layout_constraints,none,
"type %0 has conflicting constraints %1 and %2",
Expand Down
14 changes: 12 additions & 2 deletions include/swift/AST/GenericSignatureBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,15 @@ class GenericSignatureBuilder {
Type superclass,
FloatingRequirementSource source);

/// Update the layout constraint for the equivalence class of \c T.
///
/// This assumes that the constraint has already been recorded.
///
/// \returns true if anything in the equivalence class changed, false
/// otherwise.
bool updateLayout(ResolvedType type,
LayoutConstraint layout);

private:
/// Add a new superclass requirement specifying that the given
/// potential archetype has the given type as an ancestor.
Expand Down Expand Up @@ -528,8 +537,7 @@ class GenericSignatureBuilder {
LookUpConformanceInBuilder getLookupConformanceFn();

/// Lookup a protocol conformance in a module-agnostic manner.
ProtocolConformanceRef lookupConformance(CanType dependentType,
Type conformingReplacementType,
ProtocolConformanceRef lookupConformance(Type conformingReplacementType,
ProtocolDecl *conformedProtocol);

/// Enumerate the requirements that describe the signature of this
Expand Down Expand Up @@ -653,6 +661,8 @@ class GenericSignatureBuilder {

void diagnoseRedundantRequirements() const;

void diagnoseConflictingConcreteTypeRequirements() const;

bool hasExplicitConformancesImpliedByConcrete() const;

/// Describes the relationship between a given constraint and
Expand Down
3 changes: 1 addition & 2 deletions lib/AST/GenericSignature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,7 @@ bool GenericSignatureImpl::isRequirementSatisfied(
if (canFirstType->isTypeParameter())
return requiresProtocol(canFirstType, protocol);
else
return (bool)GSB->lookupConformance(/*dependentType=*/CanType(),
canFirstType, protocol);
return (bool)GSB->lookupConformance(canFirstType, protocol);
}

case RequirementKind::SameType: {
Expand Down
Loading