From 66c59bb8b0355d81c305389db3755de9b2de3360 Mon Sep 17 00:00:00 2001 From: Raphael Amorim Date: Thu, 11 Jun 2026 08:02:20 +0200 Subject: [PATCH] add signature tests --- tests/unit/mod_private_type.jam | 16 ++++++++++++++++ tests/unit/test_private_type_signatures.jam | 15 +++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/unit/mod_private_type.jam create mode 100644 tests/unit/test_private_type_signatures.jam diff --git a/tests/unit/mod_private_type.jam b/tests/unit/mod_private_type.jam new file mode 100644 index 0000000..ffcd1db --- /dev/null +++ b/tests/unit/mod_private_type.jam @@ -0,0 +1,16 @@ +// Helper for test_private_type_signatures: a PRIVATE struct used in +// this module's own pub-fn signatures. Private types register under +// their qualified identity so these signatures resolve; importers can +// only touch the values opaquely (through the pub fns), never name the +// type. +const Inner = struct { + value: u32, +}; + +pub fn makeInner(v: u32) Inner { + return Inner { value: v }; +} + +pub fn readInner(i: Inner) u32 { + return i.value; +} diff --git a/tests/unit/test_private_type_signatures.jam b/tests/unit/test_private_type_signatures.jam new file mode 100644 index 0000000..19678a2 --- /dev/null +++ b/tests/unit/test_private_type_signatures.jam @@ -0,0 +1,15 @@ +// A module whose pub fns traffic in a PRIVATE struct. Private types +// were once never registered at all — the module's own signatures +// failed to resolve (`unknown module handle` on the compiler's own +// qualified identity) unless some other module happened to define a +// same-named type that collided into the same registry slot. They now +// register under their qualified identity; the importer passes the +// values through opaquely. (Privacy still holds: naming the type via a +// handle is rejected — pinned by the C++ namespace-access tests.) + +const { assert } = import("test"); +const { makeInner, readInner } = import("mod_private_type"); + +tfn privateTypeFlowsThroughPubFns() { + assert(readInner(makeInner(41)), 41); +} -- 2.51.2