Fortran: Fix scalar class to derived select type entities
Fixed an issue in Fortran's handling of scalar class to derived type assignment in select type constructs.
A bug was fixed in the Fortran compiler related to assignment expressions within select type constructs. The compiler was not correctly passing scalar class information to derived type assignment expressions, leading to incorrect code generation. This has now been corrected by ensuring that gfc_trans_scalar_assign receives the appropriate scalar class information. A new test case was added to verify the fix.
In Details
This commit addresses PR125263 by modifying gfc_trans_assignment_1 in trans-expr.cc to correctly pass scalar class information to gfc_trans_scalar_assign when dealing with derived type assignment expressions within select type constructs. This fix ensures proper code generation for such scenarios. The issue lies in the translation of Fortran's type-bound procedures and polymorphic variables, requiring careful handling of the scalar class during assignment.
For Context
Fortran allows you to create custom data types called derived types, similar to classes in other languages. The select type construct allows you to handle different derived types based on the actual type of a variable. This commit fixes an issue where the compiler was mishandling assignment operations when working with scalar (single-value) variables of a derived type within a select type block. The fix ensures that the compiler correctly understands the type of the variable being assigned, which leads to correct code being generated by the compiler.