Skip to content
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

Crash in InternPool when referencing a non-existant member of a struct #17878

Open
IntegratedQuantum opened this issue Nov 5, 2023 · 3 comments
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Milestone

Comments

@IntegratedQuantum
Copy link
Contributor

Zig Version

0.12.0-dev.1390+94cee4fb2

Steps to Reproduce and Observed Behavior

I've been getting crashes like this for a few months now, where having a compiler error in specific cases causes zig to crash.

const std = @import("std");

pub const World = struct {
	itemDrops: @This().doesntExist = undefined, // Error here
};

pub const RotationMode = struct {
	dependsOnNeighbors: bool = false,
	generateData: *const fn(world: *World) void = undefined,
};

var rotationModes: std.StringHashMap(RotationMode) = undefined;

pub fn main() !void {
	rotationModes = undefined;
	var result: RotationMode = .{};
	_ = result;
}
$ zig build-exe test.zig
Segmentation fault (core dumped)

Expected Behavior

It should report a compiler error:

$ zig build-exe test.zig
test.zig:4:20: error: struct 'test.World' has no member named 'doesntExist'
 itemDrops: @This().doesntExist = undefined, // Error here
            ~~~~~~~^~~~~~~~~~~~
test.zig:3:19: note: struct declared here
pub const World = struct {
                  ^~~~~~

I suspect that this may be similar to #17859. It appears to produce a similar stack trace. The circumstances appear to be different however. That's why I decided to report this separately.
It appears that the InternPool isn't great at dealing with compiler errors in specific circumstances.

@IntegratedQuantum IntegratedQuantum added the bug Observed behavior contradicts documented or intended behavior label Nov 5, 2023
@Vexu Vexu added the frontend Tokenization, parsing, AstGen, Sema, and Liveness. label Nov 5, 2023
@Vexu Vexu added this to the 0.13.0 milestone Nov 5, 2023
@Daggerfall-is-the-best-TES-game
Copy link

Daggerfall-is-the-best-TES-game commented Jul 5, 2024

on zig-windows-x86_64-0.14.0-dev.154+768b17755 I get this error message so I think this has been fixed

src\main.zig:4:23: error: struct 'main.World' has no member named 'doesntExist'
    itemDrops: @This().doesntExist = undefined, // Error here
               ~~~~~~~^~~~~~~~~~~~
src\main.zig:3:19: note: struct declared here
pub const World = struct {
                  ^~~~~~

@IntegratedQuantum
Copy link
Contributor Author

It also works for me, even with 0.13.0, and it's also working with a debug build of the compiler.

@nektro
Copy link
Contributor

nektro commented Jul 5, 2024

we should double check there's a test covering this before closing

@andrewrk andrewrk modified the milestones: 0.14.0, 0.15.0 Feb 10, 2025
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 frontend Tokenization, parsing, AstGen, Sema, and Liveness.
Projects
None yet
Development

No branches or pull requests

5 participants