Index: flang/lib/Semantics/check-select-type.cpp =================================================================== --- flang/lib/Semantics/check-select-type.cpp +++ flang/lib/Semantics/check-select-type.cpp @@ -39,7 +39,7 @@ if (std::holds_alternative(guard.u)) { typeCases_.emplace_back(stmt, std::nullopt); } else if (std::optional type{GetGuardType(guard)}) { - if (PassesChecksOnGuard(guard, *type)) { + if (PassesChecksOnGuard(guard, *type, stmt)) { typeCases_.emplace_back(stmt, *type); } else { hasErrors_ = true; @@ -72,12 +72,21 @@ } bool PassesChecksOnGuard(const parser::TypeGuardStmt::Guard &guard, - const evaluate::DynamicType &guardDynamicType) { + const evaluate::DynamicType &guardDynamicType, + const parser::Statement &stmt) { return std::visit( common::visitors{ [](const parser::Default &) { return true; }, [&](const parser::TypeSpec &typeSpec) { if (const DeclTypeSpec * spec{typeSpec.declTypeSpec}) { + if (spec->AsIntrinsic() && + !selectorType_.IsUnlimitedPolymorphic()) { // C1162 + context_.Say(stmt.source, + "If selector is not Unlimited Polymorphic, " + "intrinsic type specification must not be specified " + "in type guard statement"_err_en_US); + return false; + } if (spec->category() == DeclTypeSpec::Character && !guardDynamicType.IsAssumedLengthCharacter()) { // C1160 context_.Say(parser::FindSourceLocation(typeSpec), Index: flang/test/Semantics/selecttype04.f90 =================================================================== --- /dev/null +++ flang/test/Semantics/selecttype04.f90 @@ -0,0 +1,26 @@ +type base + integer :: ii +end type +type,extends(base) :: ext + integer :: jj +end type + +call CheckC1162() +contains + subroutine CheckC1162() + class(base),allocatable :: aobj + allocate(ext::aobj) + select type(sel=>aobj) + ! OK + class is(base) + !ERROR all: Intrinsic Type specification must not be specified + type is(integer) + type is(real) + type is(logical) + type is(character(len=*)) + type is(complex) + ! OK + class default + end select + end +end