diff --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp --- a/flang/lib/Semantics/expression.cpp +++ b/flang/lib/Semantics/expression.cpp @@ -2024,8 +2024,9 @@ "component", "value")}; if (checked && *checked && GetRank(*componentShape) > 0 && GetRank(*valueShape) == 0 && - !IsExpandableScalar(*converted, GetFoldingContext(), - *componentShape, true /*admit PURE call*/)) { + (IsDeferredShape(*symbol) || + !IsExpandableScalar(*converted, GetFoldingContext(), + *componentShape, true /*admit PURE call*/))) { AttachDeclaration( Say(expr.source, "Scalar value cannot be expanded to shape of array component '%s'"_err_en_US, diff --git a/flang/test/Semantics/data01.f90 b/flang/test/Semantics/data01.f90 --- a/flang/test/Semantics/data01.f90 +++ b/flang/test/Semantics/data01.f90 @@ -12,7 +12,7 @@ integer :: myAge = 2 type(person) associated type hasAlloc - integer, allocatable :: a(:) + integer, allocatable :: a end type end diff --git a/flang/test/Semantics/structconst06.f90 b/flang/test/Semantics/structconst06.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Semantics/structconst06.f90 @@ -0,0 +1,9 @@ +! RUN: %python %S/test_errors.py %s %flang_fc1 +! Don't expand scalars for allocatable components. +module m + type t + real, allocatable :: a(:) + end type + !ERROR: Scalar value cannot be expanded to shape of array component 'a' + type(t) :: x = t(0.) +end module