Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Enum and Interface return types #601

Merged
merged 1 commit into from
May 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
72 changes: 72 additions & 0 deletions src/Scope.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,78 @@ describe('Scope', () => {
]);
});

it('finds interface types', () => {
program.setFile({ src: s`${rootDir}/source/main.bs`, dest: s`source/main.bs` }, `
namespace MyNamespace
interface MyInterface
title as string
end interface

function bar(param as MyNamespace.MyInterface) as MyNamespace.MyInterface
end function

end namespace

`);
program.validate();

expectZeroDiagnostics(program);
});

it('finds non-namespaced interface types', () => {
program.setFile({ src: s`${rootDir}/source/main.bs`, dest: s`source/main.bs` }, `
interface MyInterface
title as string
end interface

namespace MyNamespace
function bar(param as MyInterface) as MyInterface
end function

end namespace

`);
program.validate();

expectZeroDiagnostics(program);
});

it('finds enum types', () => {
program.setFile({ src: s`${rootDir}/source/main.bs`, dest: s`source/main.bs` }, `
namespace MyNamespace
enum MyEnum
title = "t"
end enum

function bar(param as MyNamespace.MyEnum) as MyNamespace.MyEnum
end function

end namespace

`);
program.validate();

expectZeroDiagnostics(program);
});

it('finds non-namespaced enum types', () => {
program.setFile({ src: s`${rootDir}/source/main.bs`, dest: s`source/main.bs` }, `
enum MyEnum
title = "t"
end enum

namespace MyNamespace
function bar(param as MyEnum) as MyEnum
end function

end namespace

`);
program.validate();

expectZeroDiagnostics(program);
});

it('finds custom types inside namespaces', () => {
program.setFile({ src: s`${rootDir}/source/main.bs`, dest: s`source/main.bs` }, `
namespace MyNamespace
Expand Down
2 changes: 1 addition & 1 deletion src/Scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ export class Scope {
// check if this custom type is in our class map
const returnTypeName = func.returnType.name;
const currentNamespaceName = func.namespaceName?.getName(ParseMode.BrighterScript);
if (!this.hasClass(returnTypeName, currentNamespaceName)) {
if (!this.hasClass(returnTypeName, currentNamespaceName) && !this.hasInterface(returnTypeName) && !this.hasEnum(returnTypeName)) {
this.diagnostics.push({
...DiagnosticMessages.invalidFunctionReturnType(returnTypeName),
range: func.returnTypeToken.range,
Expand Down