Skip to content

Discriminated record formation is broken #289

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

Merged
merged 1 commit into from
Nov 26, 2019

Conversation

xbauch
Copy link
Contributor

@xbauch xbauch commented Sep 23, 2019

the test is now marked as failing.

@xbauch
Copy link
Contributor Author

xbauch commented Sep 23, 2019

The second commit proposes a quick fix.

@xbauch xbauch force-pushed the remove/test-discriminant-record branch from edf4c2e to 2642281 Compare September 23, 2019 13:21
Copy link
Contributor

@NlightNFotis NlightNFotis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

I_Type =>
Do_Type_Reference (Etype (Iter)),
Range_Check => False,
Value => "0");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a dummy value? Shouldn't this be an unsupported feature report or an exception, something of the sort then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Or better yet, we should find out how to properly initialise the struct-member so that we don't end up calling Discriminant_Default_Value on a node that doesn't have one.

@@ -4083,12 +4095,15 @@ package body Tree_Walk is
function Do_Selected_Component (N : Node_Id) return Irep is
Root : constant Irep := Do_Expression (Prefix (N));
Component : constant Entity_Id := Entity (Selector_Name (N));
Orig_Component : constant Entity_Id :=

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a short explanation for what an original record component is and why we need it here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struct Foo { int a; };
struct Foo bar;
bar.a = 5;

So the Unique_Name of the struct-component in declaration is Foo__a. But when parsing the assignment the component is that of the entity bar, thus it's unique-name is bar__a: which is not present in Foo. That's why we have to use the component of the original-record to get the right name. (I'll add this as a comment.)

Copy link
Collaborator

@martin-cs martin-cs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty sure that this is an improvement but it's not clear to me exactly why this fixes things and whether it is a complete fix. @tjj2017 do you have thoughts on this?

@@ -15,4 +15,6 @@ procedure Discriminated_Record is
begin
Inst1.A (5) := 1;
Inst1.B (10) := 2;

pragma Assert (Inst1.A (5) = 1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This I very much approve of. If you update B and then check the same assertion again it would be even better!

@tjj2017
Copy link
Collaborator

tjj2017 commented Oct 15, 2019

The changes look sensible and should be satisfactory when the comments left by other reviewers are addressed.

@xbauch xbauch force-pushed the remove/test-discriminant-record branch from 2642281 to fa24182 Compare November 26, 2019 11:31
by giving the struct. component the right name and by forcing the initialisation
of the constraints.
@xbauch xbauch force-pushed the remove/test-discriminant-record branch from fa24182 to 61f2883 Compare November 26, 2019 11:37
@xbauch xbauch merged commit e7883c2 into diffblue:master Nov 26, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants