Skip to content

Commit

Permalink
Merge pull request #8 from Goddard-Fortran-Ecosystem/hotfix/value-of-…
Browse files Browse the repository at this point in the history
…iterator-of-empty-container

Fix for bug with empty containers.
  • Loading branch information
tclune authored May 29, 2018
2 parents 2cdd553 + ac8f397 commit d75cc7f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
6 changes: 5 additions & 1 deletion include/templates/altSet_impl.inc
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,11 @@
class(__iterator), target, intent(in) :: this
__type_declare_result, pointer :: value

value=>this%reference%items%at(this%current)
if (this%current == UNINITIALIZED) then
value => null()
else
value=>this%reference%items%at(this%current)
end if

end function __PROC(value)

Expand Down
6 changes: 5 additions & 1 deletion include/templates/map_impl.inc
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,11 @@
type(__pair), pointer :: p

p => this%setIter%value()
res => p%value
if (associated(p)) then
res => p%value
else
res => null()
end if

end function __PROC(value)

Expand Down
6 changes: 5 additions & 1 deletion include/templates/set_impl.inc
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,11 @@
class(__iterator), intent(in) :: this
__type_declare_result, pointer :: value

value=>this%node%value
if (associated(this%node)) then
value =>this%node%value
else
value => null()
end if

end function __PROC(value)

Expand Down
10 changes: 10 additions & 0 deletions tests/Map/Test_Map.m4
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,16 @@ contains

end subroutine test_at

@test
subroutine test_value_empty_is_null()
type (Map), target :: m
type (MapIterator) :: iter

iter = m%find(KEY1)
@assertFalse(associated(iter%value()))

end subroutine test_value_empty_is_null

@test
subroutine test_find()
type (Map), target :: m
Expand Down

0 comments on commit d75cc7f

Please sign in to comment.