diff --git a/src/parser.zig b/src/parser.zig index d3df6f1..305d078 100644 --- a/src/parser.zig +++ b/src/parser.zig @@ -2002,6 +2002,14 @@ pub const Parser = struct { // Optional postfix linkage modifier: `extern` (import) / `export` (define). const extern_export = self.parseOptionalExternExport(); + // `extern` and `export` are mutually exclusive — one declaration is either + // an import or a definition, never both. Reject the redundant second keyword + // with a clear message rather than the bare "expected ';'" the body parser + // would otherwise emit. + if (extern_export != .none and (self.current.tag == .kw_extern or self.current.tag == .kw_export)) { + return self.fail("conflicting linkage: 'extern' and 'export' cannot be combined — a declaration is either an import ('extern') or a definition ('export')"); + } + // Optional `[LIB] ["csym"]` tail after extern/export — a library-alias // ident then a C symbol-name string, both optional (mirrors // `#foreign LIB "csym"`). Stored on extern_lib/extern_name; the rename