Allow storing abstract object references in members · Issue #82 · SFTtech/nyan · GitHub
Skip to content

Allow storing abstract object references in members #82

Open

Description

@heinezen

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

Activity

  1. added
    specificationinvolves the nyan language specification
    proposalpending discussion about something to do
    on Oct 3, 2020
  2. linked a pull request that will close this issueAdapt nyan to new specification #84on Oct 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalpending discussion about something to dospecificationinvolves the nyan language specification

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions