Skip to content

Commit 59a1ef8

Browse files
Fix review
1 parent 70e42c3 commit 59a1ef8

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

src/compiler.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,6 +1575,7 @@ export class Compiler extends DiagnosticEmitter {
15751575
forceStdAlternative: bool = false
15761576
): bool {
15771577
if (instance.is(CommonFlags.Compiled)) return !instance.is(CommonFlags.Errored);
1578+
if (instance.is(CommonFlags.Errored)) return false;
15781579

15791580
if (!forceStdAlternative) {
15801581
if (instance.hasDecorator(DecoratorFlags.Builtin)) return true;
@@ -7186,21 +7187,6 @@ export class Compiler extends DiagnosticEmitter {
71867187
let sourceFunction = flow.sourceFunction;
71877188
let isNamed = declaration.name.text.length > 0;
71887189
let isSemanticallyAnonymous = !isNamed || contextualType != Type.void;
7189-
7190-
// Check for duplicate named function declarations before creating the
7191-
// prototype, since registering a concrete element with a duplicate
7192-
// internalName would trigger an assertion error.
7193-
if (!isSemanticallyAnonymous) {
7194-
let existingLocal = flow.getScopedLocal(declaration.name.text);
7195-
if (existingLocal) {
7196-
this.error(
7197-
DiagnosticCode.Duplicate_function_implementation,
7198-
declaration.name.range
7199-
);
7200-
return this.module.unreachable();
7201-
}
7202-
}
7203-
72047190
let prototype = new FunctionPrototype(
72057191
isSemanticallyAnonymous
72067192
? `${isNamed ? declaration.name.text : "anonymous"}|${sourceFunction.nextAnonymousId++}`

src/program.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3850,7 +3850,15 @@ export class Function extends TypedElement {
38503850
flow.setLocalFlag(local.index, LocalFlags.Initialized);
38513851
}
38523852
}
3853-
registerConcreteElement(program, this);
3853+
if (program.instancesByName.has(this.internalName)) {
3854+
program.error(
3855+
DiagnosticCode.Duplicate_function_implementation,
3856+
prototype.declaration.name.range
3857+
);
3858+
this.set(CommonFlags.Errored);
3859+
} else {
3860+
registerConcreteElement(program, this);
3861+
}
38543862
}
38553863

38563864
/** Gets the types of additional locals that are not parameters. */

tests/compiler/duplicate-function-in-scope.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"asc_flags": [],
33
"stderr": [
44
"EOF",
5+
"TS2300: Duplicate identifier 'inner'.",
56
"TS2393: Duplicate function implementation."
67
]
78
}

tests/compiler/duplicate-function-in-scope.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
// Duplicate named function declarations in the same scope should
22
// produce a diagnostic instead of crashing the compiler.
33

4+
export function testMixed1(): void {
5+
const inner = function (): void {};
6+
function inner(): void {}
7+
inner();
8+
}
9+
410
export function test(): void {
511
function inner(): void {}
612
function inner(): void {}

0 commit comments

Comments
 (0)