Skip to content

Commit 8f66e61

Browse files
authored
Merge pull request #82340 from hamishknight/record-opened-6.2
2 parents dc71b7e + 4d654b2 commit 8f66e61

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

lib/Sema/CSGen.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,7 +1933,11 @@ namespace {
19331933
SmallVector<Type, 2> specializationArgTypes;
19341934
auto options =
19351935
TypeResolutionOptions(TypeResolverContext::InExpression);
1936-
for (auto specializationArg : specializationArgs) {
1936+
ConstraintLocatorBuilder locBuilder(locator);
1937+
for (auto idx : indices(specializationArgs)) {
1938+
auto specializationArg = specializationArgs[idx];
1939+
auto argLocator =
1940+
locBuilder.withPathElement(LocatorPathElt::GenericArgument(idx));
19371941
PackExpansionExpr *elementEnv = nullptr;
19381942
if (!OuterExpansions.empty()) {
19391943
options |= TypeResolutionFlags::AllowPackReferences;
@@ -1942,9 +1946,9 @@ namespace {
19421946
auto result = TypeResolution::resolveContextualType(
19431947
specializationArg, CurDC, options,
19441948
// Introduce type variables for unbound generics.
1945-
OpenUnboundGenericType(CS, locator),
1946-
HandlePlaceholderType(CS, locator),
1947-
OpenPackElementType(CS, locator, elementEnv));
1949+
OpenUnboundGenericType(CS, argLocator),
1950+
HandlePlaceholderType(CS, argLocator),
1951+
OpenPackElementType(CS, argLocator, elementEnv));
19481952
if (result->hasError()) {
19491953
auto &ctxt = CS.getASTContext();
19501954
result = PlaceholderType::get(ctxt, specializationArg);

test/Macros/macro_explicit_generic_args.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,16 @@ func test(i: Int) {
2222
// expected-error@-1{{external macro implementation type 'A.B' could not be found for macro 'resolve'; plugin for module 'A' not found}}
2323
}
2424

25+
@freestanding(expression)
26+
macro OverloadedMacro<T, U>(_ x: T, _ y: U) // expected-error {{requires a definition}} expected-note {{declared here}}
27+
28+
@freestanding(expression)
29+
macro OverloadedMacro<T, U>(_ x: T, _ y: U, z: Int = 0) // expected-error {{requires a definition}}
30+
31+
// Make sure we don't crash.
32+
func testOverloadedMacro() {
33+
struct S<T> {} // expected-note 2{{'T' declared as parameter to type 'S'}}
34+
_ = #OverloadedMacro<S, S>
35+
// expected-error@-1 2{{generic parameter 'T' could not be inferred}}
36+
// expected-error@-2 {{missing arguments for parameters #1, #2 in macro expansion}}
37+
}

test/Sema/generic_specialization.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,12 @@ do {
7676
// expected-error@+1:13 {{cannot specialize non-generic type 'module<Swift>'}}{{none}}
7777
func f(_: Swift<Int>) {}
7878
}
79+
80+
func overloadedGenericFn<T, U>(_ x: T, _ y: U) {} // expected-note {{found this candidate}}
81+
func overloadedGenericFn<T, U>(_ x: T, _ y: U, z: Int = 0) {} // expected-note {{found this candidate}}
82+
83+
// Make sure we don't crash.
84+
func testSpecializedOverloaded() {
85+
struct S<T> {}
86+
_ = overloadedGenericFn<S, S> // expected-error {{no exact matches}}
87+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// {"signature":"swift::constraints::ConstraintSystem::recordOpenedTypes(swift::constraints::ConstraintLocatorBuilder, llvm::SmallVectorImpl<std::__1::pair<swift::GenericTypeParamType*, swift::TypeVariableType*>>&, bool)"}
2+
// RUN: not %target-swift-frontend -typecheck %s
3+
a<b> class a func a < c class b < d

0 commit comments

Comments
 (0)