Skip to content

Compile time calculation generates types lacks type hints and code completion. #2583

@Anglebase

Description

@Anglebase

For example, the following code:

const std = @import("std");

pub fn foo() void {
    std.debug.print("Hello World!", .{});
}

pub fn main() !void {
    const p = &foo;

    const T = @Type(.{ .@"struct" = .{
        .fields = &.{
            std.builtin.Type.StructField{
                .name = "foo",
                .is_comptime = false,
                .type = *const @TypeOf(foo),
                .alignment = 4,
                .default_value_ptr = @ptrCast(&p),
            },
        },
        .decls = &.{},
        .is_tuple = false,
        .layout = .auto,
    } });

    const a = T{};
    a.foo();
}

The effect in VSCode is as follows:

Image

The instances of type T and T generated during compilation in the code have no type hints and code completion.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions