Skip to content

Commit 5276f2e

Browse files
authored
Merge pull request #82334 from hamishknight/record-opened
2 parents 9b21efd + c6ec315 commit 5276f2e

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

lib/Sema/CSGen.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1938,7 +1938,11 @@ namespace {
19381938
SmallVector<Type, 2> specializationArgTypes;
19391939
auto options =
19401940
TypeResolutionOptions(TypeResolverContext::InExpression);
1941-
for (auto specializationArg : specializationArgs) {
1941+
ConstraintLocatorBuilder locBuilder(locator);
1942+
for (auto idx : indices(specializationArgs)) {
1943+
auto specializationArg = specializationArgs[idx];
1944+
auto argLocator =
1945+
locBuilder.withPathElement(LocatorPathElt::GenericArgument(idx));
19421946
PackExpansionExpr *elementEnv = nullptr;
19431947
if (!OuterExpansions.empty()) {
19441948
options |= TypeResolutionFlags::AllowPackReferences;
@@ -1947,9 +1951,9 @@ namespace {
19471951
auto result = TypeResolution::resolveContextualType(
19481952
specializationArg, CurDC, options,
19491953
// Introduce type variables for unbound generics.
1950-
OpenUnboundGenericType(CS, locator),
1951-
HandlePlaceholderType(CS, locator),
1952-
OpenPackElementType(CS, locator, elementEnv));
1954+
OpenUnboundGenericType(CS, argLocator),
1955+
HandlePlaceholderType(CS, argLocator),
1956+
OpenPackElementType(CS, argLocator, elementEnv));
19531957
if (result->hasError()) {
19541958
auto &ctxt = CS.getASTContext();
19551959
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+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
// {"signature":"swift::constraints::ConstraintSystem::recordOpenedTypes(swift::constraints::ConstraintLocatorBuilder, llvm::SmallVectorImpl<std::__1::pair<swift::GenericTypeParamType*, swift::TypeVariableType*>>&, bool)"}
2-
// RUN: not --crash %target-swift-frontend -typecheck %s
2+
// RUN: not %target-swift-frontend -typecheck %s
33
a<b> class a func a < c class b < d

0 commit comments

Comments
 (0)