diff --git a/flang/include/flang/Evaluate/tools.h b/flang/include/flang/Evaluate/tools.h --- a/flang/include/flang/Evaluate/tools.h +++ b/flang/include/flang/Evaluate/tools.h @@ -210,16 +210,18 @@ return nullptr; } -// When an expression is a "bare" LEN= derived type parameter inquiry, +// When an expression is a "bare" LEN= or KIND= derived type parameter inquiry, // possibly wrapped in integer kind conversions &/or parentheses, return // a pointer to the Symbol with TypeParamDetails. -template const Symbol *ExtractBareLenParameter(const A &expr) { +template +const Symbol *ExtractBareLenOrKindParameter(const A &expr) { if (const auto *typeParam{ evaluate::UnwrapConvertedExpr(expr)}) { if (!typeParam->base()) { const Symbol &symbol{typeParam->parameter()}; if (const auto *tpd{symbol.detailsIf()}) { - if (tpd->attr() == common::TypeParamAttr::Len) { + if (tpd->attr() == common::TypeParamAttr::Len || + tpd->attr() == common::TypeParamAttr::Kind) { return &symbol; } } diff --git a/flang/lib/Semantics/runtime-type-info.cpp b/flang/lib/Semantics/runtime-type-info.cpp --- a/flang/lib/Semantics/runtime-type-info.cpp +++ b/flang/lib/Semantics/runtime-type-info.cpp @@ -94,13 +94,15 @@ } if (expr) { if (parameters) { - if (const Symbol * lenParam{evaluate::ExtractBareLenParameter(*expr)}) { + if (const Symbol * + lenParam{evaluate::ExtractBareLenOrKindParameter(*expr)}) { return PackageIntValue( lenParameterEnum_, FindLenParameterIndex(*parameters, *lenParam)); } } context_.Say(location_, - "Specification expression '%s' is neither constant nor a length type parameter"_err_en_US, + "Specification expression '%s' is neither constant nor a length or " + "kind type parameter"_err_en_US, expr->AsFortran()); } return PackageIntValue(deferredEnum_); diff --git a/flang/test/Semantics/resolve69.f90 b/flang/test/Semantics/resolve69.f90 --- a/flang/test/Semantics/resolve69.f90 +++ b/flang/test/Semantics/resolve69.f90 @@ -33,6 +33,8 @@ type derived(typeKind, typeLen) integer, kind :: typeKind integer, len :: typeLen + character(typeKind) :: kindValue + character(typeLen) :: lenValue end type derived type (derived(constVal, 3)) :: constDerivedKind @@ -53,3 +55,12 @@ type (derived( :, :)), pointer :: colonDerivedLen2 type (derived(4, :)), pointer :: colonDerivedLen3 end subroutine s1 +Program d5 + Type string(maxlen) + Integer,Kind :: maxlen + Character(maxlen) :: value + End Type + Type(string(80)) line + line%value = 'ok' + Print *,Trim(line%value) +End Program