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

rokucommunity / brighterscript / #13590

13 Jan 2025 02:40PM UTC coverage: 86.911% (-1.3%) from 88.185%
#13590

push

web-flow
Merge 38702985d into 9d6ef67ba

12071 of 14663 branches covered (82.32%)

Branch coverage included in aggregate %.

90 of 94 new or added lines in 11 files covered. (95.74%)

796 existing lines in 47 files now uncovered.

13048 of 14239 relevant lines covered (91.64%)

31886.92 hits per line

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

87.63
/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();
166,054✔
18
        this.innerTypes = innerTypes;
166,054✔
19
    }
20

21
    public readonly kind = BscTypeKind.ArrayType;
166,054✔
22

23
    public innerTypes: BscType[] = [];
166,054✔
24

25
    public _defaultType: BscType;
26

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

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

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

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

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

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

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