Skip to content

Don't Unnecessarily Invalidate Unreferenced Generic Parameters #41128

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 5 commits into from
Feb 3, 2022
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
1 change: 0 additions & 1 deletion lib/Sema/TypeCheckGeneric.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ void TypeChecker::checkReferencedGenericParams(GenericContext *dc) {
// Produce an error that this generic parameter cannot be bound.
paramDecl->diagnose(diag::unreferenced_generic_parameter,
paramDecl->getNameStr());
decl->setInvalid();
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions test/AutoDiff/Sema/derivative_attr_type_checking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ func vjpOriginalFunctionNotFound(_ x: Float) -> (value: Float, pullback: (Float)
fatalError()
}

struct Q { }

@derivative(of: remainder(_:_:)) // expected-error {{cannot find 'remainder' in scope}}
// expected-error @+1 {{generic parameter 'T' is not used in function signature}}
func _vjpRemainder<T: FloatingPoint>(_ x: Q, _ y: Q) -> (
value: Q, pullback: (Q) -> (Q, Q)
) {
fatalError()
}

// Test `@derivative` attribute where `value:` result does not conform to `Differentiable`.
// Invalid original function should be diagnosed first.
// expected-error @+1 {{cannot find 'nonexistentFunction' in scope}}
Expand Down
6 changes: 3 additions & 3 deletions test/Constraints/overload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,12 @@ R_28051973().f(r28051973) // expected-error {{cannot use mutating member on immu
// Fix for CSDiag vs CSSolver disagreement on what constitutes a
// valid overload.

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

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

// Ensure we select the overload of '??' returning T? rather than T.
func SR3817(_ d: [String : Any], _ s: String, _ t: String) -> Any {
Expand Down
4 changes: 3 additions & 1 deletion test/Generics/unbound.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ extension GC {


class SomeClassWithInvalidMethod {
func method<T>() { // expected-error {{generic parameter 'T' is not used in function signature}}
func method<T>() { // expected-note {{in call to function 'method()'}}
// expected-error@-1 {{generic parameter 'T' is not used in function signature}}
self.method()
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
}
}

Expand Down