Skip to content

[flang] Improve error message on bad complex literal. #124331

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 1 commit into from
Jan 27, 2025
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
5 changes: 5 additions & 0 deletions flang/lib/Evaluate/tools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ ConvertRealOperandsResult ConvertRealOperands(
return {AsSameKindExprs<TypeCategory::Real>(
ConvertTo(ry, std::move(bx)), std::move(ry))};
},
[&](BOZLiteralConstant &&,
BOZLiteralConstant &&) -> ConvertRealOperandsResult {
messages.Say("operands cannot both be BOZ"_err_en_US);
return std::nullopt;
},
[&](auto &&, auto &&) -> ConvertRealOperandsResult { // C718
messages.Say(
"operands must be INTEGER, UNSIGNED, REAL, or BOZ"_err_en_US);
Expand Down
4 changes: 3 additions & 1 deletion flang/test/Semantics/complex01.f90
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
! RUN: %python %S/test_errors.py %s %flang_fc1
! C718 Each named constant in a complex literal constant shall be of type
! C718 Each named constant in a complex literal constant shall be of type
! integer or real.
subroutine s()
integer :: ivar = 35
Expand Down Expand Up @@ -30,4 +30,6 @@ subroutine s()
complex :: cvar11 = (cconst, 1.0)
!ERROR: operands must be INTEGER, UNSIGNED, REAL, or BOZ
complex :: cvar12 = (lconst, 1.0)
!ERROR: operands cannot both be BOZ
complex :: cvar13 = (z'3f700000', z'00000000')
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there already a test for creating COMPLEX from one BOZ component?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know.

end subroutine s
Loading