Skip to content

Error CS8374 Cannot ref-assign 'val' to 'reference' because 'val' has a narrower escape scope than 'reference' #3419

@greenozon

Description

@greenozon

Input code

Can't compile decompiled code

Erroneous output

		public static int CountDifferences<T>(T[] enumerable1, T[] enumerable2)
		{
			if (enumerable1 == null)
			{
				throw new ArgumentNullException("enumerable1");
			}
			if (enumerable2 == null)
			{
				throw new ArgumentNullException("enumerable2");
			}
			if (enumerable1.Length != enumerable2.Length)
			{
				throw new ArgumentException("Sizes of arrays are different");
			}
			int num = 0;
			for (int i = 0; i < enumerable1.Length; i++)
			{
				ref readonly T reference = ref enumerable1[i];
				T val = default(T);
				if (val == null)
				{
					val = reference;
					reference = ref val;
				}
				if (!reference.Equals(enumerable2[i]))
				{
					num++;
				}
			}
			return num;
		}

Image

Details

  • ILSpy version 9.0.0.7915+53522c45f887c4dc8f490815f40a724e4e9e1559
    .NET version 8.0.11+9cb3b725e3ad2b57ddc9fb2dd48d2d170563a8f5

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDecompilerThe decompiler engine itself

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions