File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed
Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -7186,6 +7186,21 @@ export class Compiler extends DiagnosticEmitter {
71867186 let sourceFunction = flow . sourceFunction ;
71877187 let isNamed = declaration . name . text . length > 0 ;
71887188 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_identifier_0 ,
7198+ declaration . name . range , declaration . name . text
7199+ ) ;
7200+ return this . module . unreachable ( ) ;
7201+ }
7202+ }
7203+
71897204 let prototype = new FunctionPrototype (
71907205 isSemanticallyAnonymous
71917206 ? `${ isNamed ? declaration . name . text : "anonymous" } |${ sourceFunction . nextAnonymousId ++ } `
Original file line number Diff line number Diff line change 1+ {
2+ "asc_flags" : [],
3+ "stderr" : [
4+ " TS2300: Duplicate identifier 'inner'." ,
5+ " EOF"
6+ ]
7+ }
Original file line number Diff line number Diff line change 1+ // Duplicate named function declarations in the same scope should
2+ // produce a diagnostic instead of crashing the compiler.
3+
4+ export function test ( ) : void {
5+ function inner ( ) : i32 {
6+ let x : i32 = 0 ;
7+ return x ;
8+ }
9+ function inner ( ) : i32 {
10+ let x : i32 = 0 ;
11+ return x + 1 ;
12+ }
13+ inner ( ) ;
14+ }
15+
16+ ERROR ( "EOF" ) ;
You can’t perform that action at this time.
0 commit comments