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

Compiler crash with certain combination of @typeName and @compileLog #1459

dbandstra opened this Issue Sep 2, 2018 · 1 comment


None yet
2 participants

dbandstra commented Sep 2, 2018

This code sample was stripped down from work in one of my projects.

See the comments in the code. The compiler is crashing when unpackComponentType is called twice (redundantly in this example), and when it's doing a compileLog.

Before I started stripping out code, it was crashing with an assert: analyze.cpp:4690: uint32_t hash_const_val(ConstExprValue*): Assertion `const_val->special == ConstValSpecialStatic' failed. Now it's crashing without an assert, but I assume the root problem is the same (because the permutations of 'this works, this works, this doesn't work' didn't change as I stripped out code).

const builtin = @import("builtin");
const std = @import("std");

const ComponentA = struct{ unused: u32 };
const ComponentB = struct{ unused: u32 };
const SystemData = struct{
  a: *ComponentA,
  b: *ComponentB,

fn unpackComponentType(comptime field_type: type) type {
  // if this compileLog is removed, the crash goes away

  return field_type;

test "" {
  inline for (@typeInfo(SystemData).Struct.fields) |field| {

    // this doesn't crash
    if (false) {
      _ = @typeName(unpackComponentType(field.field_type));

    // this doesn't crash
    if (false) {
      comptime const field_type = unpackComponentType(field.field_type);
      _ = @typeName(field_type);

    // this crashes (if there is @compileLog in unpackComponentType)
    if (true) {
      _ = unpackComponentType(field.field_type);
      _ = @typeName(unpackComponentType(field.field_type));


@andrewrk andrewrk added this to the 0.3.0 milestone Sep 2, 2018

@andrewrk andrewrk added the bug label Sep 2, 2018

@andrewrk andrewrk closed this in c84548e Sep 22, 2018


This comment has been minimized.


andrewrk commented Sep 22, 2018

Further reduced test case:

fn Foo(comptime T: type) type {
    return T;
test "" {
    _ = Foo(i32);
    _ = @typeName(Foo(i32));

@tgschultz I'm guessing this bug had been affecting you at some point. @compileLog had accidental side-effects of preventing the function that it is in from being comptime evaluated. Now it should be side effect free (aside from the intended compile error it causes plus the stderr output).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment