Skip to content
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

[Errors] No error for function with return type annotation that lacks a return statement #62

Closed
mhegazy opened this issue Jul 17, 2014 · 3 comments · Fixed by #147
Closed
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@mhegazy
Copy link
Contributor

mhegazy commented Jul 17, 2014

Code (should have an error):

function fn(): string {
}
@mhegazy mhegazy added this to the TypeScript 1.1 milestone Jul 17, 2014
DanielRosenwasser added a commit that referenced this issue Jul 18, 2014
In effect this fixes #62.

Also
    - Changes the error message for get accessors lacking return expressions.
    - Actually checks for return expressions instead of return statements for get-accessors.
    - Removes fancy quotes.
    - Corrects errors in the compiler caught by the new check.
    - Simplified `checkAndAggregateReturnTypes` by extracting it out to `visitReturnStatements`.
DanielRosenwasser added a commit that referenced this issue Jul 18, 2014
In effect this fixes #62.

Also
    - Changes the error message for get accessors lacking return expressions.
    - Actually checks for return expressions instead of return statements for get-accessors.
    - Removes fancy quotes.
    - Corrects errors in the compiler caught by the new check.
    - Simplified `checkAndAggregateReturnTypes` by extracting it out to `visitReturnStatements`.
@RyanCavanaugh
Copy link
Member

Per CR comments, the fix breaks this (bad) code from 1.0:

class C { get f() { return; } }

@DanielRosenwasser
Copy link
Member

To be clear, the old compiler was okay with

function foo(): number {
    return;
}

as well.

Well, I wouldn't say that fixing this bug is a breaking change; rather, I misunderstood the issue with this bug in Pull Request #147. I thought that we should be looking for return expressions rather than statements; however, I think it's worth asking if that's the correct behavior.

@DanielRosenwasser
Copy link
Member

I've opened up #162 to discuss this.

DanielRosenwasser added a commit that referenced this issue Jul 21, 2014
In effect this fixes #62.

Also
    - Changes the error message for get accessors lacking return expressions.
    - Actually checks for return expressions instead of return statements for get-accessors.
    - Removes fancy quotes.
    - Corrects errors in the compiler caught by the new check.
    - Simplified `checkAndAggregateReturnTypes` by extracting it out to `visitReturnStatements`.
DanielRosenwasser added a commit that referenced this issue Jul 21, 2014
In effect this fixes #62.

Also
    - Changes the error message for get accessors lacking return expressions.
    - Actually checks for return expressions instead of return statements for get-accessors.
    - Removes fancy quotes.
    - Corrects errors in the compiler caught by the new check.
    - Simplified `checkAndAggregateReturnTypes` by extracting it out to `visitReturnStatements`.
@microsoft microsoft locked and limited conversation to collaborators Jun 18, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants