Skip to content

Commit eb3fd24

Browse files
authored
fix(codegen): native compiler segfaulted on every emitError path because emitError chained getErrors() twice per expression — extract to intermediate vars and add module-scope Date fixtures (#521)
Co-authored-by: cs01 <cs01@users.noreply.github.com>
1 parent 3e8f803 commit eb3fd24

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

src/codegen/llvm-generator.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,9 @@ export class LLVMGenerator extends BaseGenerator implements IGeneratorContext {
332332

333333
public emitError(message: string, loc?: SourceLocation, suggestion?: string): never {
334334
this.diagnostics.error(message, loc, suggestion);
335-
const output = this.diagnostics.formatDiagnostic(
336-
this.diagnostics.getErrors()[this.diagnostics.getErrors().length - 1],
337-
);
335+
const errs = this.diagnostics.getErrors();
336+
const last = errs[errs.length - 1];
337+
const output = this.diagnostics.formatDiagnostic(last);
338338
process.stderr.write(output);
339339
process.exit(1);
340340
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// @test-compile-error: cannot determine type of module-scope variable
2+
// @test-description: new Date() at module scope emits clean compile error instead of segfault
3+
const d = new Date();
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// @test-compile-error: cannot determine type of module-scope variable
2+
// @test-description: new Date(0) at module scope emits clean compile error instead of segfault
3+
const d = new Date(0);

0 commit comments

Comments
 (0)