@@ -3265,11 +3265,14 @@ function createHostSplit(load) {
32653265 for ( const stmt of e . sf . statements ) {
32663266 if ( ! ts . isImportDeclaration ( stmt ) || ! ts . isStringLiteral ( stmt . moduleSpecifier ) ) continue ;
32673267 const m = HOST_SPLIT . specifier . exec ( stmt . moduleSpecifier . text ) ;
3268+ // [#30147] A statics-form body's `this` is typed by the forwarder's
3269+ // interface, which `protocol.ts` itself declares and exports.
3270+ const fromHost = stmt . moduleSpecifier . text === `./${ HOST_SPLIT . host . replace ( / \. t s $ / , '.js' ) } ` ;
32683271 const named = stmt . importClause ?. namedBindings ;
3269- if ( ! m || ! named || ! ts . isNamedImports ( named ) ) continue ;
3272+ if ( ( ! m && ! fromHost ) || ! named || ! ts . isNamedImports ( named ) ) continue ;
32703273 const el = named . elements . find ( ( x ) => x . name . text === hostType ) ;
32713274 if ( ! el ) continue ;
3272- const from = entry ( `${ HOST_SPLIT . dir } /${ m [ 1 ] } .ts` ) ;
3275+ const from = entry ( fromHost ? hostRel : `${ HOST_SPLIT . dir } /${ m [ 1 ] } .ts` ) ;
32733276 const exported = ( el . propertyName ?? el . name ) . text ;
32743277 return from ?. sf . statements . find ( ( s ) => ts . isInterfaceDeclaration ( s ) && s . name . text === exported ) ;
32753278 }
@@ -3305,16 +3308,18 @@ function createHostSplit(load) {
33053308 }
33063309 const hostType = type . typeName . text ;
33073310 // The per-member series' host interface is the module's own; ruling E's
3308- // may be imported from the module that declares it (`protocol-host.ts`).
3309- const iface = viaHostParam
3311+ // may be imported from the module that declares it (`protocol-host.ts`),
3312+ // and so may a #30147 receiver-form body's (`this: Pick<ProtocolHost, …>`,
3313+ // or the statics forwarder's interface, which `protocol.ts` declares).
3314+ const iface = viaHostParam || bodies . relPath !== hostRel && hostType !== undefined && ! bodies . sourceFile ?. statements . some ( ( s ) => ts . isInterfaceDeclaration ( s ) && s . name . text === hostType )
33103315 ? hostInterface ( bodies . relPath , hostType )
33113316 : bodies . sourceFile ?. statements . find ( ( s ) => ts . isInterfaceDeclaration ( s ) && s . name . text === hostType ) ;
33123317 const member = iface ?. members . find (
33133318 ( m ) => ts . isPropertySignature ( m ) && m . name && ts . isIdentifier ( m . name ) && m . name . text === name ,
33143319 ) ;
33153320 if ( ! member ) return undefined ;
33163321 const body = typedAsHostMember ( member . type , name ) ? hostMethods ( ) ?. get ( name )
3317- : viaHostParam && typedAsHostStatic ( member . type , name ) ? hostMethods ( { static : true } ) ?. get ( name )
3322+ : typedAsHostStatic ( member . type , name ) ? hostMethods ( { static : true } ) ?. get ( name )
33183323 : undefined ;
33193324 return body ? { body, bodies : entry ( hostRel ) . bodies } : undefined ;
33203325 } ;
@@ -3342,14 +3347,31 @@ function createHostSplit(load) {
33423347 const hostOfThis = ( arg ) => ! ! arg && ts . isCallExpression ( arg ) && ts . isIdentifier ( arg . expression ) &&
33433348 arg . expression . text === HOST_SPLIT . hostOf && arg . arguments . length === 1 &&
33443349 arg . arguments [ 0 ] . kind === ts . SyntaxKind . ThisKeyword ;
3350+ // [#30147] A plain-form stub hands its facet member the method's own
3351+ // parameters and nothing else (no host: the body reads nothing of the class).
3352+ const ownParams = ( ) => call . arguments . every ( ( a ) => {
3353+ const id = ts . isSpreadElement ( a ) ? a . expression : a ;
3354+ return ts . isIdentifier ( id ) && method . parameters . some ( ( p ) => ts . isIdentifier ( p . name ) && p . name . text === id . text ) ;
3355+ } ) ;
33453356 if ( ts . isPropertyAccessExpression ( callee ) && ts . isIdentifier ( callee . expression ) && ts . isIdentifier ( callee . name ) &&
33463357 callee . name . text !== 'call' && HOST_SPLIT . facet . test ( callee . expression . text ) ) {
33473358 // [#29985] `<X>Facet.fn(protocolHost(this), …)` — the facade form of
33483359 // ruling 6624345766: a facet class's static method takes the host
3349- // first; a private static's stub, `<X>Facet.fn(…)`, passes none.
3350- if ( isStatic ? hostOfThis ( first ) : ! hostOfThis ( first ) ) return undefined ;
3360+ // first; a private static's stub, `<X>Facet.fn(…)`, passes none, and
3361+ // so does an instance method's plain-form stub (#30147).
3362+ if ( isStatic ? hostOfThis ( first ) : ! hostOfThis ( first ) && ! ownParams ( ) ) return undefined ;
33513363 facet = callee . expression . text ;
33523364 fnName = callee . name . text ;
3365+ } else if ( ts . isPropertyAccessExpression ( callee ) && ts . isIdentifier ( callee . name ) && callee . name . text === 'call' &&
3366+ ts . isPropertyAccessExpression ( callee . expression ) && ts . isIdentifier ( callee . expression . expression ) &&
3367+ ts . isIdentifier ( callee . expression . name ) && HOST_SPLIT . facet . test ( callee . expression . expression . text ) ) {
3368+ // [#30147] The receiver forms: `<X>Facet.fn.call(protocolHost(this), …)`
3369+ // for an instance method, `<X>Facet.fn.call(<Class>Statics, …)` for a
3370+ // private static; the facet member runs on that receiver as `this`.
3371+ const onStatics = ! ! first && ts . isIdentifier ( first ) && first . text === `${ HOST_SPLIT . hostClass } Statics` ;
3372+ if ( isStatic ? ! onStatics : ! hostOfThis ( first ) ) return undefined ;
3373+ facet = callee . expression . expression . text ;
3374+ fnName = callee . expression . name . text ;
33533375 } else if ( ts . isPropertyAccessExpression ( callee ) ) {
33543376 // `fn.call(host, …)` — the per-member series.
33553377 if ( ! ts . isIdentifier ( callee . name ) || callee . name . text !== 'call' || ! ts . isIdentifier ( callee . expression ) ) return undefined ;
@@ -3813,6 +3835,10 @@ function establishesBenign(expr, ctx) {
38133835 const hop = ctx . functionBodies . split . hostCall ( call , ctx . functionBodies ) ;
38143836 if ( hop ) ( { body, bodies : guardBodies } = hop ) ;
38153837 }
3838+ // [#30147] A guard whose body moved to its facet (the members pass's receiver
3839+ // and plain forms) is answered from the facet member its stub delegates to.
3840+ const movedGuard = body && guardBodies . split ? guardBodies . split . stubTarget ( body , guardBodies ) : undefined ;
3841+ if ( movedGuard ) ( { body, bodies : guardBodies } = movedGuard ) ;
38163842 if ( ! body || ! ts . isBlock ( body ) ) return false ;
38173843 const exits = [ ] ;
38183844 const consulted = new Set ( ) ;
@@ -5318,6 +5344,11 @@ const SELF_TEST_BATTERIES = Object.freeze({
53185344 'flags: #29985 — a protocol.ts try around a `<X>Facet.fn(protocolHost(this), …)` stub follows the facet\'s static method, and the stub costs no hop' : 1 ,
53195345 'flags: #29985 — a try around a private static whose stub calls `<X>Facet.fn(…)` follows the facet\'s static method' : 1 ,
53205346 'passes: #29985 — negative control: a stub calling a static of a class the facet pattern does not name is not followed' : 1 ,
5347+ 'passes: #30147 — a moved body\'s `host.guard(error)` whose guard moved by the plain form answers on the facet\'s discriminated branch' : 1 ,
5348+ 'flags: #30147 — negative control: a plain-form stub whose facet guard asks no error type still invents the answer' : 1 ,
5349+ 'flags: #30147 — a protocol.ts try around a `<X>Facet.fn.call(protocolHost(this), …)` stub follows the facet member and its `this.x()` host call' : 1 ,
5350+ 'passes: #30147 — negative control: a `.call` stub whose receiver is not `protocolHost(this)` is not followed' : 1 ,
5351+ 'flags: #30147 — a try around a private static whose stub runs on the statics forwarder follows the facet member and its `this.x()` static call' : 1 ,
53215352 'ledger (read seams): a stale entry PASSES and is reported; an unledgered seam still FAILS (#26444)' : 1 ,
53225353 'ledger (read seams): a ledgered file on disk the scan never READ is refused; a deleted one passes (#26444)' : 1 ,
53235354 } ) ,
@@ -5331,15 +5362,15 @@ const SELF_TEST_BATTERIES = Object.freeze({
53315362// `undefined` and the comparison fails loudly.
53325363const SELF_TEST_BATTERY_FLOOR = Object . freeze ( {
53335364 selfTest : 80 ,
5334- selfTestReadSeams : 73 ,
5365+ selfTestReadSeams : 78 ,
53355366} ) ;
53365367
53375368// The roster's TOTAL, checked from BOTH verdict sites. Each entry checks only
53385369// its own partition, so nothing inside `selfTest()`'s verdict would notice
53395370// `selfTestReadSeams`'s partition being deleted from the roster wholesale — the
53405371// deleted partition's own size pin is not evaluated by anyone once its entry
53415372// stops reaching it. This is the one assertion that survives that deletion.
5342- const SELF_TEST_BATTERY_TOTAL_FLOOR = 147 ;
5373+ const SELF_TEST_BATTERY_TOTAL_FLOOR = 152 ;
53435374
53445375/**
53455376 * The floor for ONE partition of the roster, run from that partition's own
@@ -8220,6 +8251,114 @@ function selfTestReadSeams() {
82208251 expectViolation : false ,
82218252 expectSeams : 0 ,
82228253 } ,
8254+ // [#30147] The members pass's receiver forms: a stub that runs its facet
8255+ // member on the host (`<X>Facet.fn.call(protocolHost(this), …)`), on the
8256+ // statics forwarder (`.call(<Class>Statics, …)`), or with no receiver
8257+ // (an instance method's plain form, `<X>Facet.fn(<its own parameters>)`).
8258+ {
8259+ name : 'passes: #30147 — a moved body\'s `host.guard(error)` whose guard moved by the plain form answers on the facet\'s discriminated branch' ,
8260+ files : {
8261+ [ `${ HOST_SPLIT . dir } /protocol.ts` ] : FACADE_HOST . replace ( `private rethrowUnlessGone(error: unknown): void {
8262+ if (isMissingTableError(error)) return;
8263+ throw error;
8264+ }` , `private rethrowUnlessGone(error: unknown): void {
8265+ return ProtocolUninstallFacet.rethrowUnlessGone(error);
8266+ }` ) ,
8267+ [ `${ HOST_SPLIT . dir } /protocol-host.ts` ] : E1_HOST_MODULE ,
8268+ [ `${ HOST_SPLIT . dir } /protocol-uninstall.ts` ] : FACET_MODULE . replace ( 'export class ProtocolUninstallFacet {' , `export class ProtocolUninstallFacet {
8269+ static rethrowUnlessGone(error: unknown): void {
8270+ if (isMissingTableError(error)) return;
8271+ throw error;
8272+ }
8273+ static async listRows(host: Pick<ProtocolHost, 'findRows' | 'rethrowUnlessGone'>, id: string) {
8274+ try { return await host.findRows(id); }
8275+ catch (error) { host.rethrowUnlessGone(error); return []; }
8276+ }` ) ,
8277+ } ,
8278+ expectViolation : false ,
8279+ expectSeams : 1 ,
8280+ expectDiscriminatorsUsed : [ 'isMissingTableError' ] ,
8281+ } ,
8282+ {
8283+ name : 'flags: #30147 — negative control: a plain-form stub whose facet guard asks no error type still invents the answer' ,
8284+ files : {
8285+ [ `${ HOST_SPLIT . dir } /protocol.ts` ] : FACADE_HOST . replace ( `private rethrowUnlessGone(error: unknown): void {
8286+ if (isMissingTableError(error)) return;
8287+ throw error;
8288+ }` , `private rethrowUnlessGone(error: unknown): void {
8289+ return ProtocolUninstallFacet.rethrowUnlessGone(error);
8290+ }` ) ,
8291+ [ `${ HOST_SPLIT . dir } /protocol-host.ts` ] : E1_HOST_MODULE ,
8292+ [ `${ HOST_SPLIT . dir } /protocol-uninstall.ts` ] : FACET_MODULE . replace ( 'export class ProtocolUninstallFacet {' , `export class ProtocolUninstallFacet {
8293+ static rethrowUnlessGone(error: unknown): void { void error; }
8294+ static async listRows(host: Pick<ProtocolHost, 'findRows' | 'rethrowUnlessGone'>, id: string) {
8295+ try { return await host.findRows(id); }
8296+ catch (error) { host.rethrowUnlessGone(error); return []; }
8297+ }` ) ,
8298+ } ,
8299+ expectViolation : true ,
8300+ expectSeams : 1 ,
8301+ } ,
8302+ {
8303+ name : 'flags: #30147 — a protocol.ts try around a `<X>Facet.fn.call(protocolHost(this), …)` stub follows the facet member and its `this.x()` host call' ,
8304+ files : {
8305+ [ `${ HOST_SPLIT . dir } /protocol.ts` ] : FACADE_HOST
8306+ . replace ( 'return ProtocolUninstallFacet.listRowsMoved(protocolHost(this), id);' , 'return ProtocolUninstallFacet.listRowsMoved.call(protocolHost(this), id);' )
8307+ . replace ( '/*ROLLBACK*/' , `
8308+ async rollBack(id: string) {
8309+ try { return await this.listRowsMoved(id); }
8310+ catch { return []; }
8311+ }` ) ,
8312+ [ `${ HOST_SPLIT . dir } /protocol-host.ts` ] : E1_HOST_MODULE ,
8313+ [ `${ HOST_SPLIT . dir } /protocol-uninstall.ts` ] : FACET_MODULE
8314+ . replace ( "static async listRowsMoved(host: Pick<ProtocolHost, 'findRows'>, id: string) {\n return await host.findRows(id);" ,
8315+ "static async listRowsMoved(this: Pick<ProtocolHost, 'findRows'>, id: string) {\n return await this.findRows(id);" ) ,
8316+ } ,
8317+ expectViolation : true ,
8318+ expectSeams : 1 ,
8319+ } ,
8320+ {
8321+ name : 'passes: #30147 — negative control: a `.call` stub whose receiver is not `protocolHost(this)` is not followed' ,
8322+ files : {
8323+ [ `${ HOST_SPLIT . dir } /protocol.ts` ] : FACADE_HOST
8324+ . replace ( 'return ProtocolUninstallFacet.listRowsMoved(protocolHost(this), id);' , 'return ProtocolUninstallFacet.listRowsMoved.call(this.someHost, id);' )
8325+ . replace ( '/*ROLLBACK*/' , `
8326+ async rollBack(id: string) {
8327+ try { return await this.listRowsMoved(id); }
8328+ catch { return []; }
8329+ }` ) ,
8330+ [ `${ HOST_SPLIT . dir } /protocol-host.ts` ] : E1_HOST_MODULE ,
8331+ [ `${ HOST_SPLIT . dir } /protocol-uninstall.ts` ] : FACET_MODULE
8332+ . replace ( "static async listRowsMoved(host: Pick<ProtocolHost, 'findRows'>, id: string) {\n return await host.findRows(id);" ,
8333+ "static async listRowsMoved(this: Pick<ProtocolHost, 'findRows'>, id: string) {\n return await this.findRows(id);" ) ,
8334+ } ,
8335+ expectViolation : false ,
8336+ expectSeams : 0 ,
8337+ } ,
8338+ {
8339+ name : 'flags: #30147 — a try around a private static whose stub runs on the statics forwarder follows the facet member and its `this.x()` static call' ,
8340+ files : {
8341+ [ `${ HOST_SPLIT . dir } /protocol.ts` ] : `
8342+ export interface ObjectStackProtocolImplementationStaticsHost {
8343+ readonly readStatic: (typeof ObjectStackProtocolImplementation)['readStatic'];
8344+ }
8345+ export const ObjectStackProtocolImplementationStatics = {} as ObjectStackProtocolImplementationStaticsHost;
8346+ ` + FACADE_HOST
8347+ . replace ( 'return ProtocolUninstallFacet.readStaticMoved(engine, t);' , 'return ProtocolUninstallFacet.readStaticMoved.call(ObjectStackProtocolImplementationStatics, engine, t);' )
8348+ . replace ( '/*ROLLBACK*/' , `
8349+ async rollBack(id: string) {
8350+ try { return await ObjectStackProtocolImplementation.readStaticMoved(this.engine, id); }
8351+ catch { return []; }
8352+ }` ) ,
8353+ [ `${ HOST_SPLIT . dir } /protocol-host.ts` ] : E1_HOST_MODULE ,
8354+ [ `${ HOST_SPLIT . dir } /protocol-uninstall.ts` ] : FACET_MODULE
8355+ . replace ( "import type { ProtocolHost } from './protocol-host.js';" , "import type { ProtocolHost } from './protocol-host.js';\n import type { ObjectStackProtocolImplementationStaticsHost } from './protocol.js';" )
8356+ . replace ( "static async readStaticMoved(engine: any, t: string) {\n return await engine.find(t, {});" ,
8357+ "static async readStaticMoved(this: Pick<ObjectStackProtocolImplementationStaticsHost, 'readStatic'>, engine: any, t: string) {\n return await this.readStatic(engine, t);" ) ,
8358+ } ,
8359+ expectViolation : true ,
8360+ expectSeams : 1 ,
8361+ } ,
82238362 {
82248363 name : 'BOUND (#25467 E1): the `host.x()` hop IS a hop — a third hop through the host is still refused' ,
82258364 files : {
0 commit comments