Skip to content

Commit 1b67471

Browse files
committed
fix: resolve extern type methods by stripping $ prefix in impl registration
When register_impl_blocks processes `impl Tensor { def sum(self) ... }`, the for_type is resolved to Type::Extern { name: "$Tensor" } (with $ prefix from runtime_prefix). But the TypeDefinition in the registry is stored under the bare name "Tensor". The lookup for "$Tensor" failed, so methods were never added to the type, causing "Method 'sum' not found" errors that skipped the entire main function. Fix: strip the $ prefix when looking up extern types in the registry. This allows all 94 Tensor methods to be properly registered, enabling method calls like a.sum() and a.mean() to resolve correctly. hello_simple.zynml now runs end-to-end with correct output.
1 parent 46c9bcd commit 1b67471

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

crates/compiler/src/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,15 +299,18 @@ pub fn register_impl_blocks(
299299
}
300300
Type::Extern { name, .. } => {
301301
// Look up extern type by name
302+
// Extern types have runtime_prefix names like "$Tensor",
303+
// but TypeDefinitions are registered under the bare name "Tensor"
302304
let name_str = name.resolve_global().unwrap_or_default();
305+
let bare_name = name_str.strip_prefix('$').unwrap_or(&name_str);
303306
if let Some(type_def) = program.type_registry.get_type_by_name(*name) {
304307
Some(type_def.id)
305308
} else {
306-
// Try with a fresh InternedString
307-
let fresh_name =
308-
zyntax_typed_ast::InternedString::new_global(&name_str);
309+
// Try with bare name (strip $ prefix)
310+
let bare_interned =
311+
zyntax_typed_ast::InternedString::new_global(bare_name);
309312
if let Some(type_def) =
310-
program.type_registry.get_type_by_name(fresh_name)
313+
program.type_registry.get_type_by_name(bare_interned)
311314
{
312315
Some(type_def.id)
313316
} else {

0 commit comments

Comments
 (0)