Skip to content

Conversation

@wrongnull
Copy link
Contributor

Currently there is nothing indicates that those functions should be called with explicit comptime. This can lead to strange error messages in user code such as following:

const std = @import("std");

const MyUnion = union(enum) {
    field1: u32,
    field2: [] const u8,
};


fn constructMyUnion(comptime arg: anytype) MyUnion {
    if (std.meta.trait.isIntegral(@TypeOf(arg))) {
        return .{ .field1 = arg };
    }
    return .{ .field2 = arg };
}

pub fn main() void {
    _ = constructMyUnion(1);
}
error: expected type '[]const u8', found 'comptime_int'

pub const TraitFn = fn (type) callconv(.Inline) bool;

pub fn multiTrait(comptime traits: anytype) TraitFn {
pub inline fn multiTrait(comptime traits: anytype) TraitFn {
Copy link
Member

@mlugg mlugg Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functions returning TraitFn need not be marked inline; they're already comptime-only.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wrongnull
Copy link
Contributor Author

I close this pr in favor of #18061

@wrongnull wrongnull closed this Nov 22, 2023
@wrongnull wrongnull deleted the inline-trait-functions branch November 22, 2023 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants