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

Support Inheritance #310

Open
jwhpryor opened this issue Jul 3, 2024 · 1 comment
Open

Support Inheritance #310

jwhpryor opened this issue Jul 3, 2024 · 1 comment
Assignees
Milestone

Comments

@jwhpryor
Copy link
Collaborator

jwhpryor commented Jul 3, 2024

Currently, class definitions must re-declare all of their parent classes interface if they want to be used, which is repetitive.

Also, subclasses must static_cast themselves to jobjects to be used in a context their subclass is required which loses type safety.

enum classes are basically syntactic sugar for a subclassing, so this likely needs to be implemented first.

It will be nice to unify the type system to enable interface of Object throughout Java. That said, Kotlin's Any is not Java's Object, so any solution should not presume this.

@jwhpryor
Copy link
Collaborator Author

I dug into this a bit, and I think this may unfortunately be blocked by #4.

To expose a syntax where an object can invoke a parent's function, there needs to be a mechanism to discover the method using a char*.

Currently, the full set is known, so in ObjectRef it's possible to simply use the InvocableMap.

At first I thought I could simply daisy chain inheritance of ObjectRef types but this isn't viable. First, if the operator() is selected, but all candidates discarded (e.g. if a parent class function call is made on a subclass), the child most class will be selected, and only its InvocableMap will offer candidates (not parents).

I considered trying to build a map of candidates for each layer of inheritance, but this is difficult to do and maintain costexpr-ness. I think if a class was constructed in such a way as to expose a Walk metafunction that moves from child to parent class, it might be possible to compile time construct a map of candidate names, and then expose this directly to InvocableMap.

This problem may be easier to solve after migrating to C++20, so I may take a detour to do so. Much of the C++17 implementation exploits tricks in the type system to workaround not having string literals (i.e. non type templates).

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

No branches or pull requests

1 participant