* types: validate @[attribute] schema declarations (custom attributes, rfcs#35) First slice of the RFC-recommended Option A (typed schema structs): a struct marked with @[attribute] declares an attribute schema. This covers declaration-side validation only: the marker is rejected on non-struct declarations, schema structs reject mut fields and embeds, and schemas cannot be initialized, embedded, or used as generic type arguments. Use-site argument checking and typed comptime reflection follow in later slices; unregistered attribute names stay silent for now. Adds 6 checker error tests and 1 positive compile test. * types: validate custom attribute uses against schemas (rfcs#35) Second slice of Option A: a schema registry (short name, fields, targets) is collected per compilation, and every attribute use matching a schema V-strict is validated on declarations, fields, and enum values: target restrictions, positional counts, field names/duplicates/missing, and string/integer/bool/enum argument types, including reassembly of the parser's dot-enum split (\method: .get\). Unregistered names stay silent. Adds 12 checker error tests and extends the positive compile test. * parser, types: support module-qualified custom attribute names (rfcs#35) Third slice of Option A, adding the dotted name form the RFC calls the real gap. \@[mod.Name]\ and \@[mod.Name(args)]\ now parse as one attribute instead of splitting on the dot into \mod\ plus \Name\, which previously made cross-module uses unusable (two uses of the same schema collided as duplicate \mod\). Schema resolution is registry-driven and module-aware: a bare name sees the current module, \mod.Name\ sees that module, and a local schema shadows an imported homonym. A module-qualified attribute now also counts as a use of its import, so cross-module uses no longer warn as unused. Fixes error positions to use the node's own attribute window (fields and enum values took the nearest match, which could point at a neighbouring field's attribute). Adds 1 parser test, 2 module fixtures, and a vfmt round-trip test. * attributes: preserve named enum values and reject repeated named fields --------- Co-authored-by: Alexander Medvednikov <alexander@medvednikov.com>
374 B
374 B
Attribute arguments
Typed attributes accept positional and named arguments. Each schema field must be supplied once; repeating a named field or supplying it both positionally and by name is an error.
Enum values use a leading dot. A call such as @[Route(method: .get)] can begin with a named
enum argument, including when the schema is qualified with its module name.