@@ -180,10 +180,35 @@ private void markGlobAsAssigned() {
180180 * @return A RuntimeScalar representing the dereferenced value or reference. If the key
181181 * is not recognized, an empty RuntimeScalar is returned.
182182 */
183+ @ Override
183184 public RuntimeScalar hashDerefGet (RuntimeScalar index ) {
184- // System.out.println("glob hashDerefGet " + index.toString());
185+ return getGlobSlot (index );
186+ }
187+
188+ @ Override
189+ public RuntimeScalar hashDerefGetNonStrict (RuntimeScalar index , String packageName ) {
190+ // For typeglobs, slot access doesn't need symbolic reference resolution
191+ // Just access the slot directly
192+ return getGlobSlot (index );
193+ }
194+
195+ /**
196+ * Get a typeglob slot (CODE, SCALAR, ARRAY, HASH, IO, FORMAT).
197+ * This is the common implementation for both strict and non-strict contexts.
198+ */
199+ private RuntimeScalar getGlobSlot (RuntimeScalar index ) {
200+ // System.out.println("glob getGlobSlot " + index.toString());
185201 return switch (index .toString ()) {
186- case "CODE" -> GlobalVariable .getGlobalCodeRef (this .globName );
202+ case "CODE" -> {
203+ // Only return CODE ref if the subroutine is actually defined
204+ RuntimeScalar codeRef = GlobalVariable .getGlobalCodeRef (this .globName );
205+ if (codeRef .type == RuntimeScalarType .CODE && codeRef .value instanceof RuntimeCode code ) {
206+ if (code .defined ()) {
207+ yield codeRef ;
208+ }
209+ }
210+ yield new RuntimeScalar (); // Return undef if code doesn't exist
211+ }
187212 case "IO" -> IO ;
188213 case "SCALAR" -> GlobalVariable .getGlobalVariable (this .globName );
189214 case "ARRAY" -> {
@@ -211,10 +236,16 @@ public RuntimeScalar getIO() {
211236
212237 public RuntimeGlob setIO (RuntimeScalar io ) {
213238 this .IO = io ;
239+ // If the IO scalar contains a RuntimeIO, set its glob name
240+ if (io .value instanceof RuntimeIO runtimeIO ) {
241+ runtimeIO .globName = this .globName ;
242+ }
214243 return this ;
215244 }
216245
217246 public RuntimeGlob setIO (RuntimeIO io ) {
247+ // Set the glob name in the RuntimeIO for proper stringification
248+ io .globName = this .globName ;
218249 this .IO = new RuntimeScalar (io );
219250 return this ;
220251 }
0 commit comments