Skip to content

Commit 08c3642

Browse files
authored
[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 #124201.
1 parent e252c40 commit 08c3642

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

flang/lib/Evaluate/tools.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@ ConvertRealOperandsResult ConvertRealOperands(
212212
return {AsSameKindExprs<TypeCategory::Real>(
213213
ConvertTo(ry, std::move(bx)), std::move(ry))};
214214
},
215+
[&](BOZLiteralConstant &&,
216+
BOZLiteralConstant &&) -> ConvertRealOperandsResult {
217+
messages.Say("operands cannot both be BOZ"_err_en_US);
218+
return std::nullopt;
219+
},
215220
[&](auto &&, auto &&) -> ConvertRealOperandsResult { // C718
216221
messages.Say(
217222
"operands must be INTEGER, UNSIGNED, REAL, or BOZ"_err_en_US);

flang/test/Semantics/complex01.f90

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
! RUN: %python %S/test_errors.py %s %flang_fc1
2-
! C718 Each named constant in a complex literal constant shall be of type
2+
! C718 Each named constant in a complex literal constant shall be of type
33
! integer or real.
44
subroutine s()
55
integer :: ivar = 35
@@ -30,4 +30,6 @@ subroutine s()
3030
complex :: cvar11 = (cconst, 1.0)
3131
!ERROR: operands must be INTEGER, UNSIGNED, REAL, or BOZ
3232
complex :: cvar12 = (lconst, 1.0)
33+
!ERROR: operands cannot both be BOZ
34+
complex :: cvar13 = (z'3f700000', z'00000000')
3335
end subroutine s

0 commit comments

Comments
 (0)