Skip to content

[flang] Add missing symbol names to the error message #148888

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 2 commits into from
Jul 16, 2025

Conversation

eugeneepshteyn
Copy link
Contributor

Fixes #140485

@eugeneepshteyn
Copy link
Contributor Author

New output:

$ flang -c snfm_import_err02_2.f90
error: Semantic errors in snfm_import_err02_2.f90
./snfm_import_err02_2.f90:20:15: error: A distinct 'i' is already present in this scope
         import i
                ^
./snfm_import_err02_2.f90:7:14: Previous declaration of 'i'
    integer :: i
               ^
./snfm_import_err02_2.f90:11:14: Declaration of 'i' in host scope
    real    :: i
               ^

There are already semantic tests that check for this error, they are just checking the first error line.

@eugeneepshteyn eugeneepshteyn marked this pull request as ready for review July 15, 2025 16:52
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Jul 15, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 15, 2025

@llvm/pr-subscribers-flang-semantics

Author: Eugene Epshteyn (eugeneepshteyn)

Changes

Fixes #140485


Full diff: https://github.com/llvm/llvm-project/pull/148888.diff

1 Files Affected:

  • (modified) flang/lib/Semantics/resolve-names.cpp (+4-2)
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 96faa5fd954cd..b3268605e7c0c 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -8574,8 +8574,10 @@ bool ResolveNamesVisitor::Pre(const parser::ImportStmt &x) {
         } else {
           Say(name,
               "A distinct '%s' is already present in this scope"_err_en_US)
-              .Attach(symbol->name(), "Previous declaration of '%s'"_en_US)
-              .Attach(outer->name(), "Declaration of '%s' in host scope"_en_US);
+              .Attach(symbol->name(), "Previous declaration of '%s'"_en_US,
+                  symbol->name().ToString())
+              .Attach(outer->name(), "Declaration of '%s' in host scope"_en_US,
+                  outer->name().ToString());
         }
       }
     } else {

Copy link
Contributor

@akuhlens akuhlens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, one improvement might be to add a test that checks the error message.

@eugeneepshteyn eugeneepshteyn merged commit 9f20397 into llvm:main Jul 16, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Flang] The variable outputted in the compilation error message is invalid
4 participants