Repository navigation
fix(LC0095, LC0099): resolve parameter references through the binder - #641
Merged
Merged
Conversation
A parameter counted as referenced whenever any identifier in the body carried its name, including the member name of a field or method access such as MyTable.Name, so such parameters were never reported. The name scan now only pre-filters; the body is bound once and a parameter is referenced only when a bound parameter reference resolves to it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…confirmed The walker now removes confirmed parameters from the candidate set and stops visiting once the set is empty. New guards cover a record parameter used as a receiver, a parameter used as a filter value next to a field with the same name, a report procedure filtering a dataitem, and a reference under a binding error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…kips OperationWalker does not descend into is/as, conditional expressions or the test page, query, report and xmlport member accesses, so a parameter used only inside one of them stayed an unconfirmed candidate and was reported. The walker now confirms candidates by name inside those nodes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…lker skips Test page, page part, query, table key and field group, report and xmlport member accesses now visit their Instance instead of falling back to the name scan, so a parameter named like a query column is reported. Only is/as and conditional expressions, which the netstandard SDK cannot name, keep the name fallback. Diagnostics are reported in declaration order. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
LC0095/LC0099 decided "referenced" purely syntactically: a parameter was removed from the unused set whenever any
IdentifierNameSyntaxin the body carried its name, including the member name of a field or method access. Soprocedure Foo(Name: Text)whose body only readsMyTable.Namewas never reported (false negative).Fix
The case-insensitive name scan stays as a cheap pre-filter: binding is skipped only when no parameter name appears in the body. Otherwise the body is bound once (
SemanticModel.GetOperation, pre-computed by the driver for aCodeBlockAction) and a smallOperationWalkerremoves each name-matched candidate from a set when a boundIParameterReferenceExpression.Parameterequals it, stopping as soon as the set is empty. Candidates left in the set, plus parameters the name scan never matched, are reported. When the operation is null or the bound bodyIsInvalid(binding errors propagate to the block, and references under invalid nodes are missing, e.g.Rec.Init()on a record of an unresolved table), the name-scan result stands, so broken code never gets extra reports.IParameterReferenceExpression,OperationWalker.VisitParameterReferenceExpressionandIOperation.IsInvalidexist in the netstandard2.0 SDK at 12.0.Fixtures
HasDiagnostic/ParameterNamedLikeAccessedField.al(LC0095) andHasDiagnostic/EventSubscriberParameterNamedLikeField.al(LC0099): the body reads onlyMyTable.Name. Both failed before the fix.HasDiagnostic/ParameterUsedAsSetRangeField.al:MyTable.SetRange(Name, 'x'); the compiler binds the bareNameto the table field, not the parameter, so the parameter is unreferenced.NoDiagnostic/ParameterUsedWithDifferentCasing.al,ParameterPassedAsVarArgument.al,ParameterAssignedOnly.al: a different-casing read, avarargument and an assignment target all still bind as parameter references.NoDiagnostic/ParameterUsedAsRecordReceiver.al(record parameter as receiver ofSetRange/Get),ParameterUsedAsFilterValue.al(MyTable.SetRange(Name, Name): the field argument binds to the field, the value to the parameter),ParameterUsedInReportProcedure.al(report procedure filtering a dataitem with its parameter).NoDiagnostic/ParameterUsedUnderInvalidNode.al(error-tolerant fixture,NoDiagnosticInDocumentWithErrors): a record parameter of an unresolved table used only asMyRecord.Init(). It fails without theIsInvalidfallback. An undeclared receiver (Unknown.DoSomething(Name)) does not exercise the fallback: the bad call keeps its argument bound to the parameter.Review note: the three plain-identifier NoDiagnostic fixtures (assignment target,
varargument, different casing) are guards for the new walker, not the failing regressions; the regressions are the HasDiagnostic fixtures above. Per-body binding is the same cost class as PC0030's walker: oneGetOperationper code block that passes the cheap pre-filter.Review finding: nodes the SDK walker skips
OperationWalkerdoes not descend intoIIsExpression,IAsExpression,IConditionalOperatorExpression, the test page accesses (ITestPartAccess,ITestFilterAccess,ITestFilterFieldAccess),IPagePartAccess, the query accesses (IQueryElementAccess,IQueryDataItemAccess),ITableKeyAccess,ITableFieldGroupAccess, the report accesses (IReportLabelAccess,IReportDataItemAccess,IReportColumnAccess,IReportLayoutAccess) orIXmlPortNodeAccess; they fall to the emptyDefaultVisit(verified at the 12.0.11 netstandard2.0 floor and at 30.0.44). A parameter used only inside one of them stayed an unconfirmed candidate and was reported, a false positive the name scan never produced. NoDiagnostic fixturesParameterUsedInIsExpression,ParameterUsedInAsExpression,ParameterUsedInConditionalExpression(gated at 14.0),ParameterUsedAsTestPageReceiverandParameterUsedAsQueryReceiverfailed before the fix.IOperationhas noChildrenat any version. The access kinds all have visit methods at the 12.0 netstandard floor, so the walker overrides each one to visit itsInstance; a new HasDiagnostic fixtureParameterNamedLikeQueryColumn(an unusedNameparameter next toMyQuery.Name) proves the receiver path does not fall back to a name match. Is/as/conditional do not exist in the 12.0 netstandard SDK the netstandard2.1 build compiles against (that binary also runs on SDK 14/15, where they do exist), so only those, plus operand-free leaves, go through aDefaultVisitoverride that confirms a candidate by name on the node's syntax, which restores the old behaviour inside those nodes and nowhere else. Diagnostics are reported in declaration order (IParameterSymbol.Ordinal).The other
OperationWalkersubclasses in the repository may have the same gap; the audit is tracked in #642.Base App scan
A throwaway text scan (not added to the repo) looked for non-local, non-trigger, non-subscriber, non-obsolete procedure parameters (outside objects with
implements) whose name occurs in the body only right after a., never on its own. It does not catch theSetRangefield-argument shape, so it is a lower bound.Base Application(w1-29.0.54011.55789): 8,135 .al files, 22,417 procedures, 33,954 parameters: 0 hits (163 parameters never mentioned at all, which the rule already reports).MSDyn365BC.Sandbox.Code.Historycheckout (all apps, 17,502 files, 65,521 parameters): 2 hits, 1 real:Subscription Billing Tests/Base/ContractTestLibrary.Codeunit.al,BillingTemplateWriteFilter, parameterFieldNo: the body only callsBillingTemplate.FieldNo(Filter). Hidden before, reported now.Withholding Tax/.../WithholdingTaxMgmt.Codeunit.al,WithholdingAmountJournal, parameterPost: a scan artifact (Postoccurs inside the quoted field name"Wthldg. Tax Bus. Post. Group"); the rule already reported this before the change.So the change goes in the expected direction (new reports only), with very low volume on Microsoft code.
Docs
No alcops.dev change needed: the LC0095 and LC0099 pages do not describe how references are detected.
Closes #449
this.<Global>/this.<DataItem>; bare names were safe. Fixed in #639GlobalVariable+IsSynthesized+ object gate already exclude a user-declaredRec🤖 Generated with Claude Code