Repository navigation
fix: report a type the generated container cannot name because another referenced assembly declares its full name (AWT260) - #455
Conversation
Test Results 27 files + 6 27 suites +6 3h 11m 24s ⏱️ + 1h 45m 20s Results for commit dcb5443. ± Comparison against base commit 7f28496. This pull request removes 116 and adds 1692 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
🚀 Benchmark ResultsCompared to the latest run of Time (Awaiten, latest
Relative performance (how many times as long the other container takes as Awaiten, main → PR)
All benchmarks compared to main
Raw results of BuildBenchmarksBenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.5 LTS (Noble Numbat) AMD EPYC 9V45 4.52GHz, 1 CPU, 4 logical and 2 physical cores .NET SDK 10.0.404 [Host] : .NET 10.0.15 (10.0.15, 10.0.1526.53008), X64 RyuJIT x86-64-v4 Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15 LaunchCount=1 WarmupCount=10
Raw results of RealisticResolveBenchmarksBenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.5 LTS (Noble Numbat) AMD EPYC 9V45 4.51GHz, 1 CPU, 4 logical and 2 physical cores .NET SDK 10.0.404 [Host] : .NET 10.0.15 (10.0.15, 10.0.1526.53008), X64 RyuJIT x86-64-v4 Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15 LaunchCount=1 WarmupCount=10
Raw results of ResolveBenchmarksBenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.5 LTS (Noble Numbat) AMD EPYC 9V45 4.51GHz, 1 CPU, 4 logical and 2 physical cores .NET SDK 10.0.404 [Host] : .NET 10.0.15 (10.0.15, 10.0.1526.53008), X64 RyuJIT x86-64-v4 Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15 LaunchCount=1 WarmupCount=10
|
d212140 to
7dfe5fe
Compare
…f the referenced assembly RunWithGeneratedCompilationReference, RunWithModuleAndBase with BaseBuild.CompilationReference and Analyzer.RunWithCompilationReference referenced the generated library as a compilation without checking that it compiles, so a broken library build could pass in that mode while the emitted-assembly helpers already throw on it. They now fail with the library's errors, as EmitToReference does.
…r referenced assembly declares its full name (AWT260) A container that imported modules of two libraries which both declare a public Lib.Clock emitted global::Lib.Clock, which is ambiguous between the references, so the generated code failed with CS0433 (and CS0677 for the volatile field of an instance handle). Plain C# can name such a type only through an extern alias, which the generator cannot add, so the container now reports AWT260 instead, once per type, at the import or registration that brings it into the graph, naming the assemblies that declare it. The check covers the services of every registration that joins the graph, every implementation the container builds, the parameters of constructors, factories, hooks, async initializers and decorator predicates, injected properties and [ImportService] types, including type arguments and element types. A type internal to the other assembly, a default the container replaces and a same-named type the graph never needs are not reported. A type the project declares itself wins over a referenced one, so only the referenced one is reported there.
…T260) A registration Key, a [FromKey] or a container-side property entry whose key is an enum constant or a typeof spells that type in the generated keyed dispatch and host forwarding, so a key type that another referenced assembly also declares slipped past AWT260 and the build failed with CS0433. Hooks and decorator predicates of a module of another assembly bind through its generated Internals class, which the message named instead of the module the user wrote. The remaining AWT260 paths (decorators, composites, open generic closings, [Arg], hooks, async initializers, predicates and Extends) had no tests. Reporting no longer allocates a list per type, and CollectExternalServiceTypes takes the names explicitly so no caller drops them by accident.
…cannot name (AWT260) The generated container also spells the type of an [AsyncInitializer<T>] and the imported or inherited modules (and base container) whose handles, factories, hooks, predicates or wrappers it calls, so a same-named type in another reference still failed with CS0433 instead of AWT260. A module is named only when the container calls into it, which the graph does not record in one place, so the emitted source decides; it is emitted a second time only when a module's name is ambiguous.
A reference with an extern alias stays out of global::, so the container names the type of the other assembly, as a test now proves.
Searching the emitted source for the module's name also matched a generic type of the same name, such as Lib.Mod<int> beside the module Lib.Mod, and reported a module the container never calls. The graph now reports a module or base container where it decides to call a member of it (a production member or generated factory, a hook, a predicate, a wrapper, a handle alias or setter) or names a type nested in it, like any other type. The reports now run inside the graph build, so a base of the same assembly that cannot name its module fails the extending container too, instead of leaving it to emit code that does not compile.
…260) A namespace of the same full name as a type the container needs, or an accessible type named like one of the type's namespaces, makes 'global::' fail with CS0434 just like a second type makes it fail with CS0433, so the container left generated code that did not compile instead of reporting AWT260. A namespace counts whatever the accessibility of its types, as the compiler sees it either way.
…s nothing from The generated code names everything through 'global::', so an alias only helps when no type the container needs and no module it imports lives in the aliased assembly; the page did not say that a module imported through the alias counts too.
The inline ternary that picked the needer for each parameter was hard to read; a local computed once before the loop says what it decides.
…ke (AWT260) A module's generated factory leaves deferred properties to setter wrappers the container calls with the dependency, so a same-named type there still broke the generated code with CS0433 instead of reporting AWT260.
…me itself Keeping the container in a project that references only one of the declaring assemblies cannot help when that project is one of them. The docs also note the CS0436 warning the generated code then shares with the user's own code, which fails builds with warnings as errors.
7dfe5fe to
dcb5443
Compare
|
…ner cannot name because another referenced assembly declares its full name (AWT260) (#455) by Valentin Breuß
…ner cannot name because another referenced assembly declares its full name (AWT260) (#455) by Valentin Breuß
|
This is addressed in release v0.16.0. |



When two referenced assemblies, or the project and a referenced assembly, declare an accessible type of the same full name, plain C# can name it only through an
extern alias, which the generator cannot add. The generated container then failed with CS0433, CS0434 or a type mismatch instead of a diagnostic. The container now reports each such name once as AWT260, at the import, registration orExtendsthat brings it into the graph, and names the assemblies that declare it.It covers every name the generated code spells: services, implementations, parameters, properties, imports, enum and
typeofkeys, async initializer types, deferred setters, and the modules and base containers the container calls into. A namespace of the same full name, or an accessible type named like one of its namespace segments, counts as a clash too. A reference with an extern alias stays out ofglobal::and is not reported, so the remedy offers an alias when the container needs nothing from that assembly, a reference to only one of the declarers, or a rename, and only a rename when the project declares the name itself.The compilation-reference test helpers referenced the generated library without checking that it compiles, so a broken library build could pass in that mode while the emitted-assembly helpers already threw on it. They now fail with the library's errors.