1# ArkCompiler Subsystem Changelog 2 3## cl.arkcompiler.1 Compilation Check Enhanced for ArkTS Sendable and Shared Syntax Rules 4 5**Access Level** 6 7Other 8 9**Reason for Change** 10 11A sendable object must comply with the [usage rules](../../..//application-dev/arkts-utils/arkts-sendable.md#sendable-usage-rules), and a shared module must comply with the [specifications](../../..//application-dev/arkts-utils/arkts-sendable-module.md#specifications). In export scenarios where some constraints should be made, the compiler does not check for the restrictions. As a result, a runtime exception occurs, but no compilation error is reported. In this version update, a compile-time check is added for these constraints. You can find the code that fails to meet the sendable and shared module usage constraints earlier through compile-time errors or warnings, reducing fault locating costs at the runtime. 12 13**Change Impact** 14 15This change is a compatible change. 16 17 18Before change: 191. When the export default someVariable mode is used in the shared module to export a variable of the non-sendable type, an error message is displayed on the DevEco Studio editing page, but no compilation error is reported, and the program breaks down at the runtime. 202. When the export type someType = someNonSendableType mode is used in the shared module to export an alias of the non-sendable type, no error message is displayed on the DevEco Studio editing page, and no compilation exception is reported. 213. When the sendable class internally uses the sendable class object exported from the top level of the current module, no error message is displayed on the DevEco Studio editing page, no compilation exception is reported, but an exception occurs at the runtime. 22 23After change: 241. When the export default someVariable mode is used in the shared module to export a variable of the non-sendable type, an error message is displayed on the DevEco Studio editing page, and a compilation error is reported. 252. When the export type someType = someNonSendableType mode is used in the shared module to export an alias of the non-sendable type, a warning message is displayed on the DevEco Studio editing page, and a compilation warning is reported. 263. When the sendable class uses the sendable class object exported from the top level of the current module, a warning message is displayed on the DevEco Studio editing page, and a compilation warning is reported. 27 28 29Example scenarios: 30 31Constraints on export of the Shared Module 32 33Scenario 1: The export default someVariable mode is used in the shared module to export a variable of the non-sendable type. Impact: The change is a compatibility change. Before the change, the program crashes. After the change, a compilation error is reported. 34 35Before change: 36 37```ts 38'use shared'; 39class NonSendableClass {}; 40export default NonSendableClass; // The program crashes during GC. 41``` 42 43After change: 44 45```ts 46'use shared'; 47class NonSendableClass {}; 48export default NonSendableClass; // Compilation error. 49``` 50 51Scenario 2: The export type someType = someNonSendableType mode is used in the shared module to export an alias of the non-sendable type. Impact: The change is a compatibility change. Before the change, no message is displayed. After the change, a warning is displayed on the editing page, and a compilation warning is displayed. 52 53Before change: 54 55```ts 56'use shared'; 57class NonSendableClass {}; 58export type NonSendableAlias = NonSendableClass; 59``` 60 61After change: 62 63```ts 64'use shared'; 65class NonSendableClass {}; 66export type NonSendableAlias = NonSendableClass; // Warning on the DevEco Studio editing page and compilation warning 67``` 68 69Constraints on Variables in the sendable Class 70 71Scenario 1: The sendable class uses the sendable class object exported from the top level of the current module. Impact: The change is a compatibility change. Before the change, a runtime error is reported. After the change, a warning is displayed on the editing page, and a compilation warning is displayed. 72 73Before change: 74 75```ts 76import { taskpool } from '@kit.ArkTS'; 77 78@Sendable 79export class SendableData {}; 80 81@Sendable 82class SendableClass { 83 handle():void { 84 new SendableData(); // Runtime exception. 85 } 86} 87 88@Concurrent 89async function taskHandle(sendable: SendableClass) { 90 sendable.handle(); 91} 92 93taskpool.execute(new taskpool.Task(taskHandle, new SendableClass())); 94``` 95 96After change: 97 98```ts 99import { taskpool } from '@kit.ArkTS'; 100 101@Sendable 102export class SendableData {}; 103 104@Sendable 105class SendableClass { 106 handle():void { 107 new SendableData(); // Warning on the DevEco Studio editing page and compilation warning 108 } 109} 110 111@Concurrent 112async function taskHandle(sendable: SendableClass) { 113 sendable.handle(); 114} 115 116taskpool.execute(new taskpool.Task(taskHandle, new SendableClass())); 117``` 118 119**Start API Level** 120 121API version 12 122 123**Change Since** 124 125OpenHarmony SDK 5.0.0.36 126 127**Key API/Component Changes** 128 129N/A 130 131**Adaptation Guide** 132 133You are advised to fix new warnings based on the sendable and shared module specifications to prevent runtime exceptions. 134