diff --git a/flang/lib/Evaluate/intrinsics.cpp b/flang/lib/Evaluate/intrinsics.cpp index 876c2aed4ffd..166dae93178c 100644 --- a/flang/lib/Evaluate/intrinsics.cpp +++ b/flang/lib/Evaluate/intrinsics.cpp @@ -2264,7 +2264,7 @@ std::optional IntrinsicInterface::Match( messages.Say("'kind=' argument must be a constant scalar integer " "whose value is a supported kind for the " "intrinsic result type"_err_en_US); - return std::nullopt; + // use default kind below for error recovery } else if (kindDummyArg->flags.test(ArgFlag::defaultsToSameKind)) { CHECK(sameArg); resultType = *sameArg->GetType(); @@ -2274,6 +2274,8 @@ std::optional IntrinsicInterface::Match( DynamicType{TypeCategory::Integer, defaults.sizeIntegerKind()}; } else { CHECK(kindDummyArg->flags.test(ArgFlag::defaultsToDefaultForResult)); + } + if (!resultType) { int kind{defaults.GetDefaultKind(*category)}; if (*category == TypeCategory::Character) { // ACHAR & CHAR resultType = DynamicType{kind, 1}; diff --git a/flang/test/Semantics/kinds06.f90 b/flang/test/Semantics/kinds06.f90 new file mode 100644 index 000000000000..f5b488ebc714 --- /dev/null +++ b/flang/test/Semantics/kinds06.f90 @@ -0,0 +1,4 @@ +!RUN: %python %S/test_errors.py %s %flang_fc1 +!ERROR: 'kind=' argument must be a constant scalar integer whose value is a supported kind for the intrinsic result type +print *, real(1.,666) +end