PSyclone: [psyir] Check on whether dimensioning symbol is local does not work when symbol is in an ancestor scope.

For the following Fortran:

module my_mod
  integer :: dim
contains
  subroutine init()
    dim = 10
  end subroutine
  subroutine work()
    real, dimension(dim) :: my_array
  end subroutine
end module

Then PSyclone complains:

If a local datasymbol is used as part of a dimension declaration then it should be a constant, but 'dim' is not.

The problem is in ArrayType._validate_shape where the Symbol being referred to in the shape specification is looked up. It is found to have a ‘local’ interface and not be a constant. Both of which are correct. However, no check is made on which SymbolTable the symbol is in.

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Comments: 20 (7 by maintainers)

Commits related to this issue

Most upvoted comments

Unless I’ve missed something, I think the problem is that we construct the shape list before we create the symbol to which it belongs (because we have to make the type first). We’d need to alter the DataSymbol constructor so that datatype was optional. Rather than re-engineer the PSyIR classes, I think it would be more natural to do this check in e.g. psyir.backends.fortran.FortranWriter.gen_decls since that knows which symbol table it is dealing with.