You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit a510646
Browse filesBrowse the repository at this point in the historyBrowse files
fix(cs-lsp): bind same-name C# types by declared namespace (#2120)
Two projects declaring a class with the same simple name in namespaces
that share a root (Contoso.Platform.Identity.UserIdentityInfo vs
Contoso.Platform.BackOffice.Identity.UserIdentityInfo) had every CALLS
edge attached to whichever variant registered first, ignoring the
caller's `using` directive, enclosing namespace, fully-qualified name and
using-alias.
Root cause: C# graph QNs are path-derived, so cs_resolve_type_name's
namespace-prefix and using-namespace lookups (steps 5 and 7) never hit a
project type. Resolution fell through to the short-name fallback, whose
prefix score compares the file namespace against the path QN and is 0 for
every candidate, so registry order decided.
Fix:
- Record the declared namespace of each top-level C# type at extraction
(CBMDefinition.decl_namespace, walked from the AST). The file-level
namespace_name keeps only a file's FIRST namespace, which mislabels
every type of a multi-namespace file such as a reference assembly.
pxc_build_lsp_def carries it into the type's CBMLSPDef, and
result_compact relocates it.
- CBMRegisteredType.namespace_qn (C# only, top-level types only) is set by
cs_register_lsp_defs, which both the Tier-2 shared registry and the
per-file registry use, so sequential and parallel stay in lockstep.
- New resolution step 8b binds a simple or qualified type name to the
visible declaration in C# lookup order: enclosing namespaces innermost
outward, then `using` namespaces (or the global namespace for a
qualified name). A `using A = Ns.Type` alias binds the same way.
- cs_lookup_method also searches the type's other same-namespace
declarations (`partial` pieces, reference-assembly copies). These are
separate registry entries but one C# type. Without this, choosing the
namespace-correct piece that lacks the member would lose the edge to a
name-only fallback.
Proof on dotnet/runtime src/libraries (20,866 .cs files, same machine,
both binaries deterministic across two runs): CALLS 649,226 -> 657,564;
nodes unchanged (595,714). Most retargeted edges move from a target the
caller cannot see to one it can see through an enclosing namespace or
`using`. Many more move from non-method targets (enum members such as
ExpressionType.Constant) to the real partial-class methods
(Expression.Constant). The new edges are unqualified and typed calls
into sibling `partial` pieces (ImmutableArray.Create, XmlReader.Create,
AsnReader.ReadBoolean).
Test: parallel::parallel_csharp_same_name_class_binds_by_namespace covers
plain `using` in both directions, the enclosing namespace, a
fully-qualified name, a multi-namespace file and a `partial` member, in
the sequential pipeline and in the parallel pipeline with the production
Tier-2 C# registry. The harness gains an opt-in flag for that registry,
because cbm_pxc_run_one has no C# case.
Signed-off-by: Martin Vogel <[email protected]>
0 commit comments