Skip to content

Commit

Permalink
Refactor hash* diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
TwitchBronBron committed Dec 13, 2024
1 parent 647be69 commit 26146be
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
13 changes: 8 additions & 5 deletions src/DiagnosticMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,31 +631,34 @@ export let DiagnosticMessages = {
message: '#const declarations can only have values of `true`, `false`, or other #const names',
legacyCode: 1089,
severity: DiagnosticSeverity.Error,
code: 'invalid-const-value'
code: 'invalid-hash-const-value'
}),
referencedConstDoesNotExist: () => ({
hashConstDoesNotExist: () => ({
message: `Referenced #const does not exist`,
legacyCode: 1090,
severity: DiagnosticSeverity.Error,
code: 'const-does-not-exist'
code: 'hash-const-does-not-exist'
}),
invalidHashIfValue: () => ({
message: `#if conditionals can only be 'true', 'false', or other #const names`,
legacyCode: 1091,
severity: DiagnosticSeverity.Error,
code: 'invalid-hash-if-value'
}),
/**
* Treat #error directives like diagnostics, because the presence of `#error` even inside a runtime logical block that evaluates to false will 100% cause a compile error.
*/
hashError: (message: string) => ({
message: `#error ${message} `,
legacyCode: 1092,
severity: DiagnosticSeverity.Error,
code: 'hash-error'
}),
expectedEqualAfterConstName: () => ({
__unused43: () => ({
message: `Expected '=' after #const`,
legacyCode: 1093,
severity: DiagnosticSeverity.Error,
code: 'expected-equal-after-const'
code: 'expected-equal-after-hash-const'
}),
__unused17: (startingLine: number) => ({
message: `Expected '#end if' to close '#if' conditional compilation statement starting on line ${startingLine} `,
Expand Down
2 changes: 1 addition & 1 deletion src/bscPlugin/validation/BrsFileValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ export class BrsFileValidator {
const isBool = ccConst.kind === TokenKind.True || ccConst.kind === TokenKind.False;
if (!isBool && !this.event.file.ast.bsConsts.has(ccConst.text.toLowerCase())) {
this.event.program.diagnostics.register({
...DiagnosticMessages.referencedConstDoesNotExist(),
...DiagnosticMessages.hashConstDoesNotExist(),
location: ccConst.location
});
return false;
Expand Down
4 changes: 2 additions & 2 deletions src/files/BrsFile.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ describe('BrsFile', () => {
`);
program.validate();
expectDiagnostics(program, [
DiagnosticMessages.referencedConstDoesNotExist()
DiagnosticMessages.hashConstDoesNotExist()
]);
});

Expand All @@ -758,7 +758,7 @@ describe('BrsFile', () => {
`);
program.validate();
expectDiagnostics(program, [
DiagnosticMessages.referencedConstDoesNotExist()
DiagnosticMessages.hashConstDoesNotExist()
]);
});

Expand Down
1 change: 0 additions & 1 deletion src/parser/tests/statement/Dim.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import type { DimStatement } from '../../Statement';
import { DiagnosticMessages } from '../../../DiagnosticMessages';
import { Parser } from '../../Parser';
import { expectDiagnostics } from '../../../testHelpers.spec';
import { TokenKind } from '../../../lexer/TokenKind';

describe('parser DimStatement', () => {
it('parses properly', () => {
Expand Down

0 comments on commit 26146be

Please sign in to comment.