oleg-st / InlineMethod.Fody

Inline methods in compile time
MIT License
14 stars 2 forks source link

`System.FieldAccessException` Because of Inlining Method #8

Open WalkerCodeRanger opened 3 months ago

WalkerCodeRanger commented 3 months ago

Using InlineMethod.Fody 0.7.2 and Fody 6.8.1 on .NET 8. The below code throws a System.FieldAccessException because Clear is inlined. It makes sense to me why the runtime might enforce access restrictions that cause this exception. But the method should not be inlined in a case like this and a warning should be issued that it can't be inlined because it would access an inaccessible field.

using System.Collections.Generic;
using InlineMethod;

public class Example
{
    private List<int> values = new();

    [Inline]
    public void Clear() => values.Clear();
}

public class User
{
    public void Caller() => new Example().Clear();
}

Exception:

System.FieldAccessException
Attempt by method 'User.Caller()' to access field 'Example.values' failed.
   at User.Caller() in C:\dataFast\azoth-lang\azoth.tools.bootstrap\Compiler.Core\Attributes\User.cs:line 14
WalkerCodeRanger commented 3 months ago

Note I've seen the same thing happen with an inaccessible method.