Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Suggestion: errors based on control flow analysis #2176

Closed
rolyp opened this issue Mar 1, 2015 · 5 comments
Closed

Suggestion: errors based on control flow analysis #2176

rolyp opened this issue Mar 1, 2015 · 5 comments
Labels
Fixed A PR has been merged for this issue Suggestion An idea for TypeScript

Comments

@rolyp
Copy link

rolyp commented Mar 1, 2015

What, all this business with union types, indeed a veritable managerie of type-related tricks, and we can't make the basics work?

function borked(): number {
    if (false)
        return 1;
}

I know this will be flagged with the dreaded "By Design", because of some silly JavaScript use case that I can't imagine, but it's such an obviously wrong feature of the language that I can't help raising as an issue. (Apologies if it's a duplicate.)

@CyrusNajmabadi
Copy link
Contributor

@rolyp "but it's such an obviously wrong feature of the language". I don't believe there's any consensus that this is the case.

Note that @vladima has worked on some flow control language features to help surface this. See #1287 for more details.

@danquirk
Copy link
Member

danquirk commented Mar 2, 2015

As Cyrus notes, we're considering control flow analysis additions that would catch cases like this, but there are tradeoffs. I don't see an actual issue tracking this so I'll just rename this and Vlad's PR can be associated with it now.

@danquirk danquirk added Suggestion An idea for TypeScript In Discussion Not yet reached consensus labels Mar 2, 2015
@danquirk danquirk changed the title Function with return type allowed not to return a value Suggestion: errors based on control flow analysis Mar 2, 2015
@neilgalarneau
Copy link

Lots of us would want that code to cause an error.

I submitted #2316 which is more general than function borked() above, as a concrete sub-class of 'all errors that could be detected through control flow analysis'.

@RyanCavanaugh RyanCavanaugh added Revisit An issue worth coming back to and removed In Discussion Not yet reached consensus labels May 19, 2015
@RyanCavanaugh
Copy link
Member

We want to revisit all these control flow things after 2.0 ships. It's a high-value area we want to invest in, but there's no room left in the schedule for something as large in scope as this.

@mhegazy mhegazy added In Discussion Not yet reached consensus and removed Revisit An issue worth coming back to labels Nov 16, 2015
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Dec 9, 2015
@mhegazy mhegazy added this to the TypeScript 1.8 milestone Dec 9, 2015
@mhegazy mhegazy removed the In Discussion Not yet reached consensus label Dec 9, 2015
@mhegazy
Copy link
Contributor

mhegazy commented Dec 9, 2015

This should be reported as an error now with --noImplicitReturns

@mhegazy mhegazy closed this as completed Dec 9, 2015
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
Fixed A PR has been merged for this issue Suggestion An idea for TypeScript
Projects
None yet
Development

No branches or pull requests

6 participants