Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix namespace-relative enum value #793

Merged
merged 1 commit into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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