Skip to content
Open
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
3 changes: 2 additions & 1 deletion src/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1574,7 +1574,8 @@ export class Compiler extends DiagnosticEmitter {
/** Force compilation of stdlib alternative if a builtin. */
forceStdAlternative: bool = false
): bool {
if (instance.is(CommonFlags.Compiled)) return !instance.is(CommonFlags.Errored);
if (instance.is(CommonFlags.Errored)) return false;
if (instance.is(CommonFlags.Compiled)) return true;

if (!forceStdAlternative) {
if (instance.hasDecorator(DecoratorFlags.Builtin)) return true;
Expand Down
10 changes: 9 additions & 1 deletion src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3850,7 +3850,15 @@ export class Function extends TypedElement {
flow.setLocalFlag(local.index, LocalFlags.Initialized);
}
}
registerConcreteElement(program, this);
if (program.instancesByName.has(this.internalName)) {
program.error(
DiagnosticCode.Duplicate_function_implementation,
prototype.declaration.name.range
);
this.set(CommonFlags.Errored);
} else {
registerConcreteElement(program, this);
}
}

/** Gets the types of additional locals that are not parameters. */
Expand Down
8 changes: 8 additions & 0 deletions tests/compiler/duplicate-function-in-scope.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"asc_flags": [],
"stderr": [
"EOF",
"TS2300: Duplicate identifier 'inner'.",
"TS2393: Duplicate function implementation."
]
}
16 changes: 16 additions & 0 deletions tests/compiler/duplicate-function-in-scope.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Duplicate named function declarations in the same scope should
// produce a diagnostic instead of crashing the compiler.

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

export function test(): void {
function inner(): void {}
function inner(): void {}
inner();
}

ERROR("EOF");
Loading