[flang] Any type can appear in a structure constructor for an unlimited polymorphic allocatable component
A bogus error message is appearing for structure constructors containing values that correspond to unlimited polymorphic allocatable components. A value of any type can actually be used. Differential Revision: https://reviews.llvm.org/D117154
This commit is contained in:
parent
9b85d7e166
commit
bb59b38e87
|
@ -1739,7 +1739,10 @@ MaybeExpr ExpressionAnalyzer::Analyze(
|
|||
} else if (IsAllocatable(*symbol) && IsBareNullPointer(&*value)) {
|
||||
// NULL() with no arguments allowed by 7.5.10 para 6 for ALLOCATABLE
|
||||
} else if (auto symType{DynamicType::From(symbol)}) {
|
||||
if (valueType) {
|
||||
if (IsAllocatable(*symbol) && symType->IsUnlimitedPolymorphic() &&
|
||||
valueType) {
|
||||
// ok
|
||||
} else if (valueType) {
|
||||
AttachDeclaration(
|
||||
Say(expr.source,
|
||||
"Value in structure constructor of type %s is "
|
||||
|
|
|
@ -66,5 +66,18 @@ module module1
|
|||
k=2,m=3))
|
||||
!ERROR: ABSTRACT derived type 'abstract' may not be used in a structure constructor
|
||||
call abstractarg(abstract(0)(n=1))
|
||||
!This case is ok
|
||||
end subroutine errors
|
||||
subroutine polycomponent
|
||||
type :: poly
|
||||
class(*), allocatable :: p
|
||||
end type poly
|
||||
type(poly) :: x
|
||||
! These cases are not errors
|
||||
x = poly(1)
|
||||
x = poly('hello')
|
||||
x = poly(type1(1)(123))
|
||||
!ERROR: Value in structure constructor is incompatible with component 'p' of type CLASS(*)
|
||||
x = poly(z'feedface')
|
||||
end subroutine
|
||||
end module module1
|
||||
|
|
Loading…
Reference in New Issue