Skip to content

Keep typealias and disallow attributes on "nested" types #715

@bernardnormier

Description

@bernardnormier

Currently, slicec substitutes typealias where they are used. So if you write:

typealias StringSet = [cs::type("HashSet<string>")] Sequence<string>

interface Example {
    op(v : Sequence<StringSet>
}

For the code generator, these definitions are identical to:

interface Example {
    op(v : Sequence<[cs::type("HashSet<string>")] Sequence<string>>
}

(which is an allowed syntax)

Proposal

Remove this eager substitution of typealias, and disallow attributes on nested types when defining anonymous types. In other words:

interface Example {
    op(v : Sequence<[cs::type("HashSet<string>")] Sequence<string>> // syntax error with my proposal
}

In order to achieve the desired result, you have to use a typealias, as in:

typealias StringSet = [cs::type("HashSet<string>")] Sequence<string>

interface Example {
    op(v : Sequence<StringSet>
}

This limits where attributes are valid to:

  • named type (such as struct)
  • other named constructs (such as interface and typealias)
  • type references in fields and parameters (FieldTypeRef?)

With this proposal, the normalized name of an anonymous type becomes a unique, unambiguous ID. For example: Sequence<Sequence<Dictionary<string, MyModule::HashSet>>> always designates the same attribute-free anonymous type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalslice languageRelated to the Slice language itselfslicecRelated to the 'slicec' crate

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions