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

rokucommunity / brighterscript / #13615

14 Jan 2025 06:19PM UTC coverage: 86.812%. Remained the same
#13615

push

web-flow
Merge 05a55830c into 7fb92fff2

12436 of 15140 branches covered (82.14%)

Branch coverage included in aggregate %.

409 of 435 new or added lines in 36 files covered. (94.02%)

264 existing lines in 24 files now uncovered.

13334 of 14545 relevant lines covered (91.67%)

34016.38 hits per line

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

87.76
/src/types/ArrayType.ts
1

2
import { SymbolTypeFlag } from '../SymbolTypeFlag';
1✔
3
import { isArrayType, isDynamicType, isEnumMemberType, 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
import { util } from '../util';
1✔
14

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

21
    public readonly kind = BscTypeKind.ArrayType;
168,236✔
22
    public isBuiltIn = true;
168,236✔
23

24
    public innerTypes: BscType[] = [];
168,236✔
25

26
    public _defaultType: BscType;
27

28
    public get defaultType(): BscType {
29
        if (this._defaultType) {
6,245✔
30
            return this._defaultType;
2,309✔
31
        }
32
        if (this.innerTypes?.length === 0) {
3,936!
33
            return DynamicType.instance;
3,750✔
34
        }
35
        let resultType = this.innerTypes[0];
186✔
36
        if (this.innerTypes?.length > 1) {
186!
37
            resultType = getUniqueType(this.innerTypes, unionTypeFactory);
24✔
38
        }
39
        if (isEnumMemberType(resultType)) {
186✔
40
            resultType = resultType.parentEnumType ?? resultType;
2!
41
        }
42
        this._defaultType = util.getDefaultTypeFromValueType(this.innerTypes);
186✔
43
        return resultType;
186✔
44
    }
45

46
    public isTypeCompatible(targetType: BscType, data?: TypeCompatibilityData) {
47

48
        if (isDynamicType(targetType)) {
17✔
49
            return true;
1✔
50
        } else if (isObjectType(targetType)) {
16✔
51
            return true;
2✔
52
        } else if (isUnionTypeCompatible(this, targetType)) {
14!
UNCOV
53
            return true;
×
54
        } else if (isArrayType(targetType)) {
14✔
55
            const compatible = this.defaultType.isTypeCompatible(targetType.defaultType, data);
10✔
56
            if (data) {
10✔
57
                data.actualType = targetType.defaultType;
6✔
58
                data.expectedType = this.defaultType;
6✔
59
            }
60
            return compatible;
10✔
61
        } else if (this.checkCompatibilityBasedOnMembers(targetType, SymbolTypeFlag.runtime, data)) {
4✔
62
            return true;
3✔
63
        }
64
        return false;
1✔
65
    }
66

67
    public toString() {
68
        return `Array<${this.defaultType.toString()}>`;
3,961✔
69
    }
70

71
    public toTypeString(): string {
UNCOV
72
        return 'object';
×
73
    }
74

75
    public isEqual(targetType: BscType): boolean {
76
        if (isArrayType(targetType)) {
3✔
77
            if (targetType.innerTypes.length !== this.innerTypes.length) {
1!
UNCOV
78
                return false;
×
79
            }
80
            for (let i = 0; i < this.innerTypes.length; i++) {
1✔
UNCOV
81
                if (!this.innerTypes[i].isEqual(targetType.innerTypes[i])) {
×
82
                    return false;
×
83
                }
84
            }
85
            return true;
1✔
86
        }
87
        return false;
2✔
88
    }
89

90
    addBuiltInInterfaces() {
91
        if (!this.hasAddedBuiltInInterfaces) {
93✔
92
            const overrideMap = new Map<string, BuiltInInterfaceOverride>();
47✔
93
            const defaultType = this.defaultType;
47✔
94
            overrideMap
47✔
95
                // ifArray
96
                .set('peek', { returnType: defaultType })
97
                .set('pop', { returnType: defaultType })
98
                .set('push', { parameterTypes: [defaultType] })
99
                .set('shift', { returnType: defaultType })
100
                .set('unshift', { parameterTypes: [defaultType] })
101
                .set('append', { parameterTypes: [this] })
102
                // ifArrayGet
103
                .set('get', { returnType: defaultType })
104
                // ifArraySet
105
                .set('get', { parameterTypes: [IntegerType.instance, defaultType] })
106
                //ifEnum
107
                .set('next', { returnType: defaultType });
108
            BuiltInInterfaceAdder.addBuiltInInterfacesToType(this, overrideMap);
47✔
109
        }
110
        this.hasAddedBuiltInInterfaces = true;
93✔
111
    }
112
}
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

© 2026 Coveralls, Inc