From edd9b1c15157e84ca2090a961fc04a221f99fbeb Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Mon, 26 Oct 2026 18:11:51 +0800 Subject: [PATCH] fix(defines): resolve package-level from-import symbols to the package module --- App/lib/core/Gen/ImportsGenMixin.vp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/App/lib/core/Gen/ImportsGenMixin.vp b/App/lib/core/Gen/ImportsGenMixin.vp index 1f50584..5f9e035 100644 --- a/App/lib/core/Gen/ImportsGenMixin.vp +++ b/App/lib/core/Gen/ImportsGenMixin.vp @@ -735,8 +735,11 @@ novirtual class ImportsGenMixin: if alias.asname is not None: local_name = alias.asname orig_name = alias.name - # For `from . import Y`, _resolve_relative_module returns the package name - # but Y is a submodule, so map local_name -> the full submodule name. + # For `from . import Y`, _resolve_relative_module returns the package name. + # Y may be a real submodule (target package.Y) or a package __init__ symbol + # such as `JSON_NULL` (target the package itself). Only append the name + # when it denotes a submodule; otherwise the DefineT/global lives in the + # package vpi and the synthetic `package.Y` module does not exist. fi_target: str = resolved if impf.module is None and resolved is not None: fl_t: sizet = string.strlen(resolved) @@ -746,7 +749,8 @@ novirtual class ImportsGenMixin: string.strcpy(jb_t, resolved) jb_t[fl_t] = '.' string.strcpy(jb_t + fl_t + 1, alias.name) - fi_target = jb_t + if StubMergerStore.LookupSha1ByModName(jb_t) is not None or self._is_local_module_file(alias.name) != 0: + fi_target = jb_t trans._from_imports = self.add_from_import(trans.Pool, trans._from_imports, local_name, fi_target, orig_name) # Static symbols (forbidden cross-module): `from mod import name` hitting one # fail-fasts. Logic stays in _CheckStaticFromImport (inlining breaks inference).