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

Allow storing abstract object references in members #82

Open
heinezen opened this issue Oct 3, 2020 · 0 comments
Open

Allow storing abstract object references in members #82

heinezen opened this issue Oct 3, 2020 · 0 comments
Labels
proposal pending discussion about something to do specification involves the nyan language specification

Comments

@heinezen
Copy link
Member

heinezen commented Oct 3, 2020

nyan object members and sets with nyan object set types only allow non-abstract objects by default. This limitation is meant to ensure that when retrieving the object, all members are guaranteed to have values assigned. Costly checking for an uninitialized member is not necessary then.

However, it sometimes makes sense to still reference abstract objects, e.g. when the object reference is used for a type check where the member values are not needed. For this case we can use a type modifier abstract(type). For containers, this feature can be used in combination with the hierarchy_overwrite feature (see #37) to add and replace objects in an inheritance hierarchy.

# Abstract object
OtherObject():
    member : float

# Non-abstract child
ChildObject(OtherObject):
    member = 5.0f

SomeObject():
    # Default: Allows only non-abstract objects
    member_set : set(OtherObject) = {ChildObject}
    # With abstract modifier: Allows both non-abstract and abstract objects
    member_set_abs : set(abstract(OtherObject)) = {OtherObject, ChildObject}

    # also possible: non-container member with an abstract value
    member_abs : abstract(OtherObject) = OtherObject

# This object is still abstract!
StillAbstract():
    member_abs : abstract(OtherObject)

NoLongerAbstract(StillAbstract):
    member_abs = OtherObject
@heinezen heinezen added specification involves the nyan language specification proposal pending discussion about something to do labels Oct 3, 2020
@heinezen heinezen linked a pull request Oct 5, 2020 that will close this issue
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal pending discussion about something to do specification involves the nyan language specification
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant