Skip to content

Using Return Type Of Fallible Function In Another Function Causes Incorrect Comptime Error #15023

Closed
@ominitay

Description

@ominitay

Zig Version

0.11.0-dev.2168+322ace70f

Steps to Reproduce and Observed Behavior

This is the following minimum reproduction case I could determine for this:

const HelperReturnType = @typeInfo(@TypeOf(helper)).Fn.return_type.?;

pub fn concat() HelperReturnType {
    return "";
}

fn helper(comptime string: []const u8) ![]const u8 {
    return string ++ " world!";
}

test {
    _ = try concat();
}

The following compile error is observed on invocation of zig test repro.zig:

repro.zig:8:12: error: unable to resolve comptime value
    return string ++ " world!";
           ^~~~~~
repro.zig:8:12: note: slice value being concatenated must be comptime-known

It is worth noting that helper doesn't need to be called for this to happen, and that using @typeInfo to get the error set for helper and use it as part of an error union for concat's return value also exhibits this behaviour.

Making helper an inline fn allows the program to compile successfully, as does removing the concat invocation. Writing _ = HelperReturnType without a concat invocation does not reproduce the error.

Expected Behavior

The code should have compiled successfully.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions