Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/bscPlugin/validation/ScopeValidator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { tempDir, rootDir } from '../../testHelpers.spec';
import { isReturnStatement } from '../../astUtils/reflection';
import { ScopeValidator } from './ScopeValidator';
import type { ReturnStatement } from '../../parser/Statement';
import { Logger } from '@rokucommunity/logger';

describe('ScopeValidator', () => {

Expand Down Expand Up @@ -2892,6 +2893,34 @@ describe('ScopeValidator', () => {
program.validate();
expectZeroDiagnostics(program);
});

it('allows returning a function call', () => {
const spy = sinon.spy(Logger.prototype, 'error');
program.setFile<BrsFile>('source/main.bs', `
function abc(func as function) as dynamic
return func()
end function
`);
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('allows returning a roFunction call', () => {
const spy = sinon.spy(Logger.prototype, 'error');
program.setFile<BrsFile>('source/main.bs', `
function abc(func as roFunction) as dynamic
return func()
end function
`);
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([]);
});
});

describe('returnTypeCoercionMismatch', () => {
Expand Down
7 changes: 6 additions & 1 deletion src/parser/Expression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as fileUrl from 'file-url';
import type { WalkOptions, WalkVisitor } from '../astUtils/visitors';
import { WalkMode } from '../astUtils/visitors';
import { walk, InternalWalkMode, walkArray } from '../astUtils/visitors';
import { isAALiteralExpression, isAAMemberExpression, isArrayLiteralExpression, isArrayType, isCallableType, isCallExpression, isCallfuncExpression, isDottedGetExpression, isEscapedCharCodeLiteralExpression, isFunctionExpression, isFunctionStatement, isIntegerType, isInterfaceMethodStatement, isInvalidType, isLiteralBoolean, isLiteralExpression, isLiteralNumber, isLiteralString, isLongIntegerType, isMethodStatement, isNamespaceStatement, isNativeType, isNewExpression, isPrimitiveType, isReferenceType, isStringType, isTemplateStringExpression, isTypecastExpression, isUnaryExpression, isVariableExpression, isVoidType } from '../astUtils/reflection';
import { isAALiteralExpression, isAAMemberExpression, isArrayLiteralExpression, isArrayType, isCallableType, isCallExpression, isCallfuncExpression, isDottedGetExpression, isEscapedCharCodeLiteralExpression, isFunctionExpression, isFunctionStatement, isIntegerType, isInterfaceMethodStatement, isInterfaceType, isInvalidType, isLiteralBoolean, isLiteralExpression, isLiteralNumber, isLiteralString, isLongIntegerType, isMethodStatement, isNamespaceStatement, isNativeType, isNewExpression, isPrimitiveType, isReferenceType, isStringType, isTemplateStringExpression, isTypecastExpression, isUnaryExpression, isVariableExpression, isVoidType } from '../astUtils/reflection';
import type { GetTypeOptions, TranspileResult, TypedefProvider } from '../interfaces';
import { TypeChainEntry } from '../interfaces';
import { VoidType } from '../types/VoidType';
Expand Down Expand Up @@ -200,6 +200,11 @@ export class CallExpression extends Expression {
if (isNewExpression(this.parent)) {
return calleeType;
}
if (isInterfaceType(calleeType) && calleeType?.isBuiltIn && calleeType?.name === 'roFunction') {
// things typed as `roFunction` can be called, but we don't know the return type
return DynamicType.instance;
}

const specialCaseReturnType = util.getSpecialCaseCallExpressionReturnType(this, options);
if (specialCaseReturnType) {
return specialCaseReturnType;
Expand Down