1e41f4b71Sopenharmony_ci# ArkCompiler Subsystem Changelog 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci## cl.arkcompiler.1 Introduced New ArkTS Syntax Check Scenarios 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci**Access Level** 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ciOther 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci**Reason for Change** 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ciThe ArkTS syntax check tool is designed for syntax validation in the following scenarios: full build, incremental build, initial preview, and initial hot reload. Previously, during the preview and hot reload processes, when changes were made to the code and saved, triggering real-time previews and hot reloads, no ArkTS syntax check is performed. With this change, the ArkTS syntax check is introduced for these scenarios to ensure that the check result is the same as that in other scenarios. 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci**Change Impact** 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ciPrior to this change, in scenarios involving preview and hot reload, if code was modified incrementally and saved for another round of preview and hot reload, no ArkTS syntax check is performed. If the code introduces syntax errors according to ArkTS rules, the preview and hot reload processes will still proceed. However, with this change, introducing code that breaks ArkTS rules will interrupt the build process, thereby stopping real-time preview and hot reload. 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_ci**Start API Level** 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ciAPI version 10 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci**Change Since** 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ciOpenHarmony SDK 5.0.0.18 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci**Key API/Component Changes** 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ciN/A 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci**Adaptation Guide** 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ciNo adaptation is required for applications that can be fully compiled successfully. 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci## cl.arkcompiler.2 Compilation Check Standardized for ArkTS Sendable Syntax Rules 35e41f4b71Sopenharmony_ci 36e41f4b71Sopenharmony_ci**Access Level** 37e41f4b71Sopenharmony_ci 38e41f4b71Sopenharmony_ciOther 39e41f4b71Sopenharmony_ci 40e41f4b71Sopenharmony_ci**Reason for Change** 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ciIn API version 11, ArkTS introduces the concepts of the @Sendable decorator and Sendable class. However, some Sendable syntax constraints are not validated during compilation. In this change, compilation checks against these ArkTS Sendable syntax rules are added, providing clearer rules for you to use the ArkTS Sendable feature for development. 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci**Change Impact** 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ciThis change is an incompatible change. In this change, the following Sendable syntax rules are added. 47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci#### Rule 1: A Sendable class can inherit only from another Sendable class. 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ciThe rule scenario is optimized. When a Sendable class inherits from a variable (even if the variable is assigned a Sendable class), a compilation error is reported. 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci```ts 53e41f4b71Sopenharmony_ci@Sendable 54e41f4b71Sopenharmony_ciclass A {} // Sendable class 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_cilet a = A 57e41f4b71Sopenharmony_ci 58e41f4b71Sopenharmony_ci@Sendable 59e41f4b71Sopenharmony_ciclass B extends A {} 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_ci@Sendable 62e41f4b71Sopenharmony_ciclass C extends a {} // Compilation error: The Sendable class cannot inherit from a variable. 63e41f4b71Sopenharmony_ci``` 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ciAffected scenario: If the Sendable class inherits from a variable (even if the variable is assigned a Sendable class), the compilation fails after the change. This is an incompatible change. 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci--- 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ci#### Rule 2: A non-Sendable class can inherit only from another non-Sendable class. 70e41f4b71Sopenharmony_ci 71e41f4b71Sopenharmony_ciIf a non-Sendable class inherits from a Sendable class, a compilation error is reported. 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ci```ts 74e41f4b71Sopenharmony_ci@Sendable 75e41f4b71Sopenharmony_ciclass A {} 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_ciclass B extends A {} // Compilation error: A non-Sendable class cannot inherit from a Sendable class. 78e41f4b71Sopenharmony_ci``` 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ciAffected scenario: If a non-Sendable class inherits from a Sendable class, the compilation fails after the change. This is an incompatible change. 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci--- 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ci#### Rule 3: The template type of a Sendable class, collections.Array, collections.Map, and collections.Set in the generic class must be Sendable. 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ciDuring compilation, there is no longer any check or interception for the use of the template type by the Sendable class property, meaning that the Sendable class property can use the template type. The type of the generic class is checked during instantiation. If the template type of the Sendable class in the generic class is non-Sendable, an error is reported during compilation. 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ci```ts 89e41f4b71Sopenharmony_ci@Sendable 90e41f4b71Sopenharmony_ciclass B {} // Sendable class 91e41f4b71Sopenharmony_ci 92e41f4b71Sopenharmony_ci@Sendable 93e41f4b71Sopenharmony_ciclass C<T> { 94e41f4b71Sopenharmony_ci v: T; // Allow the Sendable class property to use the template type. No compilation error is reported. 95e41f4b71Sopenharmony_ci constructor(v: T) { 96e41f4b71Sopenharmony_ci this.v = v; 97e41f4b71Sopenharmony_ci } 98e41f4b71Sopenharmony_ci} 99e41f4b71Sopenharmony_ci 100e41f4b71Sopenharmony_cilet c = new C<B>(); 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_cifunction foo(a: C<B>) {} 103e41f4b71Sopenharmony_ci``` 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ci```ts 106e41f4b71Sopenharmony_ciclass B {} // Non-sendable class 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_ci@Sendable 109e41f4b71Sopenharmony_ciclass C<T> {} 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_cilet c = new C<B>(); // Compilation error: The template type of the Sendable class in the generic class cannot be non-Sendable. 112e41f4b71Sopenharmony_ci``` 113e41f4b71Sopenharmony_ci 114e41f4b71Sopenharmony_ciAffected scenarios: 1. If the Sendable class property uses the template type, no compilation error is reported. 2. If the template type of the Sendable class in the generic class is non-Sendable, the compilation fails. This is an incompatible change. 115e41f4b71Sopenharmony_ci 116e41f4b71Sopenharmony_ci--- 117e41f4b71Sopenharmony_ci 118e41f4b71Sopenharmony_ci#### Rule 4: Do not use other decorators (class, property, method, or parameter decorators) for the Sendable class. 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_ciWhen the Sendable class uses other decorators, a compilation error is reported. 121e41f4b71Sopenharmony_ci 122e41f4b71Sopenharmony_ci```ts 123e41f4b71Sopenharmony_ci// a.ts 124e41f4b71Sopenharmony_ciexport function foo(a: Function) { 125e41f4b71Sopenharmony_ci a.prototype = String 126e41f4b71Sopenharmony_ci} 127e41f4b71Sopenharmony_ci 128e41f4b71Sopenharmony_ci// b.ets 129e41f4b71Sopenharmony_ciimport { foo } from 'a' 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci@foo 132e41f4b71Sopenharmony_ci@Sendable 133e41f4b71Sopenharmony_ciclass A {} // Compilation error: A Sendable class cannot use other decorators. 134e41f4b71Sopenharmony_ci``` 135e41f4b71Sopenharmony_ci 136e41f4b71Sopenharmony_ciAffected scenario: If the Sendable class uses other decorators, the compilation fails after the change. This is an incompatible change. 137e41f4b71Sopenharmony_ci 138e41f4b71Sopenharmony_ci--- 139e41f4b71Sopenharmony_ci 140e41f4b71Sopenharmony_ci#### Rule 5: The Sendable type cannot be initialized using an object literal or array literal. 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_ciWhen an object literal or array literal is used to initialize the Sendable type, a compilation error is reported. 143e41f4b71Sopenharmony_ci 144e41f4b71Sopenharmony_ci```ts 145e41f4b71Sopenharmony_ci@Sendable 146e41f4b71Sopenharmony_ciclass C {} 147e41f4b71Sopenharmony_ci 148e41f4b71Sopenharmony_cilet c: C = {}; // Compilation error: Do not use object literals or array literals to initialize the Sendable type. 149e41f4b71Sopenharmony_ci``` 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ciAffected scenario: When an object literal or array literal is used to initialize a variable of the Sendable type, the compilation fails. 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_ci--- 154e41f4b71Sopenharmony_ci 155e41f4b71Sopenharmony_ci#### Rule 6: Do not use as to forcibly convert the non-Sendable type to the Sendable type. 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ciWhen **as** is used to forcibly convert the non-Sendable type to the Sendable type, a compilation error is reported. 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ci```ts 160e41f4b71Sopenharmony_ciclass A {} 161e41f4b71Sopenharmony_ci 162e41f4b71Sopenharmony_ci@Sendable 163e41f4b71Sopenharmony_ciclass B {} 164e41f4b71Sopenharmony_ci 165e41f4b71Sopenharmony_cifunction foo(a: A) { 166e41f4b71Sopenharmony_ci a as B; // Compilation error: Do not use as to forcibly convert the non-Sendable type to the Sendable type. 167e41f4b71Sopenharmony_ci} 168e41f4b71Sopenharmony_ci``` 169e41f4b71Sopenharmony_ci 170e41f4b71Sopenharmony_ciAffected scenario: A non-Sendable variable after forcible conversion cannot be compiled. 171e41f4b71Sopenharmony_ci 172e41f4b71Sopenharmony_ci--- 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ci 175e41f4b71Sopenharmony_ci**Start API Level** 176e41f4b71Sopenharmony_ci 177e41f4b71Sopenharmony_ciAPI version 10 178e41f4b71Sopenharmony_ci 179e41f4b71Sopenharmony_ci**Change Since** 180e41f4b71Sopenharmony_ci 181e41f4b71Sopenharmony_ciOpenHarmony SDK 5.0.0.18 182e41f4b71Sopenharmony_ci 183e41f4b71Sopenharmony_ci**Key API/Component Changes** 184e41f4b71Sopenharmony_ci 185e41f4b71Sopenharmony_ciN/A 186e41f4b71Sopenharmony_ci 187e41f4b71Sopenharmony_ci**Adaptation Guide** 188e41f4b71Sopenharmony_ci 189e41f4b71Sopenharmony_ciMake adaptations in your ArkTS code involved in the preceding scenarios according to the specifications. 190