diff --git a/src/Scope.ts b/src/Scope.ts index 58d923332..2f1e3cc6d 100644 --- a/src/Scope.ts +++ b/src/Scope.ts @@ -165,7 +165,7 @@ export class Scope { * @param containingNamespace - The namespace used to resolve relative enum names. (i.e. the namespace around the current statement trying to find a enum) */ public getEnumMemberFileLink(enumMemberName: string, containingNamespace?: string): FileLink { - let lowerNameParts = enumMemberName?.split('.'); + let lowerNameParts = enumMemberName?.toLowerCase()?.split('.'); let memberName = lowerNameParts?.splice(lowerNameParts.length - 1, 1)?.[0]; let lowerName = lowerNameParts?.join('.').toLowerCase(); const enumMap = this.getEnumMap(); diff --git a/src/bscPlugin/validation/ScopeValidator.ts b/src/bscPlugin/validation/ScopeValidator.ts index 49e658b79..0b7b9a103 100644 --- a/src/bscPlugin/validation/ScopeValidator.ts +++ b/src/bscPlugin/validation/ScopeValidator.ts @@ -125,7 +125,7 @@ export class ScopeValidator { entityNameLower += '.' + part.name.text.toLowerCase(); //if this is an enum member, stop validating here to prevent errors further down the chain - if (scope.getEnumMemberMap().has(entityNameLower)) { + if (scope.getEnumMemberFileLink(entityName, info.enclosingNamespaceNameLower)) { break; } diff --git a/src/parser/tests/statement/Enum.spec.ts b/src/parser/tests/statement/Enum.spec.ts index 682f1f1b2..80299ae79 100644 --- a/src/parser/tests/statement/Enum.spec.ts +++ b/src/parser/tests/statement/Enum.spec.ts @@ -602,6 +602,23 @@ describe('EnumStatement', () => { `); }); + it('recognizes namespace-relative enums', () => { + program.setFile('source/main.bs', ` + namespace MyNamespace + enum MyEnum + val1 + val2 + end enum + + function foo() as integer + return MyEnum.val1 + end function + end namespace + `); + program.validate(); + expectZeroDiagnostics(program); + }); + it('replaces enum values from separate file with literals', () => { program.setFile('source/enum.bs', ` enum CharacterType