postsharp / Metalama

Metalama is a Roslyn-based meta-programming framework. Use this repo to report bugs or ask questions.
181 stars 6 forks source link

IntroduceDependencyAttribute isn't working on record types #228

Closed LanceXact closed 11 months ago

LanceXact commented 1 year ago

The IntroduceDependencyAttribute used within the SimpleLogAttribute to inject an ILogger _logger isn't working on record types at compile-time. I'm getting this error:

Severity Code Description Project File Line Suppression State Error LAMA0041 'OverrideMethodAspect.BuildAspect' threw 'InvalidCastException' when applied to 'SomeRecord.GetValue()': Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.Syntax.RecordDeclarationSyntax' to type 'Microsoft.CodeAnalysis.CSharp.Syntax.ConstructorDeclarationSyntax'. Exception details are in 'C:\Users\xxxxx\AppData\Local\Temp\Metalama\CrashReports\2023.2.5\exception-f187d93b-fe84-4ec8-8ded-e0785ba642aa.txt'. To attach a debugger to the compiler, use the '-p:MetalamaDebugCompiler=True' command-line option. Entities C:\Source\xxxx\SomeRecord.cs 11 Active

Here's the offending record type (I created a tiny reproducible version):

public record SomeRecord(string Value)
{
    public string GetValue()
    {
        return Value;
    }
}
PostSharpBot commented 1 year ago

Hello @LanceXact, thank you for submitting this issue. We will try to get back to you as soon as possible. Note to the PostSharp team, this ticket is being tracked in our dashboard under ID TP-33922.

addabis commented 1 year ago

We have reproduced the issue on our side.

The underlying API that [IntroduceDependency] uses currently does not support records, but you should get a more user-friendly error rather than this exception.

We will be working on improving this. Thanks a lot for the report.

prochan2 commented 11 months ago

This bug has been fixed in Metalama 2024.0.3-preview.