-
Notifications
You must be signed in to change notification settings - Fork 12
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
Discriminated record formation is broken #289
Conversation
The second commit proposes a quick fix. |
edf4c2e
to
2642281
Compare
There was a problem hiding this 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.
gnat2goto/driver/tree_walk.adb
Outdated
I_Type => | ||
Do_Type_Reference (Etype (Iter)), | ||
Range_Check => False, | ||
Value => "0"); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 := |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.)
There was a problem hiding this 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); |
There was a problem hiding this comment.
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!
The changes look sensible and should be satisfactory when the comments left by other reviewers are addressed. |
2642281
to
fa24182
Compare
by giving the struct. component the right name and by forcing the initialisation of the constraints.
fa24182
to
61f2883
Compare
the test is now marked as failing.