1e41f4b71Sopenharmony_ci# ArkCompiler Subsystem Changelog 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci## cl.arkcompiler.1 Compilation Check Enhanced for ArkTS Sendable and Shared Syntax Rules 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci**Access Level** 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ciOther 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci**Reason for Change** 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ciA 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. 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci**Change Impact** 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ciThis change is a compatible change. 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ciBefore change: 19e41f4b71Sopenharmony_ci1. 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. 20e41f4b71Sopenharmony_ci2. 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. 21e41f4b71Sopenharmony_ci3. 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. 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ciAfter change: 24e41f4b71Sopenharmony_ci1. 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. 25e41f4b71Sopenharmony_ci2. 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. 26e41f4b71Sopenharmony_ci3. 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. 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ciExample scenarios: 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ciConstraints on export of the Shared Module 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ciScenario 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. 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ciBefore change: 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci```ts 38e41f4b71Sopenharmony_ci'use shared'; 39e41f4b71Sopenharmony_ciclass NonSendableClass {}; 40e41f4b71Sopenharmony_ciexport default NonSendableClass; // The program crashes during GC. 41e41f4b71Sopenharmony_ci``` 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ciAfter change: 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci```ts 46e41f4b71Sopenharmony_ci'use shared'; 47e41f4b71Sopenharmony_ciclass NonSendableClass {}; 48e41f4b71Sopenharmony_ciexport default NonSendableClass; // Compilation error. 49e41f4b71Sopenharmony_ci``` 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ciScenario 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. 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ciBefore change: 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci```ts 56e41f4b71Sopenharmony_ci'use shared'; 57e41f4b71Sopenharmony_ciclass NonSendableClass {}; 58e41f4b71Sopenharmony_ciexport type NonSendableAlias = NonSendableClass; 59e41f4b71Sopenharmony_ci``` 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ciAfter change: 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci```ts 64e41f4b71Sopenharmony_ci'use shared'; 65e41f4b71Sopenharmony_ciclass NonSendableClass {}; 66e41f4b71Sopenharmony_ciexport type NonSendableAlias = NonSendableClass; // Warning on the DevEco Studio editing page and compilation warning 67e41f4b71Sopenharmony_ci``` 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ciConstraints on Variables in the sendable Class 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ciScenario 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. 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ciBefore change: 74e41f4b71Sopenharmony_ci 75e41f4b71Sopenharmony_ci```ts 76e41f4b71Sopenharmony_ciimport { taskpool } from '@kit.ArkTS'; 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci@Sendable 79e41f4b71Sopenharmony_ciexport class SendableData {}; 80e41f4b71Sopenharmony_ci 81e41f4b71Sopenharmony_ci@Sendable 82e41f4b71Sopenharmony_ciclass SendableClass { 83e41f4b71Sopenharmony_ci handle():void { 84e41f4b71Sopenharmony_ci new SendableData(); // Runtime exception. 85e41f4b71Sopenharmony_ci } 86e41f4b71Sopenharmony_ci} 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ci@Concurrent 89e41f4b71Sopenharmony_ciasync function taskHandle(sendable: SendableClass) { 90e41f4b71Sopenharmony_ci sendable.handle(); 91e41f4b71Sopenharmony_ci} 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_citaskpool.execute(new taskpool.Task(taskHandle, new SendableClass())); 94e41f4b71Sopenharmony_ci``` 95e41f4b71Sopenharmony_ci 96e41f4b71Sopenharmony_ciAfter change: 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_ci```ts 99e41f4b71Sopenharmony_ciimport { taskpool } from '@kit.ArkTS'; 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci@Sendable 102e41f4b71Sopenharmony_ciexport class SendableData {}; 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ci@Sendable 105e41f4b71Sopenharmony_ciclass SendableClass { 106e41f4b71Sopenharmony_ci handle():void { 107e41f4b71Sopenharmony_ci new SendableData(); // Warning on the DevEco Studio editing page and compilation warning 108e41f4b71Sopenharmony_ci } 109e41f4b71Sopenharmony_ci} 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ci@Concurrent 112e41f4b71Sopenharmony_ciasync function taskHandle(sendable: SendableClass) { 113e41f4b71Sopenharmony_ci sendable.handle(); 114e41f4b71Sopenharmony_ci} 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_citaskpool.execute(new taskpool.Task(taskHandle, new SendableClass())); 117e41f4b71Sopenharmony_ci``` 118e41f4b71Sopenharmony_ci 119e41f4b71Sopenharmony_ci**Start API Level** 120e41f4b71Sopenharmony_ci 121e41f4b71Sopenharmony_ciAPI version 12 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci**Change Since** 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_ciOpenHarmony SDK 5.0.0.36 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ci**Key API/Component Changes** 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ciN/A 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci**Adaptation Guide** 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_ciYou are advised to fix new warnings based on the sendable and shared module specifications to prevent runtime exceptions. 134