Skip to content
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

class(*), allocatable stole my sequence type #347

Open
ivan-pi opened this issue Feb 25, 2025 · 1 comment
Open

class(*), allocatable stole my sequence type #347

ivan-pi opened this issue Feb 25, 2025 · 1 comment

Comments

@ivan-pi
Copy link

ivan-pi commented Feb 25, 2025

Given a sequence type stored in an unlimited polymorphic variable, the compiler doesn't approve of even a single method to access the data:

! seq_type.f90

type :: seq_type
   sequence
   real :: val
end type

class(*), allocatable :: a

a = seq_type(val=3.0)

select type(a)
type is (seq_type)
    print *, a%val
end select

block
    type(seq_type) :: b
    call move_alloc(from=a,to=b)
    print *, b%val
end block

block
    type(seq_type) :: b
    b = transfer(a, b)
    print *, b%val
end block

end
~> nagfor sequence_upv.f90 
NAG Fortran Compiler Release 7.2(Shin-Urayasu) Build 7203
Error: sequence_upv.f90, line 14: TYPE IS specifies SEQUENCE type SEQ_TYPE
Error: sequence_upv.f90, line 20: Expected an ALLOCATABLE variable for argument TO (no. 2) of intrinsic MOVE_ALLOC
Warning: sequence_upv.f90, line 26: Intrinsic TRANSFER from polymorphic data object might have partially undefined result
[NAG Fortran Compiler error termination, 2 errors, 1 warning]

This is a corner case of the discussions in,

@ivan-pi
Copy link
Author

ivan-pi commented Feb 25, 2025

Unfortunately the solution proposed in #345 would not deal with sequence types.

select type can't be used due to (J3/24-007):

C1166 (R1156) The type-spec or derived-type-spec shall not specify a derived type with the BIND attribute or the SEQUENCE attribute.

I believe the only legal solution at the moment is using a pointer to a target:

class(*), allocatable, target :: a
allocate(a,source=seq_type(val=3.0))
block
    type(seq_type), pointer :: b => null()
    b => a
    print *, b%val
end block

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant