# Unclassifiable statement error with a function that seems fine

**URL:** <https://fortran-lang.discourse.group/t/unclassifiable-statement-error-with-a-function-that-seems-fine/3939>\
**Category:** Help\
**Created:** [July 6, 2022, 6:37pm UTC](https://fortran-lang.discourse.group/t/unclassifiable-statement-error-with-a-function-that-seems-fine/3939 "2022-07-06T18:37:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![yeti0904](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/yeti0904/32/1886_2.png) [@yeti0904](https://fortran-lang.discourse.group/u/yeti0904)\
**Post date:** [July 6, 2022, 6:37pm UTC](https://fortran-lang.discourse.group/t/unclassifiable-statement-error-with-a-function-that-seems-fine/3939/1 "2022-07-06T18:37:37Z")

</div>

this is the code

```auto
module Util
    use, intrinsic :: iso_c_binding, only : c_int
    interface
        function Util_Rand() bind(c, name = "rand")
            import c_int
            integer(c_int) :: Util_Rand
        end function Util_Rand
    end interface
    function Util_RandomRange(minimum, maximum)
        integer :: Util_RandomRange
        integer :: minimum, maximum

        Util_RandomRange = mod(c_rand() + minimum, maximum)
    end function Util_RandomRange
end module Util

```

and error

```auto
src/util.f90:9:5:

    9 | function Util_RandomRange(minimum, maximum)
      | 1
Error: Unclassifiable statement at (1)

```

---

<div class="post-metadata">

**Author:** ![yeti0904](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/yeti0904/32/1886_2.png) [@yeti0904](https://fortran-lang.discourse.group/u/yeti0904)\
**Post date:** [July 6, 2022, 7:06pm UTC](https://fortran-lang.discourse.group/t/unclassifiable-statement-error-with-a-function-that-seems-fine/3939/2 "2022-07-06T19:06:02Z")

</div>

wrong function call name…  
im so stupid

---

<div class="post-metadata">

**Author:** ![yeti0904](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/yeti0904/32/1886_2.png) [@yeti0904](https://fortran-lang.discourse.group/u/yeti0904)\
**Post date:** [July 6, 2022, 7:07pm UTC](https://fortran-lang.discourse.group/t/unclassifiable-statement-error-with-a-function-that-seems-fine/3939/3 "2022-07-06T19:07:28Z")

</div>

now its this and im confused

```auto
    function Util_RandomRange(minimum, maximum)
        integer :: Util_RandomRange
        integer :: minimum, maximum
        integer :: randReturn

        randReturn = Util_Rand()
        Util_RandomRange = mod(randReturn + minimum, maximum)
    end function Util_RandomRange

```

---

<div class="post-metadata">

**Author:** ![ivanpribec](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/ivanpribec/32/3290_2.png) [@ivanpribec](https://fortran-lang.discourse.group/u/ivanpribec)\
**Post date:** [July 6, 2022, 7:37pm UTC](https://fortran-lang.discourse.group/t/unclassifiable-statement-error-with-a-function-that-seems-fine/3939/4 "2022-07-06T19:37:15Z")

</div>

You are missing a `contains` statement.

---

<div class="post-metadata">

**Author:** ![yeti0904](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/yeti0904/32/1886_2.png) [@yeti0904](https://fortran-lang.discourse.group/u/yeti0904)\
**Post date:** [July 6, 2022, 7:39pm UTC](https://fortran-lang.discourse.group/t/unclassifiable-statement-error-with-a-function-that-seems-fine/3939/5 "2022-07-06T19:39:35Z")

</div>

thanks

---

<div class="post-metadata">

**Author:** ![Beliavsky](https://avatars.discourse-cdn.com/v4/letter/b/ba8739/32.png) [@Beliavsky](https://fortran-lang.discourse.group/u/Beliavsky)\
**Post date:** [July 7, 2022, 12:05am UTC](https://fortran-lang.discourse.group/t/unclassifiable-statement-error-with-a-function-that-seems-fine/3939/6 "2022-07-07T00:05:18Z")

</div>

I have forgotten the `contains` statement many times. Since beginners may also do this, a clear message would be good. For

```auto
module m
implicit none
subroutine hello()
print*,"hi"
end subroutine hello
end module m

```

I think the error message would ideally be something like

`module procedure hello defined before contains statement`

since that clarifies what needs to be done. For the code shown,

`lfortran -c` says

```auto
syntax error: Token 'subroutine' is unexpected here
 --> contains.f90:3:1
  |
3 | subroutine hello()
  | ^^^^^^^^^^

```

`gfortran -c` says

```auto
contains.f90:3:1:

    3 | subroutine hello()
      | 1
Error: Unclassifiable statement at (1)
contains.f90:4:11:

    4 | print*,"hi"
      | 1
Error: Unexpected WRITE statement in MODULE at (1)
contains.f90:5:3:

    5 | end subroutine hello
      | 1
Error: Expecting END MODULE statement at (1)

```

`ifort -c` says

```auto
contains.f90(3): error #6218: This statement is positioned incorrectly and/or has syntax errors.
subroutine hello()
^
contains.f90(4): error #6274: This statement must not appear in the specification part of a module.
print*,"hi"
^
contains.f90(5): error #6786: This is an invalid statement; an END [MODULE] statement is required.
end subroutine hello
^
contains.f90(5): error #6785: This name does not match the unit name. [HELLO]
end subroutine hello
---------------^
contains.f90(6): error #6790: This is an invalid statement; an END [PROGRAM] statement is required.
end module m
^
contains.f90(6): error #6785: This name does not match the unit name. [M]
end module m
-----------^
compilation aborted for contains.f90 (code 1)

```
