llvm/flang/test/semantics/resolve09.f90
Tim Keith 9811353abf [flang] Fix problems determining object/function/subroutine
Convert each Entity to ObjectEntity at the end of each scope.
Add `ConvertToObjectEntity()` to achieve this, similar to
`ConvertToProcEntity()`. Move them both up into `ScopeHandler`
because they need to be called from `PopScope()`.

In a proc-decl, only mark the proc as a function if it has a return type.
If no return type is declared, function vs. subroutine is determined by:
- for a module it is a subroutine (at end of specification-part)
- otherwise it is by usage

If an entity that could otherwise be a function is used as the base of a
structure component, that forces it to be an object. Because we have to
change it to an object entity at that point, the `base` in `FindComponent()`
can't be const, and that propagates to all of its callers.

Remove the name argument to `ApplyImplicitRules` as it is unneeded.

Fixes flang-compiler/f18#191.

Original-commit: flang-compiler/f18@9bd8bf7c37
Reviewed-on: https://github.com/flang-compiler/f18/pull/194
Tree-same-pre-rewrite: false
2018-09-22 08:05:46 -07:00

78 lines
1.9 KiB
Fortran

! Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
!
! Licensed under the Apache License, Version 2.0 (the "License");
! you may not use this file except in compliance with the License.
! You may obtain a copy of the License at
!
! http://www.apache.org/licenses/LICENSE-2.0
!
! Unless required by applicable law or agreed to in writing, software
! distributed under the License is distributed on an "AS IS" BASIS,
! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
! See the License for the specific language governing permissions and
! limitations under the License.
integer :: y
procedure() :: a
procedure(real) :: b
call a ! OK - can be function or subroutine
!ERROR: Cannot call subroutine 'a' like a function
c = a()
!ERROR: Cannot call function 'b' like a subroutine
call b
!ERROR: Cannot call function 'y' like a subroutine
call y
call x
!ERROR: Cannot call subroutine 'x' like a function
z = x()
end
subroutine s
!ERROR: Cannot call function 'f' like a subroutine
call f
!ERROR: Cannot call subroutine 's' like a function
i = s()
contains
function f()
end
end
subroutine s2
! subroutine vs. function is determined by use
external :: a, b
call a()
!ERROR: Cannot call subroutine 'a' like a function
x = a()
x = b()
!ERROR: Cannot call function 'b' like a subroutine
call b()
end
subroutine s3
! subroutine vs. function is determined by use, even in internal subprograms
external :: a
procedure() :: b
contains
subroutine s3a()
x = a()
call b()
end
subroutine s3b()
!ERROR: Cannot call function 'a' like a subroutine
call a()
!ERROR: Cannot call subroutine 'b' like a function
x = b()
end
end
module m
! subroutine vs. function is determined at end of specification part
external :: a
procedure() :: b
contains
subroutine s()
call a()
!ERROR: Cannot call subroutine 'b' like a function
x = b()
end
end