This patch creates a temporary of the appropriate length while lowering SetLength.
The corresponding character can be truncated or padded if necessary.
This fix issue with array constructor in argument and also with statement function.
character(7) :: str = "1234567" call s(str(1:1)) contains subroutine s(a) character(*) :: a call s2([Character(3)::a]) end subroutine subroutine s2(c) character(3) :: c(1) print "(4a)", c(1), "end" end subroutine end
The example prior the patch prints 123end instead of 1. end
I do not think the temp should happen on the arguments, the actual arguments must be longer than the dummy so that the program is compliant (F2018 standard 15.5.2.11 Sequence association). So replacing the character length for the argument should be enough: only "virtual" truncation can happen.
On the result side however, I think you will need to create a temp with the result symbol length and make an assignment (charHelper.createAssign) so that the padding can occure if needed (you can skip it if it can be proved at compile time that the result length is smaller or equal to the expression length, in which case replaceScalarCharacterLength should be sufficient to insert "virtual" truncation).