Skip to content

Commit

Permalink
Fix a small bug in message origin for warnings from static field acce…
Browse files Browse the repository at this point in the history
…ss on generic type (#3186)

The warning needs to be generated from the origin where the field reference comes from - so if it's a method body, then from the method body. This is because the instantiation is determined by that place, not the field itself (the field is defined on an open generic definition of the type).

This syncs the relevants tests with a NativeAOT work-in-progress change, but in generately it adds a lot more cases and some better comments.

Co-authored-by: Tlakaelel Axayakatl Ceja <tlakaelel.ceja@microsoft.com>
  • Loading branch information
vitek-karas and tlakollo committed Jan 17, 2023
1 parent 4452038 commit c790896
Show file tree
Hide file tree
Showing 2 changed files with 320 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/linker/Linker.Steps/MarkStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1610,7 +1610,7 @@ protected void MarkField (FieldReference reference, DependencyInfo reason, in Me
Debug.Assert (reason.Kind == DependencyKind.FieldAccess || reason.Kind == DependencyKind.Ldtoken);
// Blame the field reference (without actually marking) on the original reason.
Tracer.AddDirectDependency (reference, reason, marked: false);
MarkType (reference.DeclaringType, new DependencyInfo (DependencyKind.DeclaringType, reference), new MessageOrigin (Context.TryResolve (reference)));
MarkType (reference.DeclaringType, new DependencyInfo (DependencyKind.DeclaringType, reference));

// Blame the field definition that we will resolve on the field reference.
reason = new DependencyInfo (DependencyKind.FieldOnGenericInstance, reference);
Expand Down
Loading

0 comments on commit c790896

Please sign in to comment.