-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Error on types named "undefined" #57575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
358ab6e
Add test
jakebailey 9fed7d1
New error
jakebailey 328be7b
Oops
jakebailey 6206462
Oops
jakebailey b376d0b
Error like other keywords, though undefined is not a keyword
jakebailey f8db707
Restore global
jakebailey ebd8d1c
new testing
jakebailey 3cfbd1a
reduce errors
jakebailey 115c0c5
baselines
jakebailey 0ecbb81
slightly better
jakebailey e82dde6
namespaces
jakebailey e777ac6
baseline
jakebailey 70973bb
baseline
jakebailey 886a41e
Revert namespace
jakebailey 7b80d7a
Eliminate builtinGlobals
jakebailey 49fa5c2
Small comment tweak to reflect final state
jakebailey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Restore global
- Loading branch information
commit f8db7074ce3c63479343de81cc19f9e709ca122b
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1473,7 +1473,6 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
var globals = createSymbolTable(); | ||
var undefinedSymbol = createSymbol(SymbolFlags.Property, "undefined" as __String); | ||
undefinedSymbol.declarations = []; | ||
globals.set(undefinedSymbol.escapedName, undefinedSymbol); | ||
|
||
var globalThisSymbol = createSymbol(SymbolFlags.Module, "globalThis" as __String, CheckFlags.Readonly); | ||
globalThisSymbol.exports = globals; | ||
|
@@ -2256,6 +2255,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
var identityRelation = new Map<string, RelationComparisonResult>(); | ||
var enumRelation = new Map<string, RelationComparisonResult>(); | ||
|
||
var builtinGlobals = createSymbolTable(); | ||
builtinGlobals.set(undefinedSymbol.escapedName, undefinedSymbol); | ||
|
||
// Extensions suggested for path imports when module resolution is node16 or higher. | ||
// The first element of each tuple is the extension a file has. | ||
// The second element of each tuple is the extension that should be used in a path import. | ||
|
@@ -2718,6 +2720,23 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
} | ||
} | ||
|
||
function addToSymbolTable(target: SymbolTable, source: SymbolTable, message: DiagnosticMessage) { | ||
source.forEach((sourceSymbol, id) => { | ||
const targetSymbol = target.get(id); | ||
if (targetSymbol) { | ||
// Error on redeclarations | ||
forEach(targetSymbol.declarations, addDeclarationDiagnostic(unescapeLeadingUnderscores(id), message)); | ||
} | ||
else { | ||
target.set(id, sourceSymbol); | ||
} | ||
}); | ||
|
||
function addDeclarationDiagnostic(id: string, message: DiagnosticMessage) { | ||
return (declaration: Declaration) => diagnostics.add(createDiagnosticForNode(declaration, message, id)); | ||
} | ||
} | ||
|
||
function getSymbolLinks(symbol: Symbol): SymbolLinks { | ||
if (symbol.flags & SymbolFlags.Transient) return (symbol as TransientSymbol).links; | ||
const id = getSymbolId(symbol); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I opted to eliminate builtinGlobals while here; its only use is to complain about undefined, but now we're going to complain even less and the new code had to exclude type declarations anyway. |
||
|
@@ -48777,6 +48796,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { | |
} | ||
} | ||
|
||
// Setup global builtins | ||
addToSymbolTable(globals, builtinGlobals, Diagnostics.Declaration_name_conflicts_with_built_in_global_identifier_0); | ||
|
||
getSymbolLinks(undefinedSymbol).type = undefinedWideningType; | ||
getSymbolLinks(argumentsSymbol).type = getGlobalType("IArguments" as __String, /*arity*/ 0, /*reportErrors*/ true); | ||
getSymbolLinks(unknownSymbol).type = errorType; | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
tests/baselines/reference/undefinedTypeAssignment2.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
undefinedTypeAssignment2.ts(1,5): error TS2300: Duplicate identifier 'undefined'. | ||
undefinedTypeAssignment2.ts(1,5): error TS2397: Declaration name conflicts with built-in global identifier 'undefined'. | ||
|
||
|
||
==== undefinedTypeAssignment2.ts (1 errors) ==== | ||
var undefined = void 0; | ||
~~~~~~~~~ | ||
!!! error TS2300: Duplicate identifier 'undefined'. | ||
!!! error TS2397: Declaration name conflicts with built-in global identifier 'undefined'. | ||
|
4 changes: 2 additions & 2 deletions
4
tests/baselines/reference/undefinedTypeAssignment3.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
undefinedTypeAssignment3.ts(1,5): error TS2300: Duplicate identifier 'undefined'. | ||
undefinedTypeAssignment3.ts(1,5): error TS2397: Declaration name conflicts with built-in global identifier 'undefined'. | ||
|
||
|
||
==== undefinedTypeAssignment3.ts (1 errors) ==== | ||
var undefined = null; | ||
jakebailey marked this conversation as resolved.
Show resolved
Hide resolved
|
||
~~~~~~~~~ | ||
!!! error TS2300: Duplicate identifier 'undefined'. | ||
!!! error TS2397: Declaration name conflicts with built-in global identifier 'undefined'. | ||
|
12 changes: 6 additions & 6 deletions
12
tests/baselines/reference/undefinedTypeAssignment4.errors.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.