[linker] do not set scope of non-marked typerefs
commitfc9295536621139e8004d98abce8970eabad6381
authorRadek Doulik <rodo@xamarin.com>
Tue, 16 Feb 2016 21:21:58 +0000 (16 22:21 +0100)
committerRadek Doulik <rodo@xamarin.com>
Tue, 16 Feb 2016 21:44:29 +0000 (16 22:44 +0100)
tree4ff83da7d12d50d4e096872d4224cec0ed80ff07
parent8b36e3afb7b8c78462e30a8371b48e6849abbc3d
[linker] do not set scope of non-marked typerefs

 - fixes #38818

 - setting the *unchanged* scope to non-marked types is harmful,
   because in case the type has declaring type, the scope of declaring
   type is set as well. see
   https://github.com/mono/cecil/blob/master/Mono.Cecil/TypeReference.cs#L132

   public virtual IMetadataScope Scope {
      get ...
      set {
          var declaring_type = this.DeclaringType;
          if (declaring_type != null) {
              declaring_type.Scope = value;
              return;
          }
          scope = value;
      }
   }

   so in our case, we first set correctly scope of
   System.Collections.Generic.Dictionary`2 to mscorlib, then (re)set
   scope of System.Collections.Generic.Dictionary`2/ValueCollection
   and
   System.Collections.Generic.Dictionary`2/ValueCollection/Enumerator
   to System.Collection (note that these types are not marked and are
   swept away by linker), which sets scope of its declaring type
   System.Collections.Generic.Dictionary`2 back to System.Collection

   and because the System.Collection is linked-out, the typeref is
   incorrectly written with the scope set to System later
mcs/tools/linker/Mono.Linker.Steps/SweepStep.cs