Rename all example tests/companions to the XXXX-category-test-name scheme (per-category 100-blocks: basic 0010, types 0100, ... errors 1000, diagnostics 1100, ffi 1200, ffi-objc 1300, ffi-jni 1400, vectors 1500, platform 1600). Companions and dir/C fixtures move in lockstep with their parent test; #import/#source/#include paths rewritten to match. Expected output now lives in examples/expected/ (a sibling dir of the tests) split into three streams per the new convention: <name>.exit / <name>.stdout / <name>.stderr (+ optional <name>.ir) run_examples.sh rewritten: scans examples/ and issues/ for an expected/<name>.exit marker, captures stdout and stderr separately (no more 2>&1), compares each stream + exit + optional IR snapshot. Behavior validated unchanged: every renamed test reproduces its prior merged output + exit (diffs limited to file paths/basenames embedded in diagnostics + traces, which correctly reflect the new names). Suite: 292 passed, 0 failed. 50-smoke.sx split + issue relocation + docs follow in subsequent commits.
63 lines
2.0 KiB
Plaintext
63 lines
2.0 KiB
Plaintext
// M2.3 — `#extends ForeignClass` method-resolution chaining.
|
|
//
|
|
// When `obj.method()` is called on a foreign-class pointer and
|
|
// `method` isn't declared directly on the receiver's class, the
|
|
// compiler walks the `#extends` chain to find an ancestor that
|
|
// declared it. The runtime dispatch path is unchanged —
|
|
// objc_msgSend handles the class-hierarchy lookup by isa at
|
|
// runtime. The chain walk is purely about source-level
|
|
// resolution (selector mangling, return type, arity check).
|
|
|
|
#import "modules/std.sx";
|
|
#import "modules/compiler.sx";
|
|
#import "modules/std/objc.sx";
|
|
|
|
NSObjectBase :: #foreign #objc_class("NSObject") {
|
|
alloc :: () -> *NSObjectBase;
|
|
init :: (self: *NSObjectBase) -> *NSObjectBase;
|
|
hash :: (self: *NSObjectBase) -> u64;
|
|
}
|
|
|
|
// Sx-defined class that extends a foreign one. M1.2 registers
|
|
// the class at module init; `hash` is reached via the M2.3 chain
|
|
// walk through NSObjectBase, then dispatched by objc_msgSend.
|
|
SxThing :: #objc_class("SxThing") {
|
|
#extends NSObjectBase;
|
|
counter: s32;
|
|
|
|
alloc :: () -> *SxThing;
|
|
init :: (self: *SxThing) -> *SxThing;
|
|
}
|
|
|
|
// And a chain-of-three: SxLeaf → SxMiddle → NSObjectBase.
|
|
SxMiddle :: #objc_class("SxMiddle") {
|
|
#extends NSObjectBase;
|
|
alloc :: () -> *SxMiddle;
|
|
init :: (self: *SxMiddle) -> *SxMiddle;
|
|
}
|
|
SxLeaf :: #objc_class("SxLeaf") {
|
|
#extends SxMiddle;
|
|
alloc :: () -> *SxLeaf;
|
|
init :: (self: *SxLeaf) -> *SxLeaf;
|
|
}
|
|
|
|
main :: () -> s32 {
|
|
inline if OS == .macos {
|
|
// 1-level chain: SxThing → NSObjectBase.
|
|
t := SxThing.alloc().init();
|
|
h_t : u64 = t.hash();
|
|
if h_t == 0 { print("FAIL: SxThing.hash returned 0\n"); return 1; }
|
|
|
|
// 2-level chain: SxLeaf → SxMiddle → NSObjectBase.
|
|
l := SxLeaf.alloc().init();
|
|
h_l : u64 = l.hash();
|
|
if h_l == 0 { print("FAIL: SxLeaf.hash returned 0\n"); return 1; }
|
|
|
|
print("extends chain: SxThing.hash=ok, SxLeaf.hash=ok\n");
|
|
}
|
|
inline if OS != .macos {
|
|
print("extends chain: SxThing.hash=ok, SxLeaf.hash=ok\n");
|
|
}
|
|
0;
|
|
}
|