Skip to content

[Diagnostics] Add a note to invalid generic function specialization d… #75486

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
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: 1 addition & 0 deletions lib/Sema/CSDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9366,6 +9366,7 @@ bool ConcreteTypeSpecialization::diagnoseAsError() {

bool GenericFunctionSpecialization::diagnoseAsError() {
emitDiagnostic(diag::cannot_explicitly_specialize_generic_function);
emitDiagnosticAt(Decl, diag::decl_declared_here, Decl);
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion test/Parse/generic_disambiguation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protocol Fungible {}
func meta<T>(_ m: T.Type) {}
func meta2<T>(_ m: T.Type, _ x: Int) {}

func generic<T>(_ x: T) {}
func generic<T>(_ x: T) {} // expected-note {{'generic' declared here}}

var a, b, c, d : Int

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ extension Int {
func baz() -> Int {}
func baz(_ x: Int = 0) -> Int {}

func gen<T>() -> T {} // expected-note 2 {{in call to function 'gen()'}}
func gen<T>() -> T {} // expected-note 2 {{in call to function 'gen()'}} expected-note 2 {{'gen()' declared here}}
}

// https://github.com/swiftlang/swift/issues/74857
Expand All @@ -28,7 +28,7 @@ func test(i: Int) {
}

extension Bool {
func foo<T>() -> T {}
func foo<T>() -> T {} // expected-note {{'foo()' declared here}}
}

let _: () -> Bool = false.foo<Int> // expected-error {{cannot explicitly specialize a generic function}}
Expand Down