Skip to content

Anonymous objects from nothing #812

Closed
@lkuper

Description

@lkuper

Is there a reason why we'd want to be able to create an anonymous object from nothing, rather than extending an existing one?

For example, should we support being able to do this:

fn main() {

    // Anonymous object that doesn't extend an existing one.
    let my_obj = obj () {
        fn foo() -> int { ret 2; }
        fn bar() -> int { ret self.foo(); }
    };

    assert (my_obj.foo() == 2);
    assert (my_obj.bar() == 2);

}

If the answer is yes, then we need to finish implementing support for it. Right now, the parser and translator don't require an anon obj to have a "with" clause, and if there isn't one, translating an anon obj proceeds much like translating a regular obj would, with no forwarding/backwarding vtable slots created. But the above program fails in typechecking because the typechecker doesn't know what "self" is.

If the answer is no, we don't care about having this feature, we should get rid of what support does exist. Doing so would streamline the implementation of the object system a little.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions