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

Duplicate cIncludes detection #4017

Closed
Swoogan opened this issue Dec 31, 2019 · 3 comments
Closed

Duplicate cIncludes detection #4017

Swoogan opened this issue Dec 31, 2019 · 3 comments
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@Swoogan
Copy link
Contributor

Swoogan commented Dec 31, 2019

This isn't a bug per se. Take the scenario:

a.zig

pub usingnamespace @cImport({
    @cInclude("gtk/gtk.h");
});

pub usingnamespace @import("b.zig");

b.zig

pub usingnamespace @cImport({
    @cInclude("gtk/gtk.h");
});

Building this will result in over 2000 errors, mostly pertaining to redefinitions. After doing this I gained a better understanding of what I was actually asking the compiler to do and it's clear that what I was asking it to do is stupid, but I feel like this might be an opportunity for the compiler to fail early. One error message stating "Attempt to re-include header 'gtk/gtk.h' in the same scope" would be better than 2000 symptoms of the root problem.

@andrewrk andrewrk added this to the 0.7.0 milestone Dec 31, 2019
@daurnimator daurnimator added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Jan 1, 2020
@daurnimator
Copy link
Contributor

daurnimator commented Jan 1, 2020

It would make more sense to be duplicate @cImport detection rather than @cInclude duplication: sometimes you have libraries where you include the same header multiple times with different defines set.

That said, I don't know if this should be an error. Two unrelated zig libraries might @cimport the same C library. There is no reason for that to be an error.

@pixelherodev
Copy link
Contributor

I think making it so that the redefinitions don't occur is better than marking what should in some situations succeed as an error.

@andrewrk
Copy link
Member

#20630

@andrewrk andrewrk closed this as not planned Won't fix, can't repro, duplicate, stale Jul 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

4 participants