Skip to content

fix: compiler crashed when duplicate inner function declared in function body#3000

Open
Changqing-JING wants to merge 2 commits intoAssemblyScript:mainfrom
Changqing-JING:bugfix/2999
Open

fix: compiler crashed when duplicate inner function declared in function body#3000
Changqing-JING wants to merge 2 commits intoAssemblyScript:mainfrom
Changqing-JING:bugfix/2999

Conversation

@Changqing-JING
Copy link
Contributor

@Changqing-JING Changqing-JING commented Mar 26, 2026

Fixes #2999 .

Changes proposed in this pull request:


  • I've read the contributing guidelines
  • I've added my name and email to the NOTICE file

@Changqing-JING Changqing-JING changed the title fix: compiler crashed when duplicate inner function declared in funct… fix: compiler crashed when duplicate inner function declared in function body Mar 26, 2026
@Changqing-JING Changqing-JING marked this pull request as draft March 26, 2026 08:32
Comment on lines +7196 to +7199
this.error(
DiagnosticCode.Duplicate_identifier_0,
declaration.name.range, declaration.name.text
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.error(
DiagnosticCode.Duplicate_identifier_0,
declaration.name.range, declaration.name.text
);
this.error(
DiagnosticCode.Duplicate_function_implementation,
declaration.name.range
);

It will be match with TS error

Comment on lines +4 to +14
export function test(): void {
function inner(): i32 {
let x: i32 = 0;
return x;
}
function inner(): i32 {
let x: i32 = 0;
return x + 1;
}
inner();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simplify to:

Suggested change
export function test(): void {
function inner(): i32 {
let x: i32 = 0;
return x;
}
function inner(): i32 {
let x: i32 = 0;
return x + 1;
}
inner();
}
export function test(): void {
function inner(): void {}
function inner(): void {}
inner();
}

@MaxGraey
Copy link
Member

MaxGraey commented Mar 26, 2026

Can you also add this tests case?

export function testMixed(): void {
  const inner = function (): void {}
  function inner(): void {}
  inner();
}

In this case emit Duplicate identifier 'inner'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compiler crashed when duplicate inner function define in function body

2 participants