-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
function-stmt in interface bodies may have a declaration-type-spec in their prefix that contains a use/host-associated variable #1565
Comments
Looking at the code, there is a method called module moo
implicit none
integer, parameter :: my_kind = 4
end module moo
real(kind = my_kind) function square(x)
use moo
implicit none !! (A)
real(kind = my_kind) :: x
real(kind = kind(square)) :: y !! Here we need to know the kind of square
square = x * x
end function square Deferring this case like derived types (at the end of the specification part) would be too late for the |
Hi @rofirrim , thanks for the bug report. Lowering does not claim F2003 support, but semantics should be able to deal with up to F2018, so that is definitely a bug. @klausler is working on a similar issue (deferring intrinsic function type resolution, this is actually required to handle things like |
Just in case this is useful for @klausler, delaying the evaluation of a derived type at the end of the specification part might fail in this case. type(my_type(kind(x))) function foo(x)
implicit none
real :: x
type my_type(k)
integer, kind :: k = kind(0.0)
integer(kind = k) :: x
end type !! Finishing the function type for derived types might have to happen here?
integer(kind = foo % k) :: y
end function foo Not 100% sure if this is valid as some commercial compilers are struggling with this case already. Also the use of |
Hi,
Sorry for the confusing name of the issue, I tried to be a bit precise, so I hope the testcase below is clearer.
This is rejected by flang:
I am aware this is a Fortran 2003 feature.
A similar problem happens with use-association.
I admit I'm not 100% sure about the validity of this (but all compilers I could test on https://fortran.godbolt.org were OK with this code).
My reading of the spec is such that this should be accepted.
According to my draft of Fortran 2018, the constraints associated to the
type-param-value
of adeclaration-type-spec
(such like the one appearing in theprefix
of afunction-stmt
) (R703) forces them to bespecification-expr
.(I understand here "previous" binds to the "declaration in the same scoping" and not the following cases: implicit, host, use).
As a workaround, the code can be rewritten to use a
result(r)
and then declareinteger(my_kind) :: r
, like belowThe text was updated successfully, but these errors were encountered: