dotnet / dotnet/linker

Linker fails when resolving type reference in sweep step

Open
#2,260 10 comments 0 reactions 0 assignees View on GitHub
area-Linker: Steps
Dominant language
C#
Stars
392
Forks
128
Avg merge
2d 10h
Merged PRs (30d)
2

Description

This was caused by #2234.

The problem is that first we call `SweepAssemblyReferences` on pretty much all assemblies. This will eventually call into `AssemblyReferenceCorrector.UpdateScopeOfTypeReference` which call `LinkContext.TryResolve`. In the failing case the type reference first points to "netstandard". It gets resolved to "System.Collections" and the type reference instance is overwritten to point to that. And the TryResolve cache remembers that this typeref points to "System.Collection" type-def.

Later on - we call ProcessAssemblyAction which in turn calls SweepAssembly on "System.Collection", this will remove the type-def from the assembly (not marked). This means that the type-def's Scope is reset to 'null'.

Now we eventually call ProcessAssemblyAction on the assembly which contained the type-ref. This will again end up calling `AssemblyReferenceCorrector.UpdateScopeOfTypeReference` and `TryResolve` on the same type-ref. Now the result is cached, so it returns the type-def which is now pointing to `null` scope. We try to "import" this type-def into the target assembly, and this fails, since it doesn't know where type type-def comes from.

Before the change, the `TryResolve` was a direct call to `Resolve`. In the first time around - it would return the same value (type-def). But second time around, the type-ref doesn't resolve anymore, since the type it points to has been removed, to `Resolve` returned null - and SweepStep has handling for this case - it instead resolves the assembly ref of the type-ref - which now points to "System.Collection" (was fixed up during the first pass) - so it imports that scope and leaves the type-ref pointing to that scope. This means it never actually relies on the type-ref to resolve - which it won't. In this case it's writing an unresolvable type-ref.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.