Skip to content

[silgen] Emit the location of the original function def if SILGen is erroring on a duplicate symbol definition. #72760

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
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
3 changes: 3 additions & 0 deletions include/swift/AST/DiagnosticsSIL.def
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ ERROR(bridging_objcbridgeable_broken,none,
ERROR(sil_function_redefinition,none,
"multiple definitions of symbol '%0'",
(StringRef))
NOTE(sil_function_redefinition_note,none,
"other definition here",
())

ERROR(invalid_sil_builtin,none,
"INTERNAL ERROR: invalid use of builtin: %0",
Expand Down
2 changes: 2 additions & 0 deletions lib/SILGen/SILGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,8 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
if (!f->empty()) {
diagnose(constant.getAsRegularLocation(), diag::sil_function_redefinition,
f->getName());
if (f->hasLocation())
diagnose(f->getLocation(), diag::sil_function_redefinition_note);
return;
}

Expand Down
4 changes: 2 additions & 2 deletions test/SILGen/diagnose_duplicate_functions.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// RUN: %target-swift-emit-silgen %s -o /dev/null -verify

@_silgen_name("foo")
func a(_ x: Int) -> Int {
func a(_ x: Int) -> Int { // expected-note {{other definition here}}
return x
}

Expand All @@ -11,7 +11,7 @@ func b(_ x: Int) -> Int { // expected-error {{multiple definitions of symbol 'fo
}

@_cdecl("bar")
func c(_ x: Int) -> Int {
func c(_ x: Int) -> Int { // expected-note {{other definition here}}
return x
}

Expand Down