Skip to content

Commit

Permalink
Fixed issue for callfuncs returning voidtype
Browse files Browse the repository at this point in the history
  • Loading branch information
markwpearce committed Jan 6, 2025
1 parent 3d2e4f5 commit d20aee5
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
91 changes: 91 additions & 0 deletions src/bscPlugin/validation/ScopeValidator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4856,6 +4856,97 @@ describe('ScopeValidator', () => {
DiagnosticMessages.argumentTypeMismatch('string', 'integer').message
]);
});

it('respects return value of as callfunc functions', () => {
program.setFile('components/Widget.xml', trim`
<?xml version="1.0" encoding="utf-8" ?>
<component name="Widget" extends="Group">
<script uri="Widget.bs"/>
<interface>
<function name="getInt" />
</interface>
</component>
`);

program.setFile('components/Widget.bs', `
sub getInt() as integer
return 1
end sub
`);

program.setFile('source/test.bs', `
sub doCallfunc(widget as roSGNodeWidget)
takesInt(widget@.getInt())
end sub
sub takesInt(number as integer)
print number
end sub
`);
program.validate();
expectZeroDiagnostics(program);
});

it('respects return value of as callfunc functions - negative case', () => {
program.setFile('components/Widget.xml', trim`
<?xml version="1.0" encoding="utf-8" ?>
<component name="Widget" extends="Group">
<script uri="Widget.bs"/>
<interface>
<function name="getInt" />
</interface>
</component>
`);

program.setFile('components/Widget.bs', `
sub getInt() as integer
return 1
end sub
`);

program.setFile('source/test.bs', `
sub doCallfunc(widget as roSGNodeWidget)
takesString(widget@.getInt())
end sub
sub takesString(word as string)
print word
end sub
`);
program.validate();
expectDiagnostics(program, [
DiagnosticMessages.argumentTypeMismatch('integer', 'string').message
]);
});

it('allows return value of as void functions to be dynamic', () => {
program.setFile('components/Widget.xml', trim`
<?xml version="1.0" encoding="utf-8" ?>
<component name="Widget" extends="Group">
<script uri="Widget.bs"/>
<interface>
<function name="noop" />
</interface>
</component>
`);

program.setFile('components/Widget.bs', `
sub noop()
end sub
`);

program.setFile('source/test.bs', `
sub doCallfunc(widget as roSGNodeWidget)
takesAny(widget@.noop())
end sub
sub takesAny(anything)
print anything
end sub
`);
program.validate();
expectZeroDiagnostics(program);
});
});
});

4 changes: 4 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2556,6 +2556,10 @@ export class Util {
}
}
}
if (isVoidType(result)) {
// CallFunc will always return invalid, even if function called is `as void`
result = DynamicType.instance;
}
if (options.data && !options.ignoreCall) {
options.data.isFromCallFunc = true;
}
Expand Down

0 comments on commit d20aee5

Please sign in to comment.