Skip to content

Commit 440bc39

Browse files
committed
[Diagnostics] Don't print pack element archetypes in diagnostics
1 parent 58ffca8 commit 440bc39

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/Sema/CSDiagnostics.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "swift/AST/Decl.h"
2323
#include "swift/AST/DiagnosticEngine.h"
2424
#include "swift/AST/Expr.h"
25+
#include "swift/AST/GenericEnvironment.h"
2526
#include "swift/AST/Identifier.h"
2627
#include "swift/AST/OperatorNameLookup.h"
2728
#include "swift/AST/Types.h"
@@ -123,6 +124,11 @@ class FailureDiagnostic {
123124
return resolvedType->is<UnresolvedType>() && GP ? GP : resolvedType;
124125
}
125126

127+
if (type->hasElementArchetype()) {
128+
auto *env = getDC()->getGenericEnvironmentOfContext();
129+
return env->mapElementTypeIntoPackContext(type);
130+
}
131+
126132
if (auto *packType = type->getAs<PackType>()) {
127133
if (packType->getNumElements() == 1) {
128134
auto eltType = resolveType(packType->getElementType(0));

test/Constraints/pack-expansion-expressions.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,16 @@ func outerArchetype<each T, U>(t: repeat each T, u: U) where repeat each T: P {
6666
func sameElement<each T, U>(t: repeat each T, u: U) where repeat each T: P, repeat each T == U {
6767
// expected-error@-1{{same-element requirements are not yet supported}}
6868

69-
// FIXME: Opened element archetypes in diagnostics
7069
let _: (repeat each T) = (repeat (each t).f(u))
71-
// expected-error@-1 {{cannot convert value of type 'U' to expected argument type 'τ_1_0'}}
70+
// expected-error@-1 {{cannot convert value of type 'U' to expected argument type 'each T'}}
7271
}
7372

7473
func forEachEach<each C, U>(c: repeat each C, function: (U) -> Void)
7574
where repeat each C: Collection, repeat (each C).Element == U {
7675
// expected-error@-1{{same-element requirements are not yet supported}}
7776

78-
// FIXME: Opened element archetypes in diagnostics
7977
_ = (repeat (each c).forEach(function))
80-
// expected-error@-1 {{cannot convert value of type '(U) -> Void' to expected argument type '(τ_1_0.Element) throws -> Void'}}
78+
// expected-error@-1 {{cannot convert value of type '(U) -> Void' to expected argument type '(each C.Element) throws -> Void'}}
8179
}
8280

8381
func typeReprPacks<each T: ExpressibleByIntegerLiteral>(_ t: repeat each T) {

0 commit comments

Comments
 (0)