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 field types
  • Loading branch information
georgejecook committed May 26, 2022
1 parent 7a40966 commit cd51b36
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions src/Scope.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,25 @@ describe('Scope', () => {
]);
});

it('supports enums and interfaces as types', () => {
program.setFile({ src: s`${rootDir}/source/main.bs`, dest: s`source/main.bs` }, `
interface MyInterface
title as string
end interface
enum myEnum
title = "t"
end enum
class myClass
foo as myInterface
foo2 as myEnum
end class
`);
program.validate();
expectZeroDiagnostics(program);
});

it('finds interface types', () => {
program.setFile({ src: s`${rootDir}/source/main.bs`, dest: s`source/main.bs` }, `
namespace MyNamespace
Expand Down
2 changes: 1 addition & 1 deletion src/validators/ClassValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export class BsClassValidator {
if (lowerFieldTypeName) {
const currentNamespaceName = classStatement.namespaceName?.getName(ParseMode.BrighterScript);
//check if this custom type is in our class map
if (!this.getClassByName(lowerFieldTypeName, currentNamespaceName)) {
if (!this.getClassByName(lowerFieldTypeName, currentNamespaceName) && !this.scope.hasInterface(lowerFieldTypeName) && !this.scope.hasEnum(lowerFieldTypeName)) {
this.diagnostics.push({
...DiagnosticMessages.cannotFindType(fieldTypeName),
range: statement.type.range,
Expand Down

0 comments on commit cd51b36

Please sign in to comment.