Skip to content

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
@eugeneepshteyn eugeneepshteyn deleted the fix-err-msg branch October 21, 2025 22:25
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