Skip to content

Commit 632c2bd

Browse files
committed
Add support for logical arguments to .also.
This enables patterns like: ``` diag = diag .also. myobject%passes() ``` Where the latter returns a logical. The resulting expression is slightly more concise than requiring the programmer to type `.expect.`
1 parent 5744c85 commit 632c2bd

3 files changed

Lines changed: 35 additions & 3 deletions

File tree

src/julienne/julienne_test_diagnosis_m.F90

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,16 +201,32 @@ pure module function aggregate_rank15_diagnosis(diagnoses) result(diagnosis)
201201

202202
interface operator(.also.)
203203

204-
elemental module function also(lhs, rhs) result(diagnosis)
204+
elemental module function also_DD(lhs, rhs) result(diagnosis)
205205
implicit none
206206
type(test_diagnosis_t), intent(in) :: lhs, rhs
207207
type(test_diagnosis_t) diagnosis
208208
end function
209209

210+
elemental module function also_DL(lhs, rhs) result(diagnosis)
211+
implicit none
212+
type(test_diagnosis_t), intent(in) :: lhs
213+
logical, intent(in) :: rhs
214+
type(test_diagnosis_t) diagnosis
215+
end function
216+
217+
elemental module function also_LD(lhs, rhs) result(diagnosis)
218+
implicit none
219+
logical, intent(in) :: lhs
220+
type(test_diagnosis_t), intent(in) :: rhs
221+
type(test_diagnosis_t) diagnosis
222+
end function
223+
210224
end interface
211225

212226
interface operator(.and.)
213-
module procedure also
227+
module procedure also_DD
228+
module procedure also_LD
229+
module procedure also_DL
214230
end interface
215231

216232
interface operator(.approximates.)

src/julienne/julienne_test_diagnosis_s.F90

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,18 @@
3737
end if
3838
end procedure
3939

40-
module procedure also
40+
module procedure also_DD
4141
diagnosis = .all. ([lhs,rhs])
4242
end procedure
4343

44+
module procedure also_LD
45+
diagnosis = .all. ([.expect.(lhs),rhs])
46+
end procedure
47+
48+
module procedure also_DL
49+
diagnosis = .all. ([lhs,.expect.(rhs)])
50+
end procedure
51+
4452
#ifndef __GFORTRAN__
4553

4654
module procedure aggregate_diagnosis

test/modules/test_diagnosis_test_m.F90

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ function results() result(test_results)
8686
,test_description_t("construction from (.expects. logical-expression) // 'user-defined message'" , usher(check_expects_logical)) &
8787
,test_description_t("construction from (.expects. logical-expression) // 'user-defined message'" , usher(check_expects_logical)) &
8888
,test_description_t("defining a test_diagnosis_t object by assigning a logical value" , usher(check_assigns_logical)) &
89+
,test_description_t("aggregating a test_diagnosis_t object using .also. with a logical value" , usher(check_also_logical)) &
8990
,test_description_t("hardwiring a test to pass via the passing_test() function" , usher(check_passing_test_function)) &
9091
]
9192
test_results = test_diagnosis_test%run(test_descriptions)
@@ -310,6 +311,13 @@ function check_assigns_logical() result(test_diagnosis)
310311
test_diagnosis = .true.
311312
end function
312313

314+
function check_also_logical() result(test_diagnosis)
315+
type(test_diagnosis_t) test_diagnosis
316+
test_diagnosis = .true.
317+
test_diagnosis = test_diagnosis .also. .true.
318+
test_diagnosis = .true. .also. test_diagnosis
319+
end function
320+
313321
function check_passing_test_function() result(test_diagnosis)
314322
type(test_diagnosis_t) test_diagnosis
315323
test_diagnosis = passing_test()

0 commit comments

Comments
 (0)