Skip to content

Fix mismatch_assignment error reported for generic arguments using items imported at an enclosing scope - #3121

Merged
dalance merged 1 commit into
veryl-lang:masterfrom
taichi-ishitani:fix_import_visibility_in_nested_scope
Aug 2, 2026
Merged

Fix mismatch_assignment error reported for generic arguments using items imported at an enclosing scope#3121
dalance merged 1 commit into
veryl-lang:masterfrom
taichi-ishitani:fix_import_visibility_in_nested_scope

Conversation

@taichi-ishitani

@taichi-ishitani taichi-ishitani commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

fix #3120

Cause

scope::is_imported only inspected the import / wildcard bindings declared directly in the given scope, without walking toward the enclosing scopes. Its two helpers are documented as such:

  • imports_get: "Returns the explicit import bindings of name directly in scope."
  • wildcards_get: "Returns the wildcard imports declared directly in scope."

So a reference made from inside a generate block asked the wrong scope:

module Module25H {
    import Pacakge25G::baz_1_2;                                        // bound in `Module25H`

    alias package baz_1_3 = veryl_sample4::baz_pkg::<baz_1_2::BAZ_0, 3>;

    inst baz: veryl_sample4::baz_if::<baz_1_3>;                        // scope: Module25H     -> OK
    :g {
        inst u: veryl_sample4::baz_module::<baz_1_3> (                 // scope: Module25H::g  -> NG
            baz: baz,
        );
    }
}
reference site scope asked is_imported head_already_qualified qualification
inst baz Module25H true false runs
inst u Module25H::g false true skipped

Once the qualification is skipped, baz_1_2 stays unqualified. In unalias_inner the loop then starts at the alias itself instead of its containing package, so Pacakge25G is never visited and its gen-const map {BAZ_0_VALUE: 1, BAZ_1_VALUE: 2} is never pushed onto generic_maps. apply_map runs with an empty map, BAZ_0_VALUE is left unsubstituted, and GenericSymbol::mangled() drops the arguments altogether because one of them still refers to a GenericConst:

inst baz : baz_pkg::<baz_pkg::<1,2>::BAZ_0, 3>
inst u   : baz_pkg::<baz_pkg::BAZ_0, 3>          // arguments lost

The two baz_if signatures then disagree, Signature::is_compatible fails on generic_parameters, and mismatch_assignment is reported for the port connection:

dst: sym=.. full_path=["veryl_sample4", "baz_if"] gparams=[]
src: sym=.. full_path=["veryl_sample4", "__baz_if__veryl_sample4___baz_pkg__veryl_sample4___baz_pkg__1__2_BAZ_0__3"]
     gparams=["PKG=veryl_sample4 __baz_pkg__veryl_sample4___baz_pkg__1__2_BAZ_0__3"]

Fix

scope::is_imported now walks from the query scope toward the enclosing scopes, stopping at the module / interface / package containing it, since import is not visible across a container boundary.

let mut current = Some(intern_namespace(namespace));
while let Some(scope) = current {
    let imported = /* existing imports_get / wildcards_get checks, unchanged */;
    if imported {
        return true;
    }
    if is_import_container(scope) {
        break;
    }
    current = parent(scope);
}
false

The two ifdef-related checks are carried over verbatim. In particular b.define_context == dctx stays an equality, so a reference inside an #[ifdef]-guarded generate block still does not see an unguarded import of its container. That is unchanged from the current behaviour (the nested scope holds no bindings today either), and relaxing it would alter ifdef visibility semantics on its own, so it is left out of this fix.

@codspeed-hq

codspeed-hq Bot commented Jul 30, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 8 untouched benchmarks


Comparing taichi-ishitani:fix_import_visibility_in_nested_scope (b6ac5ae) with master (283e237)

Open in CodSpeed

@taichi-ishitani
taichi-ishitani force-pushed the fix_import_visibility_in_nested_scope branch 2 times, most recently from 6937d97 to 79c1a3c Compare July 31, 2026 06:04
@taichi-ishitani
taichi-ishitani force-pushed the fix_import_visibility_in_nested_scope branch from 79c1a3c to b6ac5ae Compare August 2, 2026 01:28
@taichi-ishitani
taichi-ishitani requested a review from dalance August 2, 2026 01:29
@dalance
dalance merged commit ec35073 into veryl-lang:master Aug 2, 2026
21 checks passed
@taichi-ishitani
taichi-ishitani deleted the fix_import_visibility_in_nested_scope branch August 2, 2026 14:09
@dalance dalance added this to the v0.20.3 milestone Aug 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

False positive of mismatch_assignment warning

2 participants