Skip to content

Compiler crash when generated struct includes field of generated type from fn containing undeclared identifier #1483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tgschultz opened this issue Sep 7, 2018 · 1 comment
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@tgschultz
Copy link
Contributor

const std = @import("std");
const math = std.math;

pub fn Gen(comptime val: u32) type
{
    const UType = @IntType(false, math.ceil(val));

    const S = struct
    {
        code_len: UType,
    };
    return S;
}

test "Crash"
{
    const G = Gen(8);
}

I haven't been able to minimize the circumstances further than the above. As you can see, math.ceil is passed an incorrect type and should produce an error message communicating that. For some reason, this specific construction instead causes a compiler crash.

@andrewrk andrewrk added this to the 0.3.0 milestone Sep 7, 2018
@andrewrk andrewrk added the bug Observed behavior contradicts documented or intended behavior label Sep 7, 2018
@tgschultz tgschultz changed the title Compiler crash with @IntType under specific circumstances Compiler crash when generated struct includes field of generated type from fn containing undeclared identifier Sep 7, 2018
@tgschultz
Copy link
Contributor Author

tgschultz commented Sep 7, 2018

A more minimal example:

fn Undeclared() type
{
    return T;
}

fn Gen() type
{
    const X = Undeclared();
    return struct
    {
        x: X,
    };
}

test "undeclared identifier"
{
    const S = Gen();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

2 participants