Variable referenced before assignment is not detected when assigned later in the function
- Dominant language
- TypeScript
- Stars
- 193k
- Forks
- 42.4k
- PR merge metrics
- PR metrics pending
Description
## Variable referenced before assignment is not detected when assigned later in the function
Does this issue occur when all extensions are disabled?: No — Python diagnostics require the Python/Pylance extension.
Version: 1.135.0 (Universal)
Commit: 08d4889f9ec4a1685d257b9b95de036c8e1ce1e5
Date: 2026-08-25T14:26:52Z
Electron: 42.8.1
ElectronBuildId: 14906494
Chromium: 148.0.7778.280
Node.js: 24.18.1
V8: 14.8.178.38-electron.0
@github/copilot: 1.0.81-0
@github/copilot-sdk: 1.0.11
OS: Darwin arm64 25.6.0
## Description
VS Code/Pylance does not report that a local variable may be referenced before assignment when its assignment appears later in the same function.
## Steps to reproduce
1. Create a Python file containing:
```python
def generate_message(some_param):
try:
int(some_param)
except (ValueError, TypeError):
print(user)
return False
user = "test"
return user
```
2. Open the file in VS Code with the Python and Pylance extensions enabled.
3. Check the Problems panel and the `print(user)` statement.
4. Run:
```python
generate_message("invalid")
```
## Actual behavior
No problem is reported for `print(user)`.
At runtime, the function raises:
```text
UnboundLocalError: cannot access local variable 'user' where it is not associated with a value
Contributor guide
Assessment
This issue has not been assessed yet.