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

Regression with base classes #265

Closed
Joy-less opened this issue Mar 21, 2024 · 1 comment
Closed

Regression with base classes #265

Joy-less opened this issue Mar 21, 2024 · 1 comment

Comments

@Joy-less
Copy link

The following code works in MemoryPack 1.10.0:

using System;
using System.Threading;
using MemoryPack;

Console.WriteLine(MemoryPackSerializer.Serialize(new Test()).Length);

public abstract class TestBase {
    public int Number = Interlocked.Increment(ref LastNumber);

    private static int LastNumber;
}
[MemoryPackable]
public partial class Test : TestBase {
}

However, it fails in 1.20.0 - 1.20.4 with the following errors:

CS0122: 'TestBase.LastNumber' is inaccessible due to its protection level
MemoryPack.Generator\MemoryPack.Generator.MemoryPackGenerator\Test.MemoryPackFormatter.g.cs 117
CS0103: The name 'Interlocked' does not exist in the current context
MemoryPack.Generator\MemoryPack.Generator.MemoryPackGenerator\Test.MemoryPackFormatter.g.cs 117

The first error can be removed by making LastNumber public, and the second error can be removed by enabling global usings.

The errors only occur when inheriting from a class (abstract or not).

@Joy-less Joy-less changed the title Regression with abstract classes Regression with base classes Mar 21, 2024
@hadashiA
Copy link
Contributor

Thanks for the sample code.

Since 1.20.0, I was trying to detect the default value from the source code, but it didn't take into account the case of using the static method you presented.

We decided to revert this feature.
I believe the compile error has been eliminated in 1.20.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants