cortoproject / corto

A hierarchical object store for connecting realtime machine data with web applications, historians & more
https://www.corto.io
MIT License
86 stars 14 forks source link

Aliasing a member from a non-hidden base class does not fail until code generation #682

Closed SanderMertens closed 6 years ago

SanderMertens commented 6 years ago

Aliasing a member from a base class can be useful when the base class is hidden. This allows models to selectively make members available to a subclass initializer, instead of having to specify all members in an initializer. For example:

struct s_base {
    a, b: int32
}

struct s_sub: s_base, hidden {
    alias b: s_base/b
    c: int32
}

s_sub obj: 10, 20 // equivalent to: s_sub obj: super.b:10, c: 20

Currently no error is thrown when aliasing a member from a base class that is not hidden, which means the member would show up twice in an initializer, which does not make sense. For example:

struct s_base {
    a, b: int32
}

struct s_sub: s_base { // s_base is not hidden
    alias b: s_base/b
    c: int32
}

s_sub obj: 10, 20, 30, 40 // equivalent to: s_sub obj: super.a:10, super.b: 20, super.b: 30, c: 40

Currently the corto runtime does not throw an error when attempting this, but the code generators fail because functions are generated with duplicate argument names. That is too late; this error should be thrown in the runtime.