Skip to content

[GSB] Error types end up as unresolved equivalence classes. #16893

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

Merged
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
6 changes: 6 additions & 0 deletions lib/AST/GenericSignatureBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3944,6 +3944,12 @@ ResolvedType GenericSignatureBuilder::maybeResolveEquivalenceClass(
Type type,
ArchetypeResolutionKind resolutionKind,
bool wantExactPotentialArchetype) {
// An error type is best modeled as an unresolved potential archetype, since
// there's no way to be sure what it is actually meant to be.
if (type->is<ErrorType>()) {
return ResolvedType::forUnresolved(nullptr);
}

// The equivalence class of a generic type is known directly.
if (auto genericParam = type->getAs<GenericTypeParamType>()) {
unsigned index = GenericParamKey(genericParam).findIndexIn(
Expand Down
2 changes: 1 addition & 1 deletion test/IDE/print_ast_tc_decls_errors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ protocol AssociatedType1 {
// TYREPR: {{^}} associatedtype AssociatedTypeDecl4 : FooNonExistentProtocol, BarNonExistentProtocol{{$}}

associatedtype AssociatedTypeDecl5 : FooClass
// CHECK: {{^}} associatedtype AssociatedTypeDecl5{{$}}
// CHECK: {{^}} associatedtype AssociatedTypeDecl5 : FooClass{{$}}
}

//===---
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// RUN: %target-typecheck-verify-swift

protocol P {
associatedtype A : P where A.X == Self
associatedtype X : P where P.A == Self
// expected-error@-1{{associated type 'A' can only be used with a concrete type or generic parameter base}}
}