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

rokucommunity / brighterscript / #13308

22 Nov 2024 02:25PM UTC coverage: 86.801%. Remained the same
#13308

push

web-flow
Merge 332332a1f into 2a6afd921

11833 of 14419 branches covered (82.07%)

Branch coverage included in aggregate %.

191 of 205 new or added lines in 26 files covered. (93.17%)

201 existing lines in 18 files now uncovered.

12868 of 14038 relevant lines covered (91.67%)

32022.22 hits per line

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

86.78
/src/types/BscType.ts
1
import type { GetSymbolTypeOptions, SymbolTableProvider } from '../SymbolTable';
2
import { SymbolTable } from '../SymbolTable';
1✔
3
import { SymbolTypeFlag } from '../SymbolTypeFlag';
1✔
4
import { BuiltInInterfaceAdder } from './BuiltInInterfaceAdder';
1✔
5
import type { ExtraSymbolData, TypeCompatibilityData } from '../interfaces';
6
import { isArrayType, isInheritableType, isReferenceType } from '../astUtils/reflection';
1✔
7

8
export abstract class BscType {
1✔
9

10
    public readonly memberTable: SymbolTable;
11
    protected __identifier: string;
12
    protected hasAddedBuiltInInterfaces = false;
5,936,369✔
13
    public isBuiltIn = false;
5,936,369✔
14

15
    constructor(name = '') {
5,072,905✔
16
        this.__identifier = `${this.constructor.name}${name ? ': ' + name : ''}`;
5,936,369✔
17
        this.memberTable = new SymbolTable(this.__identifier);
5,936,369✔
18
    }
19

20
    pushMemberProvider(provider: SymbolTableProvider) {
21
        this.memberTable.pushParentProvider(provider);
13,148✔
22
    }
23

24
    popMemberProvider() {
UNCOV
25
        this.memberTable.popParentProvider();
×
26
    }
27

28
    getBuiltInMemberTable(): SymbolTable {
29
        return this.memberTable;
307,535✔
30
    }
31

32
    addMember(name: string, data: ExtraSymbolData, type: BscType, flags: SymbolTypeFlag) {
33
        this.memberTable.addSymbol(name, data, type, flags);
23,508✔
34
    }
35

36
    getMemberType(name: string, options: GetSymbolTypeOptions) {
37
        this.addBuiltInInterfaces();
12,893✔
38
        return this.memberTable.getSymbolType(name, options);
12,893✔
39
    }
40

41
    getMemberTable() {
42
        this.addBuiltInInterfaces();
2,149✔
43
        return this.memberTable;
2,149✔
44
    }
45

46
    isResolvable(): boolean {
47
        return true;
16,163✔
48
    }
49

50
    /**
51
     * Check if this type can be assigned to the target type
52
     * @param targetType the type that we're trying to assign this type to
53
     * @deprecated
54
     */
55
    isAssignableTo(targetType: BscType): boolean {
UNCOV
56
        return targetType.isTypeCompatible(this);
×
57
    }
58

59
    /**
60
     * Check if a different type can be assigned to this type - eg. does the other type convert into this type?
61
     * @param _otherType the type to check if it can be used as this type, or can automatically be converted into this type
62
     */
63
    isTypeCompatible(_otherType: BscType, data?: TypeCompatibilityData): boolean {
UNCOV
64
        throw new Error('Method not implemented.');
×
65
    }
66
    toString(): string {
UNCOV
67
        throw new Error('Method not implemented.');
×
68
    }
69
    toTypeString(): string {
UNCOV
70
        throw new Error('Method not implemented.');
×
71
    }
72

73
    isEqual(targetType: BscType, data: TypeCompatibilityData = {}): boolean {
×
UNCOV
74
        throw new Error('Method not implemented.');
×
75
    }
76

77
    checkCompatibilityBasedOnMembers(targetType: BscType, flags: SymbolTypeFlag, data: TypeCompatibilityData = {}) {
56✔
78
        if (!targetType) {
218✔
79
            return false;
2✔
80
        }
81
        let isSuperSet = true;
216✔
82
        data.missingFields ||= [];
216✔
83
        data.fieldMismatches ||= [];
216✔
84
        data.depth = data.depth ? data.depth + 1 : 1;
216✔
85
        //data.chain ||= [];
86
        this.addBuiltInInterfaces();
216✔
87
        targetType.addBuiltInInterfaces();
216✔
88

89
        if (this === targetType) {
216✔
90
            return true;
21✔
91
        }
92

93
        if (isReferenceType(targetType) && !targetType.isResolvable()) {
195!
94
            // we can't resolve the other type. Assume it does not fail on member checks
UNCOV
95
            return true;
×
96
        }
97

98
        if (data.depth > 16) {
195!
99
            // some sort of circular reference
UNCOV
100
            return false;
×
101
        }
102
        const mySymbols = this.getMemberTable()?.getAllSymbols(flags);
195!
103
        for (const memberSymbol of mySymbols) {
195✔
104
            const targetTypesOfSymbol = targetType.getMemberTable()
855✔
105
                .getSymbolTypes(memberSymbol.name, { flags: flags })
855✔
106
                ?.map(symbol => symbol.type);
735✔
107
            if (!targetTypesOfSymbol || targetTypesOfSymbol.length === 0) {
855✔
108
                // eslint-disable-next-line no-bitwise
109
                if (!(memberSymbol.flags & SymbolTypeFlag.optional)) {
120✔
110
                    data.missingFields.push({ name: memberSymbol.name, expectedType: memberSymbol.type });
115✔
111
                    isSuperSet = false;
115✔
112
                }
113

114
            } else {
115
                isSuperSet =
735✔
116
                    (targetTypesOfSymbol ?? []).reduce((superSetSoFar, typeOfTargetSymbol) => {
3,655!
117
                        if (!superSetSoFar) {
735!
UNCOV
118
                            return superSetSoFar;
×
119
                        }
120
                        const typesAreInheritableWithSameName = isInheritableType(memberSymbol.type) && isInheritableType(typeOfTargetSymbol) &&
735✔
121
                            memberSymbol.type.name.toLowerCase() === typeOfTargetSymbol.name.toLowerCase();
122
                        const typesAreArraysWithSameDefault = isArrayType(memberSymbol.type) && isArrayType(typeOfTargetSymbol) &&
735✔
123
                            memberSymbol.type.defaultType.isEqual(typeOfTargetSymbol.defaultType);
124
                        const myMemberAllowsTargetType = typesAreInheritableWithSameName || typesAreArraysWithSameDefault || memberSymbol.type?.isTypeCompatible(typeOfTargetSymbol, { depth: data.depth });
735!
125
                        if (!myMemberAllowsTargetType) {
735✔
126
                            data.fieldMismatches.push({ name: memberSymbol.name, expectedType: memberSymbol.type, actualType: targetType.getMemberType(memberSymbol.name, { flags: flags }) });
20✔
127
                        }
128
                        return superSetSoFar && myMemberAllowsTargetType;
735✔
129
                    }, true) && isSuperSet;
130
            }
131

132
        }
133
        data.depth = 0;
195✔
134
        return isSuperSet;
195✔
135
    }
136

137
    addBuiltInInterfaces() {
138
        if (!this.hasAddedBuiltInInterfaces) {
320,519✔
139
            BuiltInInterfaceAdder.addBuiltInInterfacesToType(this);
307,787✔
140
        }
141
        this.hasAddedBuiltInInterfaces = true;
320,519✔
142
    }
143
}
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