Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid code generation for global enum with Always_Valid => True #1123

Open
jklmnn opened this issue Jul 27, 2022 · 0 comments
Open

Invalid code generation for global enum with Always_Valid => True #1123

jklmnn opened this issue Jul 27, 2022 · 0 comments
Labels
bug generator Related to generator package (SPARK code generation)

Comments

@jklmnn
Copy link
Member

jklmnn commented Jul 27, 2022

The code generation for enumeration types with the aspect Always_Valid => True generates invalid code if an object of such a type is used in the global context.

If the following patch is applied:

diff --git a/tests/integration/session_comprehension_on_sequence/test.rflx b/tests/integration/session_comprehension_on_sequence/test.rflx
index 7fe8739c..4cfc60d3 100644
--- a/tests/integration/session_comprehension_on_sequence/test.rflx
+++ b/tests/integration/session_comprehension_on_sequence/test.rflx
@@ -11,6 +11,7 @@ package Test is
       Options : Universal::Options; -- §S-D-V-T-MS, §S-D-V-E-N
       Message_1 : Universal::Message; -- §S-S-D-V-T-M, §S-S-D-V-E-N
       Message_2 : Universal::Message; -- §S-S-D-V-T-M, §S-S-D-V-E-N
+      First_Option_Type : Universal::Option_Type;
    begin
       state Start is
       begin
@@ -30,6 +31,7 @@ package Test is
          Option_Types : Universal::Option_Types; -- §S-S-D-V-T-SS, <C2><A7>S-S-D-V-E-N
          Message_Options : Universal::Options; -- §S-S-D-V-T-MS, <C2><A7>S-S-D-V-E-N
       begin
+         First_Option_Type := Universal::OT_Data;
          -- §S-S-A-A-LC, §S-E-LC-V, §S-E-LC-SMS, §S-E-LC-TSS, §S-E-LC-CS, §S-E-LC-A, §S-E-S-V
          Option_Types := [for E in Options if E.Option_Type = Universal::OT_Data => E.Option_Type];
          -- Test that target sequence is reset by assignment

This will make the following test fail:

python -m pytest 'tests/integration/feature_test.py::test_compilability[session_comprehension_on_sequence]' -vv

The reason is that the default initializer is generated the same way as for regular enums

First_Option_Type : Universal.Option_Type := Universal.Option_Type'First;

but the Ada type definition is a variant record. In this case no default initializer should be generated.

@jklmnn jklmnn added bug generator Related to generator package (SPARK code generation) labels Jul 27, 2022
@jklmnn jklmnn added this to To do in RecordFlux 0.6 via automation Jul 27, 2022
@senier senier removed this from To do in RecordFlux 0.6 Aug 23, 2022
@senier senier added this to To do in RecordFlux Future via automation Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug generator Related to generator package (SPARK code generation)
Projects
No open projects
Development

No branches or pull requests

1 participant