From f79888cb008d43215dff10948c9c029c0b7b1656 Mon Sep 17 00:00:00 2001 From: George Cook Date: Thu, 26 May 2022 14:28:23 +0200 Subject: [PATCH] fixes enums and interfaces resulting in diagnostics error when used as return types from a function --- src/Scope.spec.ts | 72 +++++++++++++++++++++++++++++++++++++++++++++++ src/Scope.ts | 2 +- 2 files changed, 73 insertions(+), 1 deletion(-) diff --git a/src/Scope.spec.ts b/src/Scope.spec.ts index a393b6959..620fac906 100644 --- a/src/Scope.spec.ts +++ b/src/Scope.spec.ts @@ -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 diff --git a/src/Scope.ts b/src/Scope.ts index fcdca37fe..b40509ae3 100644 --- a/src/Scope.ts +++ b/src/Scope.ts @@ -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,