title: Fortran function incorrectly accepts array of wrong shape
body: <p>Could someone explain why the following Fortran code compiles and runs?:</p>
  
  <pre><code>PROGRAM wrong_array_shape
  
    IMPLICIT NONE
    REAL :: x(2)
    INTEGER :: n
  
    x = 1.
    n = 2
  
    WRITE(*, *) f(x, n)
  
  CONTAINS
  
    REAL FUNCTION f(x, n)
  
      IMPLICIT NONE
      INTEGER, INTENT(IN) :: n
      REAL, INTENT(IN) :: x(n, n)
  
      f = x(1, 1)
  
    END FUNCTION f
  
  END PROGRAM wrong_array_shape
  </code></pre>
  
  <p>The array <code>x</code> that is declared in the main program is a one-dimensional array of length <code>2</code>, while the function is expecting a two-dimensional array of size <code>n x n</code>. I expected this to fail to compile and/or fail to run, but it runs fine and writes out the result <code>1.000000...</code> to the screen.</p>
  
  <p>I would like to have a compile-time warning (or preferably a fail) when compiling code that contains errors like this.</p>
  
  <p>In case is is relevant, I am using gfortran 9.2.0 and compile with no special flags, I compile simply with <code>gfortran wrong_array_shape.f90</code>.</p>