@@ -271,26 +271,58 @@ def test_apply_inquiry(fortran_reader, fortran_writer):
271271 " end if\n " ) in output
272272
273273
274- def test_validate_structure (fortran_reader ):
275- '''Test that a StructureReference raises an exception. This limitation
276- will be removed once issue #1858 is addressed.
277-
274+ def test_validate_structure_references (fortran_reader ):
275+ ''' Test that the transformation can be applied to StructureReferences.
276+ TODO #1858: this still has several limitations.
278277 '''
279278 code = (
280279 "program test\n "
281280 " type :: array_type\n "
282- " real, dimension(10) :: a\n "
281+ " real :: scalar\n "
282+ " real, dimension(10) :: field\n "
283283 " real, pointer :: ptr\n "
284284 " end type\n "
285285 " type(array_type) :: ref\n "
286+ " type(array_type), dimension(10) :: array_of_ref\n "
286287 " real :: b\n \n "
287- " ref%a = b\n "
288+ " ! These pass the transformation unmodified\n "
289+ " ref%scalar = 1\n "
290+ " array_of_ref(:)%scalar = 1\n "
291+ " ref%field(:) = 1\n "
292+ " array_of_ref(:)%field(:) = 1\n "
293+ " ! These need range expressions added\n "
294+ " array_of_ref%scalar = 1\n "
295+ " array_of_ref%field = 1\n "
296+ " ref%field = 1\n "
297+ " ! This is not supported\n "
288298 " ref%ptr => b\n "
289- "end program test\n " )
299+ "end program test\n "
300+ )
290301 psyir = fortran_reader .psyir_from_source (code )
291302 trans = Reference2ArrayRangeTrans ()
292- for assign in psyir .walk (Assignment ):
293- trans .validate (assign .lhs )
303+ assign = psyir .walk (Assignment )
304+
305+ # The 4 first statements are fine
306+ trans .apply (assign [0 ].lhs )
307+ trans .apply (assign [1 ].lhs )
308+ trans .apply (assign [2 ].lhs )
309+ trans .apply (assign [3 ].lhs )
310+
311+ # TODO #1858: Add support for StructureReference
312+ with pytest .raises (TransformationError ) as err :
313+ trans .apply (assign [4 ].lhs )
314+ assert ("Reference2ArrayRangeTrans does not yet support Structure"
315+ "References but found 'array_of_ref: DataSymbol<Array<"
316+ in str (err .value ))
317+ with pytest .raises (TransformationError ) as err :
318+ trans .apply (assign [5 ].lhs )
319+ assert ("Reference2ArrayRangeTrans does not yet support Structure"
320+ "References but found 'array_of_ref: DataSymbol<Array<"
321+ in str (err .value ))
322+
323+ # TODO #1858: Extend validations to Structure members
324+ trans .apply (assign [6 ].lhs )
325+ trans .apply (assign [7 ].lhs )
294326
295327
296328def test_validate_pointer_assignment (fortran_reader ):
@@ -310,15 +342,3 @@ def test_validate_pointer_assignment(fortran_reader):
310342 trans .validate (reference )
311343 assert ("The supplied node should be a Reference to a symbol of known "
312344 "type, but " in str (info .value ))
313-
314-
315- def test_apply_validate ():
316- '''Test that the apply method calls validate by checking that the
317- exception raised by validate is raised when apply is called.
318-
319- '''
320- trans = Reference2ArrayRangeTrans ()
321- with pytest .raises (TransformationError ) as info :
322- trans .apply (None )
323- assert ("The supplied node should be a Reference but found 'NoneType'."
324- in str (info .value ))
0 commit comments