Skip to content

Commit

Permalink
Fix exception when given unknown type (#983)
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Dec 7, 2023
1 parent ca58a07 commit e5cedc5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/types/BscType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ export abstract class BscType {
}

checkCompatibilityBasedOnMembers(targetType: BscType, flags: SymbolTypeFlag, data: TypeCompatibilityData = {}) {
if (!targetType) {
return false;
}
let isSuperSet = true;
data.missingFields ||= [];
data.fieldMismatches ||= [];
Expand Down Expand Up @@ -113,7 +116,7 @@ export abstract class BscType {
return superSetSoFar;
}

const myMemberAllowsTargetType = memberSymbol.type.isTypeCompatible(typeOfTargetSymbol, { depth: data.depth });
const myMemberAllowsTargetType = memberSymbol.type?.isTypeCompatible(typeOfTargetSymbol, { depth: data.depth });
if (!myMemberAllowsTargetType) {
data.fieldMismatches.push({ name: memberSymbol.name, expectedType: memberSymbol.type, actualType: targetType.getMemberType(memberSymbol.name, { flags: flags }) });
}
Expand All @@ -133,4 +136,3 @@ export abstract class BscType {
this.hasAddedBuiltInInterfaces = true;
}
}

6 changes: 6 additions & 0 deletions src/types/InterfaceType.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ describe('InterfaceType', () => {
});
});

it('does not crash when given non types', () => {
const iface = new InterfaceType('roArray');
expect(iface.isTypeCompatible(undefined)).to.be.false;
expect(iface.isTypeCompatible(null)).to.be.false;
});

it('roku component types are compatible with BscTypes', () => {
// TODO: Fix String type compatibility - reason is because of overloaded members (Mid(), StartsWith(), etc)
// SEE: https://github.com/rokucommunity/brighterscript/issues/926
Expand Down

0 comments on commit e5cedc5

Please sign in to comment.