Skip to content

Commit 6c09a9b

Browse files
authored
[flang] Check assignment conformance for derived types (#99059)
Derived type assignment checking needs to account for the possibility of derived assignment. The implementation was checking compile-time conformance errors only on the path for assignments of intrinsic types. Add a static array conformance check in the derived type flow once it has been established that no defined assignment exists. Fixes #98981.
1 parent ef94732 commit 6c09a9b

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

flang/lib/Semantics/expression.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4533,6 +4533,8 @@ std::optional<ProcedureRef> ArgumentAnalyzer::TryDefinedAssignment() {
45334533
!OkLogicalIntegerAssignment(lhsType->category(), rhsType->category())) {
45344534
SayNoMatch("ASSIGNMENT(=)", true);
45354535
}
4536+
} else if (!fatalErrors_) {
4537+
CheckAssignmentConformance();
45364538
}
45374539
return std::nullopt;
45384540
}

flang/test/Semantics/array-constr-values.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ subroutine arrayconstructorvalues()
3535
intarray = [integer:: EMPLOYEE (19, "Jack"), 2, 3, 4, 5]
3636

3737
! C7112
38+
!ERROR: Dimension 1 of left-hand side has extent 3, but right-hand side has extent 2
3839
!ERROR: Value in array constructor of type 'INTEGER(4)' could not be converted to the type of the array 'employee'
3940
emparray = (/ EMPLOYEE:: EMPLOYEE(19, "Ganesh"), EMPLOYEE(22, "Omkar"), 19 /)
41+
!ERROR: Dimension 1 of left-hand side has extent 3, but right-hand side has extent 2
4042
!ERROR: Value in array constructor of type 'employeer' could not be converted to the type of the array 'employee'
4143
emparray = (/ EMPLOYEE:: EMPLOYEE(19, "Ganesh"), EMPLOYEE(22, "Ram"),EMPLOYEER("ShriniwasPvtLtd") /)
4244

flang/test/Semantics/assign10.f90

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
! RUN: %python %S/test_errors.py %s %flang_fc1
22
! Shape conformance checks on assignments
33
program test
4+
type t
5+
integer n
6+
end type
47
real :: a0, a1a(2), a1b(3), a2a(2,3), a2b(3,2)
8+
type(t) c(10)
59
a0 = 0. ! ok
610
!ERROR: No intrinsic or user-defined ASSIGNMENT(=) matches scalar REAL(4) and rank 1 array of REAL(4)
711
a0 = [0.]
@@ -20,4 +24,6 @@ program test
2024
a2a(1,:) = a1a
2125
!ERROR: Dimension 1 of left-hand side has extent 2, but right-hand side has extent 3
2226
a2a = a2b
27+
!ERROR: Dimension 1 of left-hand side has extent 10, but right-hand side has extent 0
28+
c(1:10) = c(10:1)
2329
end

0 commit comments

Comments
 (0)