Skip to content

Commit

Permalink
Fix namespace-relative enum value (#793)
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Apr 17, 2023
1 parent 71dfc03 commit 03825f0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<EnumMemberStatement> {
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();
Expand Down
2 changes: 1 addition & 1 deletion src/bscPlugin/validation/ScopeValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
17 changes: 17 additions & 0 deletions src/parser/tests/statement/Enum.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 03825f0

Please sign in to comment.