fix(AC0032): detect this. self-access via the operation tree (#349)#353
Merged
Conversation
…349) fix(AC0032): detect self-access via `this` keyword and bare implicit self AC0032 (unused permissions) resolves table data access at the syntax level. It recognised variable receivers (`MyTable.Modify()`, `Rec.Modify()`) but missed two self-access forms, both of which made a table's self-permission appear unused and produced a false positive (issue #343): - `this.Modify()` — the AL `this` self-reference keyword (BC 2024 wave 2) - `Modify()` — bare implicit self Root cause: the `this` receiver matched neither the identifier fast path nor the `GetSymbolInfo` fallback, and the implicit-self branch checked `containingObject is IRecordTypeSymbol` — always false, since a table object's symbol is an `ITableTypeSymbol`, not a record. Changes: - Resolve any non-identifier receiver (the `this` self-reference and expression receivers) via the operation tree: `SemanticModel.GetOperation(receiver)?.Type`. In a table, `this` binds to the record; non-record objects (e.g. a codeunit, where `this` is the instance) yield a non-record type and are ignored. This mirrors AC0031 (`RequiredPermissionDetector`) and never references `ThisExpressionSyntax`, which is absent at the netstandard2.1 compile floor (AL 12.0.13). Because `IOperation`, `GetOperation` and `IOperation.Type` all exist at that floor, the fix needs no `#if` guard and works on AL 14.0+ across every TFM — not just the net8.0/net10.0 builds (AL 16.0+). - Resolve bare implicit self from the containing `ITableTypeSymbol`. - `TryGetPermissionForType` accepts either a record type (via `OriginalDefinition`) or a table type directly. Fixes #343 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Arthurvdv
added a commit
that referenced
this pull request
Jun 26, 2026
Replace the IInstanceReferenceOperation type check (guarded with #if !NETSTANDARD2_1) for detecting a this/self instance with EnumProvider.OperationKind.ThisReference (guarded != default). IInstanceReferenceOperation is absent from the netstandard2.1 compile floor (AL 12.0.13), so the #if guard silently dropped this. suppression on the netstandard2.1 binary that serves AL 14.0-15.2. The OperationKind enum is reachable via EnumProvider on every TFM and resolves to default on SDKs without the member (where no this code can exist), so the guard makes it a no-op there and exact elsewhere. Mirrors the AC0032 / PR #353 approach of resolving this via the operation tree instead of typed nodes. Rec/xRec are reserved AL keywords sharing one record type, so the name remains the only public discriminator between the current record and the xRec before-image (IsThis/HasImplicitWith live on the internal SynthesizedGlobalVariableSymbol). Adds EnumProvider.OperationKind.ThisReference; sorts the OperationKind and SymbolKind members alphabetically. Documents the operation-level this/self pattern in the analyzer-development and netstandard2.1 instruction files. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Arthurvdv
added a commit
that referenced
this pull request
Jun 26, 2026
…371) fix(PC0037): suppress same-field assignment in own validate trigger PC0037 raised a false positive when a field is assigned to the current record (Rec/self) inside that field's own OnValidate / OnBeforeValidate / OnAfterValidate trigger. Such by-design value transformation (default values, rounding) cannot use Validate() without recursion, so it must not be flagged (issue #357). Suppression is narrow: only the same field on the current record is exempted. Cross-field cascades, xRec, and other same-table record variables still fire. Covers tables, table extensions, pages and page extensions, and the Rec., bare implicit-with, and this. reference forms. Detection details: - Current record (IsCurrentRecordInstance): a this/self reference detected via instance.Kind == EnumProvider.OperationKind.ThisReference (guarded != default), or an instance symbol named Rec (covers explicit Rec. and a page's implicit-with bare reference). IInstanceReferenceOperation is NOT referenced: it is absent from the netstandard2.1 compile floor (AL 12.0.13), and using it would force an #if guard that silently drops this. suppression on the netstandard2.1 binary serving AL 14.0-15.2. The enum resolves to default on SDKs without the member, so the guard is a no-op there and exact elsewhere, on every TFM. Mirrors the AC0032 / PR #353 operation-tree approach. Rec/xRec are reserved AL keywords sharing one record type, so the name is the only public discriminator from the xRec before-image (IsThis/HasImplicitWith live on the internal SynthesizedGlobalVariableSymbol). - Owner field (ResolveTriggerOwnerField): from the trigger's containing symbol -- IFieldSymbol (table field), IControlSymbol.RelatedFieldSymbol (page control), or, for modify(...) before/after validate in extensions, the change-modify symbol's internal Target read via reflection, guarded by owner.Kind == SymbolKind.Change and resolved recursively. Adds EnumProvider.OperationKind.ThisReference and EnumProvider.SymbolKind .Change (members kept alphabetically sorted). Documents the operation-level this/self pattern in the analyzer-development and netstandard2.1 compat instruction files, and updates the PC0037 instruction file. Tests: 20 PC0037 cases (full PlatformCop suite green). The four extension fixtures are skipped below runtime 13.0 (extension target declared in the same module) and the this. fixture below 14.0 (the this keyword) via SkipTestIfVersionIsTooLow, matching AC0032 / DuplicateODataEntityName. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.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.
Detects
this.self-access (and bare implicit self) in AC0032 via the operation tree.Moved into
mainfromrelease/v1.0.0(commit739fff7, originally PR #349) so it lands without implying a v1.0.0 release. Independent of the other split PRs.Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com