-
Notifications
You must be signed in to change notification settings - Fork 1.1k
CHASM: ComponentPointer support #7774
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
CHASM: ComponentPointer support #7774
Conversation
a0704ae
to
685e4f3
Compare
685e4f3
to
8b2525a
Compare
switch internal.value().(type) { | ||
case []string: // Pointer | ||
default: // Component | Data | ||
if err = assertStructPointer(reflect.TypeOf(internal.value())); err != nil { |
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 think it is the case based on my reading of the code but want to double check: If Component or Data field type, it (T
) needs to be pointer to a struct. For Pointer field type, T
can be an interface.
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 is a value of pointer itself. And it must be of []string
type. It is set internally, so it is always must be the case.
For other call of the assertStructPointer
, it asserts on actual type of the value which is passed to deserialize
method, which is always concrete type, even if the field is defined using interface. You can check TestFieldInterface
.
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.
ok I see. The type the T
in Field[T]
can always be an interface. But when creating a new Field, it needs to be a concrete type (i.e. pointer to struct) when creating the field ().
Then I guess what I want to confirm is: do Component|DataPointerTo()
have the same requirement? Looks like the answer is yes because the Ref() impl only check = node.value
and node value is always concrete type.
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, the answer is "yes" :-).
In
func ComponentPointerTo[C Component](
ctx MutableContext,
c C,
) (Field[C], error) {
C
can be and interface, but c
will be always an instance of a concrete type which should match the type of what it points to. If they are mismatch, it can be hard to debug, I guess.
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.
Got it. Thanks for confirming.
I guess usually the component using Pointer won't actually care or know the concrete type of the component being pointed to. So the use case I have in mind is the component's constructor will just accept an interface and then create a pointer to the passed in interface value, which means c
is an interface.
It's easy to support that I think, just need to check for the try to match the underlying value in Ref().
What changed?
CHASM: Add basic
ComponentPointer
support to CHASM component.Why?
Part of CHASM workstream. Few things are still pending:
RefC
andRefD
should return error.RefC
andRefD
needs to be revisited. It is not clear if it is possible to implement w/o deserializing entire component starting from root and all the way down, becausen.value
is needed to compare with passed argument.How did you test it?