Skip to content

Suggestion: errors based on control flow analysis #2176

Closed

Description

@rolyp

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.)

Activity

  1. CyrusNajmabadi commented on Mar 1, 2015

    @CyrusNajmabadi
    Contributor

    Roly Perera (@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 Vladimir Matveev (@vladima) has worked on some flow control language features to help surface this. See #1287 for more details.

  2. danquirk commented on Mar 2, 2015

    @danquirk
    Member

    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.

  3. added
    Suggestion
    In Discussion
    on Mar 2, 2015
  4. changed the title [-]Function with return type allowed not to return a value[/-] on Mar 2, 2015
  5. neilgalarneau commented on Mar 12, 2015

    @neilgalarneau

    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'.

  6. added
    Revisit
    and removed
    In Discussion
    on May 19, 2015
  7. RyanCavanaugh commented on May 19, 2015

    @RyanCavanaugh
    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.

  8. added
    In Discussion
    and removed
    Revisit
    on Nov 16, 2015
  9. added
    Fixed
    on Dec 9, 2015
  10. removed
    In Discussion
    on Dec 9, 2015
  11. mhegazy commented on Dec 9, 2015

    @mhegazy
    Contributor

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

  12. locked and limited conversation to collaborators on Jun 18, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FixedSuggestion

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions