From aefb3dbf687b46775bca1b600317bc053648b211 Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Thu, 5 Nov 2026 20:41:25 +0100 Subject: First steps for overrides --- stubs/src/kotlin/proxy/KotlinProxyLog.java | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'stubs/src/kotlin/proxy/KotlinProxyLog.java') diff --git a/stubs/src/kotlin/proxy/KotlinProxyLog.java b/stubs/src/kotlin/proxy/KotlinProxyLog.java index 50e347a..3afdb38 100644 --- a/stubs/src/kotlin/proxy/KotlinProxyLog.java +++ b/stubs/src/kotlin/proxy/KotlinProxyLog.java @@ -51,9 +51,33 @@ public final class KotlinProxyLog { } /** - * Called by stub methods that declare a reference return type (other than - * String). Reflectively instantiates the real, un-stubbed class of that - * return type so the caller (the daemon) can keep going: e.g. + * Return value for stub methods with a reference return type (other than + * String). Asks {@link KotlinProxyOverrides#invoke} first — per-method + * custom implementations, passed the full argument list — and falls back + * to materializing a real no-arg instance of the declared return type. + * The generated body checkcasts the result to the declared type. + * + * The generated bytecode pushes the args array FIRST (member, owner and + * return type last) so its stack stays shallow (peak 4) — keep this + * parameter order in sync with RETURN_VALUE_DESC in gen_class.py. + */ + public static Object returnValue(Object[] args, String member, + String ownerDotName, String returnDotName) { + Object v = KotlinProxyOverrides.invoke(member, ownerDotName, + returnDotName, args); + if (v != KotlinProxyOverrides.NO_VALUE) { + log("OVERRIDE " + ownerDotName + "." + member + + " -> " + dump(v)); + return v; + } + return newInstance(returnDotName); + } + + /** + * Default return-value materialization (the fallback of + * {@link #returnValue}). Reflectively instantiates the real, un-stubbed + * class of the declared return type so the caller (the daemon) can keep + * going: e.g. * K2JVMCompiler.createArguments() returns a genuine K2JVMCompilerArguments, * which lets parseCommandLineArguments run and doExecute be reached with the * fully-populated args (the boundary we want to log). Returns null when the -- cgit v1.3.1