Files
sx/examples/issue-0019.sx
2026-03-05 16:20:36 +02:00

43 lines
1.5 KiB
Plaintext

// issue-0019: #import c symbols are globally visible instead of scoped to the importing file
//
// When a file uses `#import c { #include "foo.h"; #source "foo.c"; }`,
// the C symbols become available to ALL files in the compilation unit,
// not just the file that imported them.
//
// This means a file can call C functions without importing the module
// that declares them, as long as some other file in the project does.
//
// Expected: C symbols from `#import c` should only be visible in files
// that directly (or transitively via SX #import) import the module.
//
// Repro:
// - a.sx: `#import c { #include "some_lib.h"; #source "some_lib.c"; };`
// - b.sx: does NOT import a.sx, but calls some_lib_function() — compiles successfully
//
// In the game project:
// - main.sx imports modules/stb_truetype.sx (which has #import c for kbts/stbtt)
// - ui/glyph_cache.sx does NOT import modules/stb_truetype.sx
// - ui/glyph_cache.sx calls kbts_ShapeRun, stbtt_InitFont, etc. — compiles fine
// - If main.sx removed the import, glyph_cache.sx would break
// Minimal repro structure (two files):
// --- module_with_c.sx ---
// #import c {
// #include "vendors/some_lib.h";
// #source "vendors/some_lib.c";
// };
//
// uses_c :: () -> s32 {
// some_lib_function();
// }
// --- main.sx (this file) ---
// #import "module_with_c.sx";
//
// main :: () -> s32 {
// // This should fail because we never imported the C module directly,
// // but currently it compiles:
// some_lib_function();
// }