Add testcases for sendable rules

Issue: https://gitee.com/openharmony/third_party_typescript/issues/IAK1BE

Change-Id: Iec8012265afd85f26b77d6b4094ff92a666a822a
Signed-off-by: lizhonghan <lizhonghan1@huawei.com>
This commit is contained in:
lizhonghan 2024-08-14 16:22:48 +08:00
parent da083844c0
commit b438ca5e65
53 changed files with 2318 additions and 1 deletions

View File

@ -24,7 +24,8 @@
"testcase/arkts-sendable-as-expr/arkts-sendable-as-expr-ts/@arkts.lang.d.ets",
"testcase/arkts-sendable-generic-types/@arkts.lang.d.ets",
"testcase/arkts-sendable-obj-init/@arkts.lang.d.ets",
"testcase/arkts-no-structural-typing/@arkts.lang.d.ets"],
"testcase/arkts-no-structural-typing/@arkts.lang.d.ets",
"testcase/common-lib/@arkts.lang.d.ets"],
"beta2":["testcase/arkts-sendable-beta-compatible/arkts-sendable-beta-compatible-1-errorr.ets",
"testcase/arkts-sendable-beta-compatible/arkts-sendable-beta-compatible-2-ok.ets"],
"beta3":["testcase/arkts-sendable-closure-export/arkts-sendable-closure-export-1-error.ets",

View File

@ -0,0 +1,55 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class NonSendableClass { public a = '' }
class NonSendableClass2 { public b = '' }
@Sendable
class SendableClass { public a: string = '' }
@Sendable
class SendableClass2 { public b: string = '' }
interface IStruct1 { a: '' }
interface IStruct2 { b: '' }
type alis1 = SendableClass
type alis2 = SendableClass2
/*
* 1. `NonSendable` can be converted to `NonSendable`.
* 2. `NonSendable` can be converted to a union type that includes `Sendable`.
* 3. `Sendable` has no conversion restrictions.
* 4. Union types that include `null` or `undefined` can be considered as the type without them.
* 5. Union with system types (e.g., `number`, `string`) have special behavior.
*/
/* // cmp `let struct2 = new NonSendableClass() as IStruct1;` */
/* // cmp `let struct3 = new NonSendableClass() as IStruct1 | SendableClass;` */
/* // cmp `let struct4 = new NonSendableClass() as SendableClass | IStruct1;` */
/* // cmp `let struct5 = new NonSendableClass() as SendableClass | boolean;` */
let struct6 = new NonSendableClass() as SendableClass | null; // ERROR
let struct7 = new NonSendableClass() as SendableClass | undefined; // ERROR
let struct8 = new NonSendableClass() as SendableClass | alis1; // ERROR
/* // cmp `let struct9 = new NonSendableClass() as SendableClass | alis2;` */
let struct10 = new NonSendableClass() as SendableClass; // ERROR
/* // cmp `let struct11 = new NonSendableClass() as IStruct1;` */
let struct12 = new NonSendableClass() as undefined; // TSC
let noStruct1 = new NonSendableClass2() as IStruct1; // TSC
let noStruct2 = new NonSendableClass2() as SendableClass | IStruct1; // TSC
let noStruct3 = new NonSendableClass2() as SendableClass | null; // ERROR
let noStruct4 = new NonSendableClass2() as SendableClass | undefined; // ERROR
let noStruct5 = new NonSendableClass2() as SendableClass | boolean; // TSC
let noStruct6 = new NonSendableClass2() as SendableClass; // ERROR
let noStruct7 = new NonSendableClass2() as boolean; // TSC
let noStruct8 = new NonSendableClass2() as SendableClass | number; // TSC

View File

@ -0,0 +1,139 @@
{
"arktsVersion_1_0": [
{
"messageText": "Conversion of type 'NonSendableClass' to type 'undefined' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.",
"expectLineAndCharacter": {
"line": 45,
"character": 16
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 19,
"character": 1
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 21,
"character": 1
}
},
{
"messageText": "Structural typing is not supported (arkts-no-structural-typing)",
"expectLineAndCharacter": {
"line": 39,
"character": 15
}
},
{
"messageText": "Structural typing is not supported (arkts-no-structural-typing)",
"expectLineAndCharacter": {
"line": 40,
"character": 15
}
},
{
"messageText": "Structural typing is not supported (arkts-no-structural-typing)",
"expectLineAndCharacter": {
"line": 41,
"character": 15
}
},
{
"messageText": "Structural typing is not supported (arkts-no-structural-typing)",
"expectLineAndCharacter": {
"line": 43,
"character": 16
}
},
{
"messageText": "Structural typing is not supported (arkts-no-structural-typing)",
"expectLineAndCharacter": {
"line": 48,
"character": 17
}
},
{
"messageText": "Structural typing is not supported (arkts-no-structural-typing)",
"expectLineAndCharacter": {
"line": 50,
"character": 17
}
},
{
"messageText": "Structural typing is not supported (arkts-no-structural-typing)",
"expectLineAndCharacter": {
"line": 51,
"character": 17
}
},
{
"messageText": "Structural typing is not supported (arkts-no-structural-typing)",
"expectLineAndCharacter": {
"line": 53,
"character": 17
}
}
],
"arktsVersion_1_1": [
{
"messageText": "Conversion of type 'NonSendableClass' to type 'undefined' may be a mistake because neither type sufficiently overlaps with the other. If this was intentional, convert the expression to 'unknown' first.",
"expectLineAndCharacter": {
"line": 45,
"character": 16
}
},
{
"messageText": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)",
"expectLineAndCharacter": {
"line": 39,
"character": 15
}
},
{
"messageText": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)",
"expectLineAndCharacter": {
"line": 40,
"character": 15
}
},
{
"messageText": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)",
"expectLineAndCharacter": {
"line": 41,
"character": 15
}
},
{
"messageText": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)",
"expectLineAndCharacter": {
"line": 43,
"character": 16
}
},
{
"messageText": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)",
"expectLineAndCharacter": {
"line": 50,
"character": 17
}
},
{
"messageText": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)",
"expectLineAndCharacter": {
"line": 51,
"character": 17
}
},
{
"messageText": "Casting \"Non-sendable\" data to \"Sendable\" type is not allowed (arkts-sendable-as-expr)",
"expectLineAndCharacter": {
"line": 53,
"character": 17
}
}
]
}

View File

@ -0,0 +1,55 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class NonSendableClass { public a = '' }
class NonSendableClass2 { public b = '' }
@Sendable
class SendableClass { public a: string = '' }
@Sendable
class SendableClass2 { public b: string = '' }
interface IStruct1 { a: '' }
interface IStruct2 { b: '' }
type alis1 = SendableClass
type alis2 = SendableClass2
/*
* 1. `NonSendable` can be converted to `NonSendable`.
* 2. `NonSendable` can be converted to a union type that includes `Sendable`.
* 3. `Sendable` has no conversion restrictions.
* 4. Union types that include `null` or `undefined` can be considered as the type without them.
* 5. Union with system types (e.g., `number`, `string`) have special behavior.
*/
let struct2 = new NonSendableClass() as IStruct1;
let struct3 = new NonSendableClass() as IStruct1 | SendableClass;
let struct4 = new NonSendableClass() as SendableClass | IStruct1;
let struct5 = new NonSendableClass() as SendableClass | boolean;
/* // cmp `let struct6 = new NonSendableClass() as SendableClass | null; // ERROR` */
/* // cmp `let struct7= new NonSendableClass() as SendableClass | undefined; // ERROR` */
/* // cmp `let struct8 = new NonSendableClass() as SendableClass | alis1; // ERROR` */
let struct9 = new NonSendableClass() as SendableClass | alis2;
/* // cmp `let struct10 = new NonSendableClass() as SendableClass; // ERROR` */
let struct11 = new NonSendableClass() as IStruct1;
/* // cmp `let struct12 = new NonSendableClass() as undefined; // TSC` */
/* // cmp `let noStruct1 = new NonSendableClass2() as IStruct1; // TSC` */
/* // cmp `let noStruct2 = new NonSendableClass2() as SendableClass | IStruct1; // TSC` */
/* // cmp `let noStruct3 = new NonSendableClass2() as SendableClass | null; // ERROR` */
/* // cmp `let noStruct4 = new NonSendableClass2() as SendableClass | undefined; // ERROR` */
/* // cmp `let noStruct5 = new NonSendableClass2() as SendableClass | boolean; // TSC` */
/* // cmp `let noStruct6 = new NonSendableClass2() as SendableClass; // ERROR` */
/* // cmp `let noStruct7 = new NonSendableClass2() as boolean; // TSC` */
/* // cmp `let noStruct8 = new NonSendableClass2() as SendableClass | number; // TSC` */

View File

@ -0,0 +1,33 @@
{
"arktsVersion_1_0": [
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 19,
"character": 1
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 21,
"character": 1
}
},
{
"messageText": "Structural typing is not supported (arkts-no-structural-typing)",
"expectLineAndCharacter": {
"line": 35,
"character": 15
}
},
{
"messageText": "Structural typing is not supported (arkts-no-structural-typing)",
"expectLineAndCharacter": {
"line": 44,
"character": 16
}
}
],
"arktsVersion_1_1": []
}

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class NonSendableClass { public a = '' }
class NonSendableClass2 { public b = '' }
@Sendable
class SendableClass { public a: string = '' }
@Sendable
class SendableClass2 { public b: string = '' }
interface IStruct1 { a: '' }
interface IStruct2 { b: '' }
type alis1 = SendableClass
type alis2 = SendableClass2
/*
* 1. `any` type can be converted to `Sendable`.
*/
let objectAnyType = Object() as SendableClass
let objectAnyType2 = 1 as ESObject as SendableClass
let objectAnyType3 = JSON.parse('') as SendableClass

View File

@ -0,0 +1,34 @@
{
"arktsVersion_1_0": [
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 19,
"character": 1
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 21,
"character": 1
}
},
{
"messageText": "Usage of \"ESObject\" type is restricted (arkts-limited-esobj)",
"expectLineAndCharacter": {
"line": 33,
"character": 27
}
}
],
"arktsVersion_1_1": [
{
"messageText": "Usage of 'ESObject' type is restricted (arkts-limited-esobj)",
"expectLineAndCharacter": {
"line": 33,
"character": 27
}
}
]
}

View File

@ -0,0 +1,43 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { NonSendable, SomeDecorator, SomeDecorator2 } from './arkts-sendable-class-decorator-lib-dependencie'
@NonSendable // should report, arkts-sendable-class-decorator
@Sendable
class SendableClass {
// should report, arkts-sendable-class-decorator
@SomeDecorator
public prop: string = '';
constructor() {}
// should report, arkts-sendable-class-decorator
@SomeDecorator
myMethod1() {}
// should report, arkts-sendable-class-decorator
myMethod2(@SomeDecorator2 param: string) {}
// should report, arkts-sendable-class-decorator
@SomeDecorator
get myPropertyGet(): string {
return this.prop;
}
// should report, arkts-sendable-class-decorator
@SomeDecorator
set myProperty2Set(value: string) {
this.prop = value;
}
}

View File

@ -0,0 +1,97 @@
{
"arktsVersion_1_0": [
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 19,
"character": 1
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 20,
"character": 1
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 23,
"character": 3
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 28,
"character": 3
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 32,
"character": 13
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 34,
"character": 3
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 39,
"character": 3
}
}
],
"arktsVersion_1_1": [
{
"messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)",
"expectLineAndCharacter": {
"line": 19,
"character": 1
}
},
{
"messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)",
"expectLineAndCharacter": {
"line": 23,
"character": 3
}
},
{
"messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)",
"expectLineAndCharacter": {
"line": 28,
"character": 3
}
},
{
"messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)",
"expectLineAndCharacter": {
"line": 32,
"character": 13
}
},
{
"messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)",
"expectLineAndCharacter": {
"line": 34,
"character": 3
}
},
{
"messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)",
"expectLineAndCharacter": {
"line": 39,
"character": 3
}
}
]
}

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@Sendable // OK
class SendableClass {
public prop: string = ''; // OK
constructor() {} // OK
myMethod1() {} // OK
myMethod2(param: string) {} // OK
get myProperty(): string { // OK
return this.prop;
}
set myProperty(value: string) { // OK
this.prop = value;
}
}

View File

@ -0,0 +1,12 @@
{
"arktsVersion_1_0": [
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 17,
"character": 1
}
}
],
"arktsVersion_1_1": []
}

View File

@ -0,0 +1,43 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { NonSendable, SomeDecorator, SomeDecorator2 } from './arkts-sendable-class-decorator-lib-dependencie'
@NonSendable // should report, arkts-sendable-class-decorator
@Sendable
class SendableClass {
// should report, arkts-sendable-class-decorator
@SomeDecorator
public prop: string = '';
constructor() {}
// should report, arkts-sendable-class-decorator
@SomeDecorator
myMethod1() {}
// should report, arkts-sendable-class-decorator
myMethod2(@SomeDecorator2 param: string) {}
// should report, arkts-sendable-class-decorator
@SomeDecorator
get myPropertyGet(): string {
return this.prop;
}
// should report, arkts-sendable-class-decorator
@SomeDecorator
set myProperty2Set(value: string) {
this.prop = value;
}
}

View File

@ -0,0 +1,97 @@
{
"arktsVersion_1_0": [
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 19,
"character": 1
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 20,
"character": 1
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 23,
"character": 3
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 28,
"character": 3
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 32,
"character": 13
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 34,
"character": 3
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 39,
"character": 3
}
}
],
"arktsVersion_1_1": [
{
"messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)",
"expectLineAndCharacter": {
"line": 19,
"character": 1
}
},
{
"messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)",
"expectLineAndCharacter": {
"line": 23,
"character": 3
}
},
{
"messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)",
"expectLineAndCharacter": {
"line": 28,
"character": 3
}
},
{
"messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)",
"expectLineAndCharacter": {
"line": 32,
"character": 13
}
},
{
"messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)",
"expectLineAndCharacter": {
"line": 34,
"character": 3
}
},
{
"messageText": "Only \"@Sendable\" decorator can be used on \"Sendable\" class (arkts-sendable-class-decorator)",
"expectLineAndCharacter": {
"line": 39,
"character": 3
}
}
]
}

View File

@ -0,0 +1,24 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
declare type ClassDecorator = <TFunction extends Function>(target: TFunction) => TFunction | void;
// should report, arkts-no-symbol
declare type PropertyDecorator = (target: Object, propertyKey: string | symbol) => void;
// should report, arkts-no-symbol
declare type ParameterDecorator = (target: Object, propertyKey: string | symbol, parameterIndex: number) => void;
export declare const SomeDecorator: PropertyDecorator;
export declare const SomeDecorator2: ParameterDecorator;
export declare const NonSendable: ClassDecorator;

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { lang } from '../common-lib/@arkts.lang';
interface BaseNonSendableInterface {}
interface ISendableExtend1 extends lang.ISendable {} // normal interface can extends ISendable
interface ISendableExtend2 extends lang.ISendable {
p: string
}
/*
* NonSendable class cannot implements ISendable interface
*/
class NonSendableClass1 implements lang.ISendable {} // ERROR, arkts-sendable-class-inheritance
class NonSendableClass2 implements ISendableExtend1 {} // ERROR, arkts-sendable-class-inheritance
class NonSendableClass3 implements ISendableExtend2 { // ERROR, arkts-sendable-class-inheritance
public p = ''
}

View File

@ -0,0 +1,4 @@
{
"arktsVersion_1_0": [],
"arktsVersion_1_1": []
}

View File

@ -0,0 +1,45 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { lang } from '../common-lib/@arkts.lang';
@Sendable
class BaseSendableClass {}
class BaseNonSendableClass {}
interface BaseNonSendableInterface {}
interface ISendableExtend1 extends lang.ISendable {} // normal interface can extends ISendable
interface ISendableExtend2 extends lang.ISendable {
p: string
}
interface INonSendable {}
/*
* NonSendable class can implements only NonSendable interface
*/
class SendableClass0 implements BaseNonSendableInterface {}
/*
* Sendable class can implements any interface
*/
@Sendable
class SendableClass1 implements lang.ISendable {}
@Sendable
class SendableClass2 implements ISendableExtend1 {}
@Sendable
class SendableClass3 implements ISendableExtend2 {
public p = ''
}

View File

@ -0,0 +1,41 @@
{
"arktsVersion_1_0": [
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 19,
"character": 1
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 38,
"character": 1
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 40,
"character": 1
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 42,
"character": 1
}
}
],
"arktsVersion_1_1": [
{
"messageText": "Field in sendable class must have type annotation (arkts-sendable-explicit-field-type)",
"expectLineAndCharacter": {
"line": 44,
"character": 3
}
}
]
}

View File

@ -0,0 +1,41 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { lang } from '../common-lib/@arkts.lang';
@Sendable
class BaseSendableClass {}
class BaseNonSendableClass {}
interface ISendableExtend extends lang.ISendable {}
interface INonSendable {}
@Sendable
class BaseSendableClass2 implements lang.ISendable {}
/*
* Sendable and NonSendable class cannot extends from each other
*/
@Sendable
class SendableClass1 extends BaseNonSendableClass {} // ERROR, arkts-sendable-class-inheritance
class NonSendableClass1 extends BaseSendableClass {} // ERROR, arkts-sendable-class-inheritance
class NonSendableClass2 extends BaseSendableClass2 {} // ERROR, arkts-sendable-class-inheritance
// ERROR, arkts-sendable-class-inheritance
class BaseSendableClass4 extends BaseSendableClass implements lang.ISendable {}
// ERROR, arkts-sendable-class-inheritance
class BaseSendableClass5 extends BaseSendableClass implements ISendableExtend {}

View File

@ -0,0 +1,62 @@
{
"arktsVersion_1_0": [
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 19,
"character": 1
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 24,
"character": 1
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 30,
"character": 1
}
}
],
"arktsVersion_1_1": [
{
"messageText": "The inheritance for \"Sendable\" classes is limited (arkts-sendable-class-inheritance)",
"expectLineAndCharacter": {
"line": 31,
"character": 30
}
},
{
"messageText": "The inheritance for \"Sendable\" classes is limited (arkts-sendable-class-inheritance)",
"expectLineAndCharacter": {
"line": 32,
"character": 33
}
},
{
"messageText": "The inheritance for \"Sendable\" classes is limited (arkts-sendable-class-inheritance)",
"expectLineAndCharacter": {
"line": 36,
"character": 33
}
},
{
"messageText": "The inheritance for \"Sendable\" classes is limited (arkts-sendable-class-inheritance)",
"expectLineAndCharacter": {
"line": 38,
"character": 34
}
},
{
"messageText": "The inheritance for \"Sendable\" classes is limited (arkts-sendable-class-inheritance)",
"expectLineAndCharacter": {
"line": 40,
"character": 34
}
}
]
}

View File

@ -0,0 +1,42 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { lang } from '../common-lib/@arkts.lang';
@Sendable
class BaseSendableClass {}
class BaseNonSendableClass {}
@Sendable
class BaseSendableClass2 implements lang.ISendable {}
interface ISendableExtend extends lang.ISendable {}
interface INonSendable {}
/*
* Sendable class can extend only Sendable class
*/
@Sendable
class SendableClass1 extends BaseSendableClass {} // OK
/*
* Sendable class can implements any interface(plus version)
*/
@Sendable
class SendableClass4 extends BaseSendableClass implements INonSendable {}
@Sendable
class SendableClass5 implements INonSendable {}
@Sendable
class SendableClass6 extends BaseSendableClass implements lang.ISendable {}

View File

@ -0,0 +1,47 @@
{
"arktsVersion_1_0": [
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 19,
"character": 1
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 22,
"character": 1
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 30,
"character": 1
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 37,
"character": 1
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 39,
"character": 1
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 41,
"character": 1
}
}
],
"arktsVersion_1_1": []
}

View File

@ -0,0 +1,27 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { lang } from '../common-lib/@arkts.lang';
@Sendable
class SendableClass1 {
public [1]: string = '';
public ['2']: string = '';
public ['abc']: string = '';
}
let a = new SendableClass1();
a.abc = '123'

View File

@ -0,0 +1,55 @@
{
"arktsVersion_1_0": [
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 19,
"character": 1
}
},
{
"messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)",
"expectLineAndCharacter": {
"line": 21,
"character": 10
}
},
{
"messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)",
"expectLineAndCharacter": {
"line": 22,
"character": 10
}
},
{
"messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)",
"expectLineAndCharacter": {
"line": 23,
"character": 10
}
}
],
"arktsVersion_1_1": [
{
"messageText": "Computed property names are not allowed in \"Sendable\" classes and interfaces (arkts-sendable-computed-prop-name)",
"expectLineAndCharacter": {
"line": 21,
"character": 10
}
},
{
"messageText": "Computed property names are not allowed in \"Sendable\" classes and interfaces (arkts-sendable-computed-prop-name)",
"expectLineAndCharacter": {
"line": 22,
"character": 10
}
},
{
"messageText": "Computed property names are not allowed in \"Sendable\" classes and interfaces (arkts-sendable-computed-prop-name)",
"expectLineAndCharacter": {
"line": 23,
"character": 10
}
}
]
}

View File

@ -0,0 +1,38 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@Sendable
class SendableClass1 {
public '1': string = '';
public '2': string = '';
public 'abc': string = '';
}
let a1 = new SendableClass1();
a1.abc = '123'
class NonSendableClass1 {
// public [1]: string,
public ['2']: string = '';
public ['abc']: string = '';
}
let a2 = new NonSendableClass1();
a2.abc = '123'
function f1(i: SendableClass1) {}
f1(new SendableClass1())

View File

@ -0,0 +1,47 @@
{
"arktsVersion_1_0": [
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 17,
"character": 1
}
},
{
"messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)",
"expectLineAndCharacter": {
"line": 19,
"character": 3
}
},
{
"messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)",
"expectLineAndCharacter": {
"line": 20,
"character": 3
}
},
{
"messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)",
"expectLineAndCharacter": {
"line": 21,
"character": 3
}
},
{
"messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)",
"expectLineAndCharacter": {
"line": 29,
"character": 10
}
},
{
"messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)",
"expectLineAndCharacter": {
"line": 30,
"character": 10
}
}
],
"arktsVersion_1_1": []
}

View File

@ -0,0 +1,30 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { lang } from '../common-lib/@arkts.lang';
interface ISendableExtend1 extends lang.ISendable {
[1]: string,
['2']: string,
['abc']: string,
}
@Sendable
class ISendableClass implements lang.ISendable {
public [1]: string = '';
public ['2']: string = '';
public ['abc']: string = '';
}

View File

@ -0,0 +1,83 @@
{
"arktsVersion_1_0": [
{
"messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)",
"expectLineAndCharacter": {
"line": 20,
"character": 3
}
},
{
"messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)",
"expectLineAndCharacter": {
"line": 21,
"character": 3
}
},
{
"messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)",
"expectLineAndCharacter": {
"line": 22,
"character": 3
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 25,
"character": 1
}
},
{
"messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)",
"expectLineAndCharacter": {
"line": 27,
"character": 10
}
},
{
"messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)",
"expectLineAndCharacter": {
"line": 28,
"character": 10
}
},
{
"messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)",
"expectLineAndCharacter": {
"line": 29,
"character": 10
}
}
],
"arktsVersion_1_1": [
{
"messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)",
"expectLineAndCharacter": {
"line": 20,
"character": 3
}
},
{
"messageText": "Computed property names are not allowed in \"Sendable\" classes and interfaces (arkts-sendable-computed-prop-name)",
"expectLineAndCharacter": {
"line": 27,
"character": 10
}
},
{
"messageText": "Computed property names are not allowed in \"Sendable\" classes and interfaces (arkts-sendable-computed-prop-name)",
"expectLineAndCharacter": {
"line": 28,
"character": 10
}
},
{
"messageText": "Computed property names are not allowed in \"Sendable\" classes and interfaces (arkts-sendable-computed-prop-name)",
"expectLineAndCharacter": {
"line": 29,
"character": 10
}
}
]
}

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { lang } from '../common-lib/@arkts.lang';
interface INonSendableExtend1 {
['1']: string,
['2']: string,
['abc']: string,
}
@Sendable
class ISendableClass implements lang.ISendable {
public '1': string;
public '2': string;
public 'abc': string;
}
function f1(i: ISendableClass) {}
f1(new ISendableClass())

View File

@ -0,0 +1,54 @@
{
"arktsVersion_1_0": [
{
"messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)",
"expectLineAndCharacter": {
"line": 20,
"character": 3
}
},
{
"messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)",
"expectLineAndCharacter": {
"line": 21,
"character": 3
}
},
{
"messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)",
"expectLineAndCharacter": {
"line": 22,
"character": 3
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 25,
"character": 1
}
},
{
"messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)",
"expectLineAndCharacter": {
"line": 27,
"character": 3
}
},
{
"messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)",
"expectLineAndCharacter": {
"line": 28,
"character": 3
}
},
{
"messageText": "Objects with property names that are not identifiers are not supported (arkts-identifiers-as-prop-names)",
"expectLineAndCharacter": {
"line": 29,
"character": 3
}
}
],
"arktsVersion_1_1": []
}

View File

@ -0,0 +1,23 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@Sendable
class SendableClass1 {
public prop1!: string; // should report, arkts-sendable-definite-assignment
constructor() {
this.prop1 = ''
}
}

View File

@ -0,0 +1,27 @@
{
"arktsVersion_1_0": [
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 17,
"character": 1
}
},
{
"messageText": "Definite assignment assertions are not supported (arkts-no-definite-assignment)",
"expectLineAndCharacter": {
"line": 19,
"character": 3
}
}
],
"arktsVersion_1_1": [
{
"messageText": "Definite assignment assertion is not allowed in \"Sendable\" classes (arkts-sendable-definite-assignment)",
"expectLineAndCharacter": {
"line": 19,
"character": 10
}
}
]
}

View File

@ -0,0 +1,32 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@Sendable
class SendableClass1 {
public prop1: string; // OK
public prop2?: string;
public readonly prop3: string;
constructor() {
this.prop1 = ''
this.prop2 = ''
this.prop3 = ''
this.prop3 = ''!
}
}
let sendableClassImpl1 = new SendableClass1();
sendableClassImpl1.prop1!;
sendableClassImpl1.prop2!?.toString();

View File

@ -0,0 +1,12 @@
{
"arktsVersion_1_0": [
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 17,
"character": 1
}
}
],
"arktsVersion_1_1": []
}

View File

@ -0,0 +1,48 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@Sendable
class SendableClassT<T> {
public var1: number = 1;
public var2: string = '1';
}
@Sendable
class SendableClass1 {
public var1: number = 1;
public var2: string = '1';
}
@Sendable
class SendableClass2 {
public var1: number = 1;
public var2: string = '1';
}
class NonSendableClass1 {}
class NonSendableClass2 { public p1 = 1 }
/*
* 1. The generic parameter of `SendableClass` must be of a `Sendable` type.
* 2. If the parameter is a union, each type in the union must be a `Sendable` type.
*/
let A1: SendableClassT<SendableClass1 | NonSendableClass1> = new SendableClassT<SendableClass1 | NonSendableClass1>();
let A2: SendableClassT<SendableClass1 | NonSendableClass1> = new SendableClassT<SendableClass1>();
let A3: SendableClassT<SendableClass1 | NonSendableClass1> = new SendableClassT<NonSendableClass1>();
let A4: SendableClassT<NonSendableClass1 | NonSendableClass2> =
new SendableClassT<NonSendableClass1 | NonSendableClass2>();
let A5: SendableClassT<SendableClass1 | SendableClass2> =
new SendableClassT<SendableClass1 | SendableClass2 | NonSendableClass1>();

View File

@ -0,0 +1,83 @@
{
"arktsVersion_1_0": [
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 17,
"character": 1
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 23,
"character": 1
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 29,
"character": 1
}
}
],
"arktsVersion_1_1": [
{
"messageText": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)",
"expectLineAndCharacter": {
"line": 42,
"character": 24
}
},
{
"messageText": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)",
"expectLineAndCharacter": {
"line": 42,
"character": 81
}
},
{
"messageText": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)",
"expectLineAndCharacter": {
"line": 43,
"character": 24
}
},
{
"messageText": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)",
"expectLineAndCharacter": {
"line": 44,
"character": 24
}
},
{
"messageText": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)",
"expectLineAndCharacter": {
"line": 44,
"character": 81
}
},
{
"messageText": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)",
"expectLineAndCharacter": {
"line": 45,
"character": 24
}
},
{
"messageText": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)",
"expectLineAndCharacter": {
"line": 46,
"character": 22
}
},
{
"messageText": "Type arguments of generic \"Sendable\" type must be a \"Sendable\" data type (arkts-sendable-generic-types)",
"expectLineAndCharacter": {
"line": 48,
"character": 22
}
}
]
}

View File

@ -0,0 +1,42 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@Sendable
class SendableClassT<T> {
public var1: number = 1;
public var2: string = '1';
}
@Sendable
class SendableClass1 {
public var1: number = 1;
public var2: string = '1';
}
@Sendable
class SendableClass2 {
public var1: number = 1;
public var2: string = '1';
}
class NonSendableClass1 {}
class NonSendableClass2 { public p1 = 1 }
/*
* 1. The generic parameter of `SendableClass` must be of a `Sendable` type.
* 2. If the parameter is a union, each type in the union must be a `Sendable` type.
*/
let A1: SendableClassT<SendableClass1 | SendableClass2> = new SendableClassT<SendableClass1 | SendableClass2>();

View File

@ -0,0 +1,26 @@
{
"arktsVersion_1_0": [
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 17,
"character": 1
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 23,
"character": 1
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 29,
"character": 1
}
}
],
"arktsVersion_1_1": []
}

View File

@ -0,0 +1,39 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { lang } from '../common-lib/@arkts.lang';
interface INonSendable {};
let vArray = [1, 2];
let vObj1: INonSendable = {}
let vObj2: lang.ISendable = {} // should report, arkts-sendable-obj-init
interface ISendableExtend1 extends lang.ISendable {}
let vObj3: ISendableExtend1 = {} // should report, arkts-sendable-obj-init
@Sendable
class BaseSendClass1 {}
@Sendable
class BaseSendClass2 implements lang.ISendable {}
/* // cmp `let a1:BaseSendClass1 = new BaseSendClass1();` */
/* // cmp `let a2:BaseSendClass1 = 1;` */
/* // cmp `let a3:BaseSendClass1 = '1';` */
let a4:BaseSendClass1 = {}; // should report, arkts-sendable-obj-init
let a5:BaseSendClass1 = [1, 2]; // should report, arkts-sendable-obj-init
/* // cmp `let a6:BaseSendClass1 = vArray;` */
let a7:BaseSendClass1 = vObj1; // should report, arkts-no-structural-typing
let a8:BaseSendClass2 = vObj1; // should report, arkts-no-structural-typing
/* // cmp `let a9:BaseSendClass1 = true;` */

View File

@ -0,0 +1,62 @@
{
"arktsVersion_1_0": [
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 26,
"character": 1
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 28,
"character": 1
}
},
{
"messageText": "Structural typing is not supported (arkts-no-structural-typing)",
"expectLineAndCharacter": {
"line": 37,
"character": 5
}
},
{
"messageText": "Structural typing is not supported (arkts-no-structural-typing)",
"expectLineAndCharacter": {
"line": 38,
"character": 5
}
}
],
"arktsVersion_1_1": [
{
"messageText": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)",
"expectLineAndCharacter": {
"line": 34,
"character": 25
}
},
{
"messageText": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)",
"expectLineAndCharacter": {
"line": 35,
"character": 25
}
},
{
"messageText": "Structural typing is not supported (arkts-no-structural-typing)",
"expectLineAndCharacter": {
"line": 37,
"character": 5
}
},
{
"messageText": "Structural typing is not supported (arkts-no-structural-typing)",
"expectLineAndCharacter": {
"line": 38,
"character": 5
}
}
]
}

View File

@ -0,0 +1,39 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { lang } from '../common-lib/@arkts.lang';
interface INonSendable {};
let vArray = [1, 2];
let vObj1: INonSendable = {}
/* // cmp `let vObj2: lang.ISendable = {} // should report, arkts-sendable-obj-init` */
interface ISendableExtend1 extends lang.ISendable {}
/* // cmp `let vObj3: ISendableExtend1 = {} // should report, arkts-sendable-obj-init` */
@Sendable
class BaseSendClass1 {}
@Sendable
class BaseSendClass2 implements lang.ISendable {}
let a1:BaseSendClass1 = new BaseSendClass1();
let a2:BaseSendClass1 = 1; // Native support, when class is {}
let a3:BaseSendClass1 = '1'; // Native support, when class is {}
/* // cmp `let a4:BaseSendClass1 = {}; // should report, arkts-sendable-obj-init` */
/* // cmp `let a5:BaseSendClass1 = [1, 2]; // should report, arkts-sendable-obj-init` */
let a6:BaseSendClass1 = vArray; // Native support, when class is {}
/* // cmp `let a7:BaseSendClass1 = vObj1; // should report, arkts-no-structural-typing` */
/* // cmp `let a8:BaseSendClass2 = vObj1; // should report, arkts-no-structural-typing` */
let a9:BaseSendClass1 = true; // Native support, when class is {}

View File

@ -0,0 +1,27 @@
{
"arktsVersion_1_0": [
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 26,
"character": 1
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 28,
"character": 1
}
}
],
"arktsVersion_1_1": [
{
"messageText": "Structural typing is not supported (arkts-no-structural-typing)",
"expectLineAndCharacter": {
"line": 36,
"character": 5
}
}
]
}

View File

@ -0,0 +1,48 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@Sendable
class BaseSendClass1 {}
class BaseNonSendableClass1 {}
interface A {
p1: BaseSendClass1
p2: BaseSendClass1
p3: BaseSendClass1
p4: BaseSendClass1
p5: BaseSendClass1
p6: BaseSendClass1
p7: BaseSendClass1
p8: BaseSendClass1 | BaseNonSendableClass1
p9: BaseNonSendableClass1
}
interface INonSendable {};
let vArray = [1, 2];
let vObj1: INonSendable = {}
// Because vObj1 triggers rule arkts-no-structural-typing convert to arkts-no-untyped-obj-literals.
let v: A = {
p1: new BaseSendClass1(),
p2: 1,
p3: '1',
p4: vObj1,
p5: vArray,
p6: {},
p7: [],
p8: {},
p9: {}
}

View File

@ -0,0 +1,48 @@
{
"arktsVersion_1_0": [
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 17,
"character": 1
}
},
{
"messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)",
"expectLineAndCharacter": {
"line": 38,
"character": 12
}
}
],
"arktsVersion_1_1": [
{
"messageText": "Object literal must correspond to some explicitly declared class or interface (arkts-no-untyped-obj-literals)",
"expectLineAndCharacter": {
"line": 38,
"character": 12
}
},
{
"messageText": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)",
"expectLineAndCharacter": {
"line": 44,
"character": 7
}
},
{
"messageText": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)",
"expectLineAndCharacter": {
"line": 45,
"character": 7
}
},
{
"messageText": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)",
"expectLineAndCharacter": {
"line": 46,
"character": 7
}
}
]
}

View File

@ -0,0 +1,43 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@Sendable
class BaseSendClass1 {}
class BaseNonSendableClass1 {}
interface A {
p1: BaseSendClass1
p2: BaseSendClass1
p3: BaseSendClass1
p4: BaseSendClass1
p5: BaseSendClass1
p6: BaseSendClass1
p7: BaseSendClass1
p8: BaseSendClass1 | BaseNonSendableClass1
p9: BaseNonSendableClass1
}
let v: A = {
p1: new BaseSendClass1(),
p2: new BaseSendClass1(),
p3: new BaseSendClass1(),
p4: new BaseSendClass1(),
p5: new BaseSendClass1(),
p6: new BaseSendClass1(),
p7: new BaseSendClass1(),
p8: new BaseNonSendableClass1(),
p9: new BaseNonSendableClass1(),
}

View File

@ -0,0 +1,12 @@
{
"arktsVersion_1_0": [
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 17,
"character": 1
}
}
],
"arktsVersion_1_1": []
}

View File

@ -0,0 +1,28 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@Sendable
class SendableClass9 {
// should report, arkts-sendable-obj-init
public prop1: SendableClass9 = { prop1: new SendableClass9(), prop2: new SendableClass9() };
// should report, arkts-sendable-obj-init
public prop2: SendableClass9 = [1, 2];
}
// should report, arkts-sendable-obj-init
let v0: SendableClass9 = { prop1: new SendableClass9(), prop2: new SendableClass9() };
// should report, arkts-sendable-obj-init
let v1: SendableClass9 = [1, 2];

View File

@ -0,0 +1,41 @@
{
"arktsVersion_1_0": [
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 17,
"character": 1
}
}
],
"arktsVersion_1_1": [
{
"messageText": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)",
"expectLineAndCharacter": {
"line": 20,
"character": 34
}
},
{
"messageText": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)",
"expectLineAndCharacter": {
"line": 22,
"character": 34
}
},
{
"messageText": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)",
"expectLineAndCharacter": {
"line": 26,
"character": 26
}
},
{
"messageText": "Objects of \"Sendable\" type can not be initialized using object literal or array literal (arkts-sendable-obj-init)",
"expectLineAndCharacter": {
"line": 28,
"character": 26
}
}
]
}

View File

@ -0,0 +1,56 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { lang } from '../common-lib/@arkts.lang';
class NonSendableClass2 {}
@Sendable
class SendableClass10 {}
type alias0 = number | null;
type alias1 = SendableClass10;
type alias2 = NonSendableClass2;
type alias3 = NonSendableClass2 | undefined;
@Sendable
class SendableClass3 {
public prop1: string[]; // should report, arkts-sendable-prop-types
public prop2: NonSendableClass2; // should report, arkts-sendable-prop-types
public prop3: NonSendableClass2 | null; // should report, arkts-sendable-prop-types
public prop4: NonSendableClass2 | undefined; // should report, arkts-sendable-prop-types
public prop5: NonSendableClass2 | null | undefined; // should report, arkts-sendable-prop-types
public prop6: alias2; // should report, arkts-sendable-prop-types
public prop7: alias3; // should report, arkts-sendable-prop-types
constructor() {
this.prop1 = ['']
this.prop2 = new NonSendableClass2(); // should report, arkts-sendable-imported-variables
this.prop3 = null;
this.prop4 = undefined;
this.prop5 = undefined;
this.prop6 = new NonSendableClass2(); // should report, arkts-sendable-imported-variables
this.prop7 = undefined;
}
}
class B {}
@Sendable
class C {}
interface A extends lang.ISendable {
c: B; // should report, arkts-sendable-prop-types
}

View File

@ -0,0 +1,90 @@
{
"arktsVersion_1_0": [
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 20,
"character": 1
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 27,
"character": 1
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 51,
"character": 1
}
}
],
"arktsVersion_1_1": [
{
"messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)",
"expectLineAndCharacter": {
"line": 39,
"character": 22
}
},
{
"messageText": "Only imported variables can be captured by \"Sendable\" class (arkts-sendable-imported-variables)",
"expectLineAndCharacter": {
"line": 43,
"character": 22
}
},
{
"messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)",
"expectLineAndCharacter": {
"line": 29,
"character": 3
}
},
{
"messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)",
"expectLineAndCharacter": {
"line": 30,
"character": 3
}
},
{
"messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)",
"expectLineAndCharacter": {
"line": 31,
"character": 3
}
},
{
"messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)",
"expectLineAndCharacter": {
"line": 32,
"character": 3
}
},
{
"messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)",
"expectLineAndCharacter": {
"line": 33,
"character": 3
}
},
{
"messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)",
"expectLineAndCharacter": {
"line": 34,
"character": 3
}
},
{
"messageText": "Properties in \"Sendable\" classes and interfaces must have a Sendable data type (arkts-sendable-prop-types)",
"expectLineAndCharacter": {
"line": 35,
"character": 3
}
}
]
}

View File

@ -0,0 +1,64 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { lang } from '../common-lib/@arkts.lang';
class NonSendableClass2 {}
@Sendable
class SendableClass10 {}
type alias0 = number | null;
type alias1 = SendableClass10;
type alias2 = NonSendableClass2;
type alias3 = NonSendableClass2 | undefined;
@Sendable
class SendableClass4<T, U> {
public prop1: number; // OK
public prop2: string; // OK
public prop3: boolean; // OK
public prop4: bigint; // OK
public prop5: SendableClass10; // OK
public prop6: null; // OK
public prop7: undefined; // OK
public prop8: U; // OK
public prop9: T | number | undefined; // OK
public prop10: alias0; // OK
public prop11: alias1; // OK
constructor(u: U, t: T) {
this.prop1 = 1;
this.prop2 = '';
this.prop3 = true;
this.prop4 = BigInt(11111);
this.prop5 = new SendableClass10();
this.prop6 = null;
this.prop7 = undefined;
this.prop8 = u;
this.prop9 = undefined;
this.prop10 = null;
this.prop11 = new SendableClass10();
}
}
class B {}
@Sendable
class C {}
interface A extends lang.ISendable {
a: number; // OK
b: C; // OK
}

View File

@ -0,0 +1,26 @@
{
"arktsVersion_1_0": [
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 20,
"character": 1
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 27,
"character": 1
}
},
{
"messageText": "No decorators except ArkUI decorators are currently allowed (arkts-no-decorators-except-arkui)",
"expectLineAndCharacter": {
"line": 58,
"character": 1
}
}
],
"arktsVersion_1_1": []
}

View File

@ -0,0 +1,18 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
declare namespace lang {
interface ISendable {}
}