• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rokucommunity / brighterscript / #13233

24 Oct 2024 01:02PM UTC coverage: 86.866% (-1.3%) from 88.214%
#13233

push

web-flow
Merge cc3491b40 into 7cfaaa047

11613 of 14131 branches covered (82.18%)

Branch coverage included in aggregate %.

7028 of 7618 new or added lines in 100 files covered. (92.26%)

87 existing lines in 18 files now uncovered.

12732 of 13895 relevant lines covered (91.63%)

30018.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.59
/src/types/ArrayType.ts
1

2
import { SymbolTypeFlag } from '../SymbolTypeFlag';
1✔
3
import { isArrayType, isDynamicType, isObjectType } from '../astUtils/reflection';
1✔
4
import type { TypeCompatibilityData } from '../interfaces';
5
import { BscType } from './BscType';
1✔
6
import { BscTypeKind } from './BscTypeKind';
1✔
7
import type { BuiltInInterfaceOverride } from './BuiltInInterfaceAdder';
8
import { BuiltInInterfaceAdder } from './BuiltInInterfaceAdder';
1✔
9
import { DynamicType } from './DynamicType';
1✔
10
import { IntegerType } from './IntegerType';
1✔
11
import { unionTypeFactory } from './UnionType';
1✔
12
import { getUniqueType, isUnionTypeCompatible } from './helpers';
1✔
13

14
export class ArrayType extends BscType {
1✔
15
    constructor(...innerTypes: BscType[]) {
16
        super();
158,028✔
17
        this.innerTypes = innerTypes;
158,028✔
18
    }
19

20
    public readonly kind = BscTypeKind.ArrayType;
158,028✔
21

22
    public innerTypes: BscType[] = [];
158,028✔
23

24
    public get defaultType(): BscType {
25
        if (this.innerTypes?.length === 0) {
3,880!
26
            return DynamicType.instance;
3,564✔
27
        } else if (this.innerTypes?.length === 1) {
316!
28
            return this.innerTypes[0];
285✔
29
        }
30
        return getUniqueType(this.innerTypes, unionTypeFactory);
31✔
31
    }
32

33
    public isTypeCompatible(targetType: BscType, data?: TypeCompatibilityData) {
34

35
        if (isDynamicType(targetType)) {
17✔
36
            return true;
1✔
37
        } else if (isObjectType(targetType)) {
16✔
38
            return true;
2✔
39
        } else if (isUnionTypeCompatible(this, targetType)) {
14!
NEW
40
            return true;
×
41
        } else if (isArrayType(targetType)) {
14✔
42
            const compatible = this.defaultType.isTypeCompatible(targetType.defaultType, data);
10✔
43
            if (data) {
10✔
44
                data.actualType = targetType.defaultType;
6✔
45
                data.expectedType = this.defaultType;
6✔
46
            }
47
            return compatible;
10✔
48
        } else if (this.checkCompatibilityBasedOnMembers(targetType, SymbolTypeFlag.runtime, data)) {
4✔
49
            return true;
3✔
50
        }
51
        return false;
1✔
52
    }
53

54
    public toString() {
55
        return `Array<${this.defaultType.toString()}>`;
3,775✔
56
    }
57

58
    public toTypeString(): string {
59
        return 'object';
×
60
    }
61

62
    public isEqual(targetType: BscType): boolean {
63
        if (isArrayType(targetType)) {
3✔
64
            if (targetType.innerTypes.length !== this.innerTypes.length) {
1!
NEW
65
                return false;
×
66
            }
67
            for (let i = 0; i < this.innerTypes.length; i++) {
1✔
NEW
68
                if (!this.innerTypes[i].isEqual(targetType.innerTypes[i])) {
×
NEW
69
                    return false;
×
70
                }
71
            }
72
            return true;
1✔
73
        }
74
        return false;
2✔
75
    }
76

77
    addBuiltInInterfaces() {
78
        if (!this.hasAddedBuiltInInterfaces) {
96✔
79
            const overrideMap = new Map<string, BuiltInInterfaceOverride>();
17✔
80
            const defaultType = this.defaultType;
17✔
81
            overrideMap
17✔
82
                // ifArray
83
                .set('peek', { returnType: defaultType })
84
                .set('pop', { returnType: defaultType })
85
                .set('push', { parameterTypes: [defaultType] })
86
                .set('shift', { returnType: defaultType })
87
                .set('unshift', { parameterTypes: [defaultType] })
88
                .set('append', { parameterTypes: [this] })
89
                // ifArrayGet
90
                .set('get', { returnType: defaultType })
91
                // ifArraySet
92
                .set('get', { parameterTypes: [IntegerType.instance, defaultType] })
93
                //ifEnum
94
                .set('next', { returnType: defaultType });
95
            BuiltInInterfaceAdder.addBuiltInInterfacesToType(this, overrideMap);
17✔
96
        }
97
        this.hasAddedBuiltInInterfaces = true;
96✔
98
    }
99
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc