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

rokucommunity / brighterscript / #14385

09 May 2025 11:44AM UTC coverage: 87.032% (-2.0%) from 89.017%
#14385

push

web-flow
Merge a194c3925 into 489231ac7

13732 of 16677 branches covered (82.34%)

Branch coverage included in aggregate %.

8175 of 8874 new or added lines in 103 files covered. (92.12%)

84 existing lines in 22 files now uncovered.

14604 of 15881 relevant lines covered (91.96%)

20324.31 hits per line

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

87.85
/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();
180,492✔
18
        this.innerTypes = innerTypes;
180,492✔
19
    }
20

21
    public readonly kind = BscTypeKind.ArrayType;
180,492✔
22
    public isBuiltIn = true;
180,492✔
23

24
    public innerTypes: BscType[] = [];
180,492✔
25

26
    public _defaultType: BscType;
27
    private isCheckingInnerTypesForDefaultType = false;
180,492✔
28

29
    public get defaultType(): BscType {
30
        if (this._defaultType) {
8,861✔
31
            return this._defaultType;
4,641✔
32
        }
33
        if (this.innerTypes?.length === 0 || this.isCheckingInnerTypesForDefaultType) {
4,220!
34
            return DynamicType.instance;
4,024✔
35
        }
36
        this.isCheckingInnerTypesForDefaultType = true;
196✔
37

38
        let resultType = this.innerTypes[0];
196✔
39
        if (this.innerTypes?.length > 1) {
196!
40
            resultType = getUniqueType(this.innerTypes, unionTypeFactory) ?? DynamicType.instance;
30!
41
        }
42
        if (isEnumMemberType(resultType)) {
196✔
43
            resultType = resultType.parentEnumType ?? resultType;
2!
44
        }
45
        this._defaultType = util.getDefaultTypeFromValueType(resultType);
196✔
46
        this.isCheckingInnerTypesForDefaultType = false;
196✔
47
        return this._defaultType;
196✔
48
    }
49

50
    public isTypeCompatible(targetType: BscType, data?: TypeCompatibilityData) {
51

52
        if (isDynamicType(targetType)) {
20✔
53
            return true;
1✔
54
        } else if (isObjectType(targetType)) {
19✔
55
            return true;
3✔
56
        } else if (isUnionTypeCompatible(this, targetType)) {
16!
NEW
57
            return true;
×
58
        } else if (isArrayType(targetType)) {
16✔
59
            const compatible = this.defaultType.isTypeCompatible(targetType.defaultType, data);
10✔
60
            if (data) {
10✔
61
                data.actualType = targetType.defaultType;
6✔
62
                data.expectedType = this.defaultType;
6✔
63
            }
64
            return compatible;
10✔
65
        } else if (this.checkCompatibilityBasedOnMembers(targetType, SymbolTypeFlag.runtime, data)) {
6✔
66
            return true;
3✔
67
        }
68
        return false;
3✔
69
    }
70

71
    public toString() {
72
        return `Array<${this.defaultType.toString()}>`;
4,230✔
73
    }
74

75
    public toTypeString(): string {
76
        return 'object';
×
77
    }
78

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

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