Lyricdev
GitHub

LYR-SEM0067

an attribute on a generic declaration

error ยท spec 11-metaprogramming

An attribute other than a compiler instruction sits on a generic function or type.

Explanation

An attribute's value is one value for the declaration, and a generic declaration stands for as many instances as the program creates; a test or benchmark marked on one could not be instantiated by the runner. Compiler instructions such as @Deprecated or @NoInline say the same of every instance and are allowed.

Put the attribute on a non-generic declaration, for example a wrapper that calls the generic one with concrete types.

Wrong

import std.core { OnFunction };

struct Label :: [OnFunction] {
    text: string,
}

@Label { text = "first" }
fn first<T>(xs: T[]): T {
    return xs[0];
}

fn main(): void {
    let _ = first([1, 2]);
}
import std.core { OnFunction };

struct Label :: [OnFunction] {
    text: string,
}

@Label { text = "first" }
fn first(xs: int[]): int {
    return xs[0];
}

fn main(): void {
    let _ = first([1, 2]);
}