Skip to content

comptime_int exported constants are silently dropped #10004

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
CrystalGamma opened this issue Oct 22, 2021 · 4 comments
Closed

comptime_int exported constants are silently dropped #10004

CrystalGamma opened this issue Oct 22, 2021 · 4 comments
Labels
bug Observed behavior contradicts documented or intended behavior miscompilation The compiler reports success but produces semantically incorrect code.
Milestone

Comments

@CrystalGamma
Copy link

CrystalGamma commented Oct 22, 2021

Zig Version

0.8.1

Steps to Reproduce

Write a source file like this:

export const my_const = 42;

Build it, using e. g. zig build-obj. Inspect the resulting object file or assembly.

Expected Behavior

Either a compiler error, or the value to be emitted using a default representation (though which one would be unclear, with comptime_int type).

Actual Behavior

The constant is silently dropped.

@CrystalGamma CrystalGamma added the bug Observed behavior contradicts documented or intended behavior label Oct 22, 2021
@mrakh
Copy link
Contributor

mrakh commented Oct 22, 2021

Makes sense for it not to show up, as comptime_int has no size or alignment information. Changing it to the following should fix the issue:

export const my_const : u32 = 42;

But it is weird that trying to export a comptime_int doesn't throw a compiler error.

@daurnimator
Copy link
Contributor

Being a comptime int, it doesn't show up in exported object files; but it does should show up in emitted headers.

@CrystalGamma
Copy link
Author

So an exported comptime_int not generating an error is a design decision? That doesn't seem to be well-documented. At least I can't find it in The Documentation searching for 'export'.

@andrewrk andrewrk added the miscompilation The compiler reports success but produces semantically incorrect code. label Nov 20, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.9.1 Nov 20, 2021
@andrewrk andrewrk modified the milestones: 0.9.1, 0.10.0 Feb 3, 2022
@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Apr 17, 2022
@Vexu
Copy link
Member

Vexu commented Apr 23, 2023

Fixed by #12075

@Vexu Vexu closed this as completed Apr 23, 2023
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 miscompilation The compiler reports success but produces semantically incorrect code.
Projects
None yet
Development

No branches or pull requests

5 participants