Skip to content

CFA does not consider pass-by-reference to invalidate assumptions #61416

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

Closed
Sainan opened this issue Mar 13, 2025 · 3 comments
Closed

CFA does not consider pass-by-reference to invalidate assumptions #61416

Sainan opened this issue Mar 13, 2025 · 3 comments
Labels
Duplicate An existing issue was already created

Comments

@Sainan
Copy link

Sainan commented Mar 13, 2025

πŸ”Ž Search Terms

control flow analysis, branch, condition

πŸ•— Version & Regression Information

Tested in 5.8.2.

⏯ Playground Link

https://www.typescriptlang.org/play/?noUncheckedIndexedAccess=true#code/JYOwLgpgTgZghgYwgAgBIFcC2cTIN4BQyycA5hAPwBcyIWARtANwEC+BBM6ICYwA9rgSCAzlggAKfvQBWNDNhABKfEWTSZAOjIoAvMm4ATCDFARDLdgWEgRYdbPlYcyfXhLkaAFgBMyVizAMMhSstrkKoTENmKYkhpKLNGi9jo0dJiMUK4OWjpMyAD0hcgAcvypuNBQ-FBsBEA

πŸ’» Code

interface Human {
  age?: number;
}

function consume(obj: Human) {
  obj.age = undefined;
}

const obj: Human = { age: 42 };
if (obj.age) {
  consume(obj);
  const age: number = obj.age; // Not an error
}

πŸ™ Actual behavior

Assignment of const age: number succeeds with undefined.

πŸ™‚ Expected behavior

obj.age is assessed as number | undefined, causing the assignment to fail.

Additional information about the issue

No response

@nmain
Copy link

nmain commented Mar 13, 2025

Duplicate of #9998

@Sainan
Copy link
Author

Sainan commented Mar 13, 2025

Fair, although in this case the function is not a black box.

@RyanCavanaugh RyanCavanaugh added the Duplicate An existing issue was already created label Mar 13, 2025
@typescript-bot
Copy link
Collaborator

This issue has been marked as "Duplicate" and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot typescript-bot closed this as not planned Won't fix, can't repro, duplicate, stale Mar 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate An existing issue was already created
Projects
None yet
Development

No branches or pull requests

4 participants