Skip to content

Commit

Permalink
fixes enums and interfaces resulting in diagnostics error when used a…
Browse files Browse the repository at this point in the history
…s return types from a function (#601)
  • Loading branch information
georgejecook authored May 26, 2022
1 parent 806c0f2 commit 6b56ec3
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 1 deletion.
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

0 comments on commit 6b56ec3

Please sign in to comment.