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

A complex literal constant can have one BOZ component, since the type
and value of the literal can be determined by converting the BOZ value
to the type of the other component. But a complex literal constant with
two BOZ components doesn't have a well-defined type. The error message
was confusing in the case; emit a better one.

Fixes https://github.com/llvm/llvm-project/issues/124201.
This commit is contained in:
Peter Klausler 2025-01-27 09:00:10 -08:00 committed by GitHub
parent e252c40210
commit 08c364280a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View File

@ -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);

View File

@ -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
@ -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')
end subroutine s