test(ffi-linkage): Phase 5.0 prereq — xfail extern undeclared-library ref unvalidated
An `extern LIB "csym"` ref must name a declared #library / #import c unit, like its `#foreign LIB` twin (example 1620). Today checkForeignRefs reads only foreign_expr.library_ref and skips the extern keyword's extern_lib, so a bogus `extern nosuchunit "abs"` compiles silently (the symbol resolves via the default image and runs). Expected pins the DESIRED compile-time diagnostic; the next commit extends checkForeignRefs to green it. Fourth extern/#foreign divergence and a prerequisite for the fn-decl migration. 647 corpus (1231 xfail), 444 unit.
This commit is contained in:
19
examples/1231-ffi-extern-undeclared-lib.sx
Normal file
19
examples/1231-ffi-extern-undeclared-lib.sx
Normal file
@@ -0,0 +1,19 @@
|
||||
// An `extern LIB "csym"` reference must name something real, exactly like
|
||||
// its `#foreign LIB` twin (example 1620): `nosuchunit` names neither a
|
||||
// #library constant nor a named `#import c` unit, so this is a compile-time
|
||||
// diagnostic — the bogus library reference is caught BEFORE the symbol
|
||||
// would silently resolve through whatever image happens to carry it.
|
||||
//
|
||||
// Regression (FFI-linkage Part B): `checkForeignRefs` validated only a
|
||||
// `#foreign` (foreign_expr) library_ref and skipped the `extern` keyword's
|
||||
// `extern_lib`, so a bogus `extern` lib reference compiled silently (the
|
||||
// symbol resolved via the default image and ran). Prerequisite for
|
||||
// migrating the fn-decl `#foreign` path onto `extern`.
|
||||
#import "modules/std.sx";
|
||||
|
||||
c_abs :: (n: i32) -> i32 extern nosuchunit "abs";
|
||||
|
||||
main :: () -> i32 {
|
||||
print("c_abs = {}\n", c_abs(-5));
|
||||
0
|
||||
}
|
||||
1
examples/expected/1231-ffi-extern-undeclared-lib.exit
Normal file
1
examples/expected/1231-ffi-extern-undeclared-lib.exit
Normal file
@@ -0,0 +1 @@
|
||||
1
|
||||
5
examples/expected/1231-ffi-extern-undeclared-lib.stderr
Normal file
5
examples/expected/1231-ffi-extern-undeclared-lib.stderr
Normal file
@@ -0,0 +1,5 @@
|
||||
error: extern library 'nosuchunit' is not declared; expected a #library constant or a named '#import c' unit
|
||||
--> examples/1231-ffi-extern-undeclared-lib.sx:14:1
|
||||
|
|
||||
14 | c_abs :: (n: i32) -> i32 extern nosuchunit "abs";
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
Reference in New Issue
Block a user