@@ -14,9 +14,10 @@ module m_result
1414 ! !
1515 ! ! Holds either the result or an error.
1616
17- class(* ), allocatable :: data_v(..)
18- ! ! Data i.e. the result (if no error occurs)
19- ! !
17+ ! class(*), allocatable :: data_v(..)
18+ ! MZ: assumed rank can only be dummy argument NOT type/class argument
19+ ! Data i.e. the result (if no error occurs)
20+ !
2021 ! Assumed rank array
2122 ! (https://fortran-lang.discourse.group/t/assumed-rank-arrays/1049)
2223 ! Technically a Fortran 2018 feature,
@@ -36,7 +37,8 @@ module m_result
3637 ! procedure, public:: build
3738 ! TODO: Think about whether build should be on the abstract class
3839 ! or just on each concrete implementation
39- procedure , public :: finalise, is_error
40+ procedure , public :: is_error
41+ final, public :: finalise
4042
4143 end type Result
4244
@@ -47,79 +49,15 @@ module m_result
4749
4850contains
4951
50- ! See above about whether we include this here or not
51- ! Build should return a Result with an error if we try to set/allocate both
52- ! data and error
53- ! subroutine build(self, code, message)
54- ! !! Build instance
55- !
56- ! class(ErrorV), intent(inout) :: self
57- ! ! Hopefully can leave without docstring (like Python)
58- !
59- ! integer, intent(in) :: code
60- ! !! Error code
61- ! !!
62- ! !! Use [TODO: figure out xref] `NO_ERROR_CODE` if there is no error
63- !
64- ! character(len=*), optional, intent(in) :: message
65- ! !! Error message
66- !
67- ! self % code = code
68- ! if (present(message)) then
69- ! self % message = message
70- ! end if
71- !
72- ! end subroutine build
73-
74- ! subroutine constructor(self, code, message)
75- ! !! Build instance
76- !
77- ! class(*), allocatable :: data_v(..)
78- ! class(ErrorV), intent(inout) :: self
79- ! ! Hopefully can leave without docstring (like Python)
80- ! integer, intent(in) :: code = NO_ERROR_CODE
81- ! !! Error code
82- ! !!
83- ! !! Use [TODO: figure out xref] `NO_ERROR_CODE` if there is no error
84- ! character(len=*), optional, intent(in) :: message = ""
85- ! !! Error message
86- !
87- ! self % code = code
88- ! if (present(message)) then
89- ! self % message = message
90- ! end if
91- !
92- ! end subroutine constructor
93-
94- function finalise (self ) result(res)
52+ subroutine finalise (self )
9553 ! ! Finalise the instance (i.e. free/deallocate)
9654
9755 class(Result), intent (inout ) :: self
9856 ! Hopefully can leave without docstring (like Python)
9957
100- ! type(ResultNone) :: res
58+ if ( allocated (self % error_v)) deallocate (self % error_v)
10159
102- res = Result()
103-
104- if (allocated (self % data_v) .and. allocated (self % error_v)) then
105- deallocate (self % data_v)
106- deallocate (self % error_v)
107- call res % build(message= " Both data and error were allocated" )
108-
109- elseif (allocated (self % data_v)) then
110- deallocate (self % data_v)
111- ! No error - no need to call res % build
112-
113- elseif (allocated (self % error_v)) then
114- deallocate (self % error_v)
115- ! No error - no need to call res % build
116-
117- else
118- call res % build(message= " Neither data nor error was allocated" )
119-
120- end if
121-
122- end function finalise
60+ end subroutine finalise
12361
12462 pure function is_error (self ) result(is_err)
12563 ! ! Determine whether `self` contains an error or not
0 commit comments