List of [Codeunit X].Set(Index, NewValue, var OldValue) generates C# that does not compile (CS1503: NavCodeunit to NavCodeunitHandle)
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 55/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- backend-api-design
Hướng nghiên cứu
The payload names no repository source files or tests. Start by locating the compiler code that emits the three-argument List.Set call and compare it with the working Dictionary.Set and List.Get output shown in the issue. Confirm the generated call uses the expected NavCodeunitHandle and by-reference wrapper, then add a regression test covering both statement and used-value forms.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Please include the following with each issue:
1. Describe the bug
For a list of codeunits, the three-argument overload Set(Index, NewValue, var OldValue) is emitted with .Target (a NavCodeunit) for both the new value and the var old value, while the platform's ALSet expects a NavCodeunitHandle and a ByRef<NavCodeunitHandle>. The AL compiler reports no diagnostic; the server fails to compile the generated C# and refuses the whole object, so every call into the codeunit fails, not only the Set call. Both forms are affected: the statement (DataError.ThrowError) and the used value (ok := Items.Set(...), DataError.TrapError).
This looks like the same family as #6652 (NavCodeunit instead of NavCodeunitHandle, fixed in 2021 for codeunit return values), but for a different construct.
2. To Reproduce
Steps to reproduce the behavior:
- Create an app (
"runtime": "15.0") with the two codeunits below. - Publish it to a Business Central 29 sandbox.
- Run codeunit 50101 (e.g. add
&codeunit=50101to the web client URL). - Optionally, build with
alc /generatecode+and openbin/COD50101.csin the .app to see the generated C#.
codeunit 50100 "Repro Item"
{
}
codeunit 50101 "List Set Repro"
{
trigger OnRun()
var
Items: List of [Codeunit "Repro Item"];
NewItem: Codeunit "Repro Item";
OldItem: Codeunit "Repro Item";
begin
Items.Add(OldItem);
Items.Set(1, NewItem, OldItem);
end;
}
3. Expected behavior
The code compiles on the server and Set replaces the element, returning the previous one in OldItem. The compiler already emits the right shape for the neighbouring calls, which compile and work:
// Items.Set(1, NewItem); (two-argument overload)
this.items.ALSet(DataError.ThrowError, 1, this.newItem);
// ByKey.Set(1, NewItem, OldItem); (Dictionary of [Integer, Codeunit "Repro Item"])
this.byKey.ALSet(1, this.newItem, new ByRef<NavCodeunitHandle>(() => this.oldItem, setValue => this.oldItem.ALAssign(setValue)));
// Items.Get(1, OldItem);
this.items.ALGet(DataError.ThrowError, 1, new ByRef<NavCodeunitHandle>(() => this.oldItem, setValue => this.oldItem.ALAssign(setValue)));
So List.Set with an old value should be this.items.ALSet(DataError.ThrowError, 1, this.newItem, new ByRef<NavCodeunitHandle>(...)).
4. Actual behavior
Generated C# (from alc /generatecode+):
this.items.ALSet(DataError.ThrowError, 1, this.newItem.Target, this.oldItem.Target);
Error on the server when any method of the codeunit is first run (observed in our app, whose generated code has exactly this line; the repro above generates the same line):
System.InvalidOperationException: C# compilation has failed for the application object CodeUnit_50101.
... error CS1503: Argument 3: cannot convert from 'Microsoft.Dynamics.Nav.Runtime.NavCodeunit' to 'Microsoft.Dynamics.Nav.Runtime.NavCodeunitHandle'
... error CS1503: Argument 4: cannot convert from 'Microsoft.Dynamics.Nav.Runtime.NavCodeunit' to 'Microsoft.Dynamics.Nav.Runtime.ByRef<Microsoft.Dynamics.Nav.Runtime.NavCodeunitHandle>'
Workaround: read the old element with Get(Index) and call the two-argument Set(Index, NewValue).
5. Versions:
- AL Language: 18.1.2842859 (compiler
alc.exe18.1.43.24897) - Visual Studio Code: 1.142.0
- Business Central: online sandbox, version 29 (platform 29.0.57071.0)
- List of Visual Studio Code extensions that you have installed: not involved. The repro was built with the command-line compiler (
alc.exefrom the AL Language extension'sbinfolder), outside Visual Studio Code. - Operating System:
- Windows
- Linux
- MacOS
Final Checklist
Please remember to do the following:
-
Search the issue repository to ensure you are reporting a new issue
-
Reproduce the issue after disabling all extensions except the AL Language extension
-
Simplify your code around the issue to better isolate the problem
- Ngôn ngữ chính
- PowerShell
- Star
- 891
- Fork
- 287
- Merge trung bình
- 4 giờ 7 phút
- Pull request đã merge (30 ngày)
- 1
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/AL
-
accepted al-tools bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 43/100
-
al_writetranslation: where should the .xlf land when targetLanguage is not a plain culture code?Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 52/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 58/100
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 43/100
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
cunla/fakeredis-py#636 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
opensafely-core/job-server#6180 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug implicit-state
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 69/100
-
area:models enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày