From 09e4ec2aa5834cd0e91c7f50295887db76b4e650 Mon Sep 17 00:00:00 2001 From: agra Date: Wed, 20 May 2026 10:59:39 +0300 Subject: [PATCH] ffi 2.11 xfail: DSL call site on `#jni_class`-typed receiver MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `act.getWindow()` on `act: *Activity` (where `Activity :: #jni_class("android/app/Activity") { getWindow :: ... }`) should lower to `#jni_call(*void)(act, "getWindow", "()Ljava/lang/Object;")` (omitted-env form picking up env from the enclosing `#jni_env` scope via 2.16b's lexical-direct path). Today's sema reports "unresolved: 'getWindow'" because foreign-class members aren't yet wired into the method-resolution path. The make-green follow-up needs: - sema: register `ForeignClassDecl.members` so method names resolve on foreign-class receivers (or suppress the unresolved fallback for them). - lower: build a `foreign_class_map` in scan pass; new arm in `lowerCall`'s method-dispatch site emits a synthetic `FfiIntrinsicCall { kind: jni_call, args: [target, "name", "(sig)Ret", method_args...] }` with the descriptor derived via `jni_descriptor.deriveMethod`. - type system: `*Activity` resolution path so `inferExprType` on the receiver returns a known type (likely register foreign classes as synthetic 0-field structs reusing the struct-type machinery). Larger session needed — pausing here at the xfail. --- examples/ffi-jni-class-08-call.sx | 31 +++++++++++++++++++++++ tests/expected/ffi-jni-class-08-call.exit | 1 + tests/expected/ffi-jni-class-08-call.txt | 1 + 3 files changed, 33 insertions(+) create mode 100644 examples/ffi-jni-class-08-call.sx create mode 100644 tests/expected/ffi-jni-class-08-call.exit create mode 100644 tests/expected/ffi-jni-class-08-call.txt diff --git a/examples/ffi-jni-class-08-call.sx b/examples/ffi-jni-class-08-call.sx new file mode 100644 index 0000000..dd1fefa --- /dev/null +++ b/examples/ffi-jni-class-08-call.sx @@ -0,0 +1,31 @@ +// Phase 2 step 2.11 (PLAN-FFI.md): xfail then green for DSL call-site +// lowering — `inst.method(args)` on a `#jni_class`-typed value lowers +// to `#jni_call(T)(inst, "method", "(sig)Ret", args...)` with the +// descriptor auto-derived from the sx signature. +// +// `#jni_env(env)` brings env into lexical scope; the omitted-env +// `#jni_call` form (2.16b) picks it up directly. + +#import "modules/std.sx"; + +Activity :: #jni_class("android/app/Activity") { + getWindow :: (self: *Self) -> *void; +} + +g_should_call : bool = false; + +unused_jni :: (env: *void, act: *Activity) { + #jni_env(env) { + // Today: this fails — sema doesn't know `Activity` as a type, or + // the method dispatch doesn't recognize foreign-class members. + win := act.getWindow(); + } +} + +main :: () -> s32 { + if g_should_call { + unused_jni(null, null); + } + print("ok\n"); + 0; +} diff --git a/tests/expected/ffi-jni-class-08-call.exit b/tests/expected/ffi-jni-class-08-call.exit new file mode 100644 index 0000000..d00491f --- /dev/null +++ b/tests/expected/ffi-jni-class-08-call.exit @@ -0,0 +1 @@ +1 diff --git a/tests/expected/ffi-jni-class-08-call.txt b/tests/expected/ffi-jni-class-08-call.txt new file mode 100644 index 0000000..b09005d --- /dev/null +++ b/tests/expected/ffi-jni-class-08-call.txt @@ -0,0 +1 @@ +/Users/agra/projects/sx/examples/ffi-jni-class-08-call.sx:21:16: error: unresolved: 'getWindow'