Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MutatingMethods_MutationsAffectOriginal test fails (imported from CoreFX) #9088

Closed
EgorBo opened this issue Jun 9, 2018 · 7 comments
Closed
Assignees
Projects

Comments

@EgorBo
Copy link
Member

EgorBo commented Jun 9, 2018

Steps to Reproduce

The following test imported from CoreFX fails on mono (and works fine on .NET Core 2.1):

using System;

namespace ConsoleApplication11
{
    internal class Program
    {
        public static void Main()
        {
            MutatingStruct? ms = new MutatingStruct() { Value = 1 };

            for (int i = 1; i <= 4; i++)
            {
                AssertEqual(i.ToString(), ms.Value.ToString());
                AssertEqual(i, ms.Value.Value);

                AssertEqual(i.ToString(), ms.ToString());
                AssertEqual(i + 1, ms.Value.Value);
            }

            for (int i = 5; i <= 6; i++)
            {
                ms.Value.Equals(new object());
                AssertEqual(i, ms.Value.Value);

                ms.Equals(new object());
                AssertEqual(i + 1, ms.Value.Value);
            }
        }

        private static void AssertEqual(object o1, object o2)
        {
            if (!o1.Equals(o2))
                throw new Exception($"{o1} != {o2}");
        }

        private struct MutatingStruct
        {
            public int Value;
            public override string ToString() => Value++.ToString();
            public override bool Equals(object obj) => Value++.Equals(null);
            public override int GetHashCode() => Value++.GetHashCode();
        }
    }   
}

Current Behavior

Unhandled Exception:
System.Exception: 6 != 5

Expected Behavior

Exception is not thrown (.NET Core 2.1)

On which platforms did you notice this

[x] macOS
[ ] Linux
[ ] Windows

@marek-safar marek-safar added this to Bugs Pool in Bugs Week via automation Jun 11, 2018
@marek-safar
Copy link
Member

@vargaz please add it to your bugs week list

@lewurm lewurm self-assigned this Jun 12, 2018
@lewurm lewurm moved this from Bugs Pool to In Progress in Bugs Week Jun 12, 2018
@vargaz
Copy link
Contributor

vargaz commented Jun 14, 2018

            ms.Equals(new object());

doesn't seem to call MutatingStruct.Equals ().

@vargaz
Copy link
Contributor

vargaz commented Jun 14, 2018

2 problems here:
ms.Equals(new object());
returns false without calling ms.Value.Equals, since object () is not the same type.

it should be changed to:
ms.Equals(new MutatingStruct() { Value = 1 });

Also, Nullable.Equals () does:
return other.value.Equals (value);
this should be changed to
return value.Equals (other.value);

@lewurm lewurm assigned vargaz and unassigned lewurm Jun 14, 2018
@lewurm
Copy link
Contributor

lewurm commented Jun 14, 2018

FWIW, the interp has the same result. it's a problem in the BCL imho.

@jaykrell
Copy link
Contributor

Mono BCL that is?

@vargaz
Copy link
Contributor

vargaz commented Jun 18, 2018

Should we enable the original test ?

@marek-safar
Copy link
Member

@vargaz @lewurm added the test in his commit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Bugs Week
Archived
Development

No branches or pull requests

5 participants