StefanMaron / BusinessCentral.LinterCop

Community driven code linter for AL (MS Dynamics 365 Business Central)
https://stefanmaron.com
MIT License
77 stars 31 forks source link

BusinessCentral.LinterCop.Design.Rule0044AnalyzeTransferFields causes InvalidCastException #469

Closed a-gnius closed 9 months ago

a-gnius commented 10 months ago

Looks like a similar issue to #448 is still there. It has to do with a Rule 44 related to transferfields: "BusinessCentral.LinterCop.Design.Rule0044AnalyzeTransferFields".

Could it be investigated?

Error Details: Unhandled exception. System.InvalidCastException: Unable to cast object of type 'Microsoft.Dynamics.Nav.CodeAnalysis.Syntax.SimpleNamedDataTypeSyntax' to type 'Microsoft.Dynamics.Nav.CodeAnalysis.Syntax.SubtypedDataTypeSyntax'. at BusinessCentral.LinterCop.Design.Rule0044AnalyzeTransferFields.GetObjectName(VariableDeclarationBaseSyntax variable) at BusinessCentral.LinterCop.Design.Rule0044AnalyzeTransferFields.AnalyzeTransferFields(OperationAnalysisContext ctx) at System.Threading.Tasks.Task.<>c.b__128_1(Object state) at System.Threading.QueueUserWorkItemCallback.<>c.<.cctor>b__6_0(QueueUserWorkItemCallback quwi) at System.Threading.ExecutionContext.RunForThreadPoolUnsafe[TState](ExecutionContext executionContext, Action`1 callback, TState& state) at System.Threading.QueueUserWorkItemCallback.Execute() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() at System.Threading.Thread.StartCallback()

tinestaric commented 9 months ago

This looks like you have a procedure with the name TransferFields() defined, and it doesn't take a parameter of type Record as the first parameter.

In any case, @Arthurvdv I think we need to add an early return to AnalyzeTransferFields to only analyze BuiltInMethods. Same as we already have for rule 0040.

YannRobertCargo commented 9 months ago

Same here, I think it might be because we use transferfields with a parameter of type Variant

a-gnius commented 9 months ago

It's like @tinestaric guessed. We had a TransferFields() procedure with RecordRef parameters.

Arthurvdv commented 9 months ago

I think we need to add an early return to AnalyzeTransferFields to only analyze BuiltInMethods.

Good idea, that will resolve exceptions and possible false positives

I think it might be because we use transferfields with a parameter of type Variant

Thanks for this one, this also causes an exception when passing a Variant in stead of a Record variable as parameter to the TransferFields method.

Both of these issues should now resolved in the (pre)release version of v0.30.11 of the LinterCop.