Skip to content

character specifier mis-parses length when it is an expression containing a comma  #519

Description

@perazz

What happens. A character declaration whose length is an expression containing a comma fails to parse when the kind is given before the length, or positionally:

character(kind=ck, len=max(n, 0)), pointer :: tmp   ! FortranSyntaxError
character(max(n, 0), ck)           :: s             ! FortranSyntaxError

Error: Intrinsic 'MAX' expects at least 2 args but found 1.

The length-first form parses correctly:

character(len=max(n, 0), kind=ck), pointer :: tmp   ! OK

Cause. In Char_Selector.match, the kind-first and positional branches omit the repmap() call that restores comma-hidden sub-expressions (present in the length-first branch), so the inner comma of the length expression stays hidden and the intrinsic argument-count check sees one argument.

Minimal module reproducer:

module m
  implicit none
  integer, parameter :: ck = 1
contains
  subroutine s(n)
    integer, intent(in) :: n
    character(kind=ck, len=max(n, 0)), pointer :: tmp
  end subroutine s
end module m

I am attaching PR #520 that should solve this. Thank you, Federico

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions