Skip to content

Commit 4b8ba3c

Browse files
authored
Don't Unnecessarily Invalidate Unreferenced Generic Parameters (#41128)
1 parent 973f5d2 commit 4b8ba3c

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

lib/Sema/TypeCheckGeneric.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,6 @@ void TypeChecker::checkReferencedGenericParams(GenericContext *dc) {
506506
// Produce an error that this generic parameter cannot be bound.
507507
paramDecl->diagnose(diag::unreferenced_generic_parameter,
508508
paramDecl->getNameStr());
509-
decl->setInvalid();
510509
}
511510
}
512511
}

test/AutoDiff/Sema/derivative_attr_type_checking.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ func vjpOriginalFunctionNotFound(_ x: Float) -> (value: Float, pullback: (Float)
7979
fatalError()
8080
}
8181

82+
struct Q { }
83+
84+
@derivative(of: remainder(_:_:)) // expected-error {{cannot find 'remainder' in scope}}
85+
// expected-error @+1 {{generic parameter 'T' is not used in function signature}}
86+
func _vjpRemainder<T: FloatingPoint>(_ x: Q, _ y: Q) -> (
87+
value: Q, pullback: (Q) -> (Q, Q)
88+
) {
89+
fatalError()
90+
}
91+
8292
// Test `@derivative` attribute where `value:` result does not conform to `Differentiable`.
8393
// Invalid original function should be diagnosed first.
8494
// expected-error @+1 {{cannot find 'nonexistentFunction' in scope}}

test/Constraints/overload.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,12 @@ R_28051973().f(r28051973) // expected-error {{cannot use mutating member on immu
187187
// Fix for CSDiag vs CSSolver disagreement on what constitutes a
188188
// valid overload.
189189

190-
func overloadedMethod(n: Int) {} // expected-note {{'overloadedMethod(n:)' declared here}}
191-
func overloadedMethod<T>() {}
190+
func overloadedMethod(n: Int) {}
191+
func overloadedMethod<T>() {} // expected-note {{in call to function 'overloadedMethod()'}}
192192
// expected-error@-1 {{generic parameter 'T' is not used in function signature}}
193193

194194
overloadedMethod()
195-
// expected-error@-1 {{missing argument for parameter 'n' in call}}
195+
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
196196

197197
// Ensure we select the overload of '??' returning T? rather than T.
198198
func SR3817(_ d: [String : Any], _ s: String, _ t: String) -> Any {

test/Generics/unbound.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@ extension GC {
5151

5252

5353
class SomeClassWithInvalidMethod {
54-
func method<T>() { // expected-error {{generic parameter 'T' is not used in function signature}}
54+
func method<T>() { // expected-note {{in call to function 'method()'}}
55+
// expected-error@-1 {{generic parameter 'T' is not used in function signature}}
5556
self.method()
57+
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
5658
}
5759
}
5860

0 commit comments

Comments
 (0)