From 8c5f8741e7f451c05f32bf379805416e8dac1325 Mon Sep 17 00:00:00 2001 From: Bronley Plumb Date: Mon, 13 Jan 2025 15:51:02 -0500 Subject: [PATCH] Fix crash when unraveling complex BinaryReferenceType --- src/files/BrsFile.spec.ts | 29 +++++++++++++++++++++++++++++ src/types/ReferenceType.ts | 2 +- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/files/BrsFile.spec.ts b/src/files/BrsFile.spec.ts index 7a72616b1..79a672650 100644 --- a/src/files/BrsFile.spec.ts +++ b/src/files/BrsFile.spec.ts @@ -27,6 +27,7 @@ import * as fileUrl from 'file-url'; import { isAALiteralExpression, isBlock } from '../astUtils/reflection'; import type { AALiteralExpression } from '../parser/Expression'; import { CallExpression, FunctionExpression, LiteralExpression } from '../parser/Expression'; +import { Logger } from '@rokucommunity/logger'; let sinon = sinonImport.createSandbox(); @@ -188,6 +189,34 @@ describe('BrsFile', () => { expectDiagnostics(program, [DiagnosticMessages.itemCannotBeUsedAsVariable('enum').message]); }); + it('does not crazy during validation with unique binary operator', () => { + //monitor the logging system, if we detect an error, this test fails + const spy = sinon.spy(Logger.prototype, 'error'); + program.setFile('source/main.bs', ` + namespace date + function timeElapsedInDay() + time = 1 + if true then + time = getInteger() + end if + clockSeconds = getInteger() + 1 + assumedMidnight = time - clockSeconds + offset = assumedMidnight - 1 + end function + + function getInteger() + return 1 + end function + end namespace + + `); + program.validate(); + expectZeroDiagnostics(program); + expect( + spy.getCalls().map(x => (x.args?.[0] as string)?.toString()).filter(x => x?.includes('Error when calling plugin')) + ).to.eql([]); + }); + it('supports the third parameter in CreateObject', () => { program.setFile('source/main.brs', ` sub main() diff --git a/src/types/ReferenceType.ts b/src/types/ReferenceType.ts index bcd7aece6..befa053be 100644 --- a/src/types/ReferenceType.ts +++ b/src/types/ReferenceType.ts @@ -426,7 +426,7 @@ export class BinaryOperatorReferenceType extends BscType { return () => undefined; } } else { - resultType = binaryOpResolver(this.leftType, this.operator, this.rightType); + resultType = binaryOpResolver(this.leftType, this.operator, this.rightType) ?? DynamicType.instance; this.cachedType = resultType; }