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

Getters are not control flow analysed #8437

Closed
tinganho opened this issue May 3, 2016 · 4 comments
Closed

Getters are not control flow analysed #8437

tinganho opened this issue May 3, 2016 · 4 comments
Assignees
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@tinganho
Copy link
Contributor

tinganho commented May 3, 2016

class A {
    private something: string;

    public get id(): string | null {
        return null;
    }

    public doSomethingUseful() {
        if (this.id) {
            this.something = this.id; // Error can be null
        }
    }
}
@ahejlsberg
Copy link
Member

I'm inclined to agree this is a bug, but obviously there's no guarantee that an accessor will return the same value the next time it is invoked. It's sort of akin to saying that if a function call foo() returns a truthy value, then we should assume it will also return a truthy value the next time it is called.

@mhegazy
Copy link
Contributor

mhegazy commented May 3, 2016

this is a bit too pedantic. For an interface property, there is no guarantee it was implemented as an accessor, so not sure why this would be any different.

@tinganho
Copy link
Contributor Author

tinganho commented May 3, 2016

Sorry, I actually missed that it was being called 2 times. But I think I agree with @ahejlsberg then.

@tinganho tinganho closed this as completed May 3, 2016
@ahejlsberg
Copy link
Member

Well, @mhegazy has a point too. I'm inclined to fix it, so I'm going to reopen the issue.

@ahejlsberg ahejlsberg reopened this May 3, 2016
@ahejlsberg ahejlsberg added the Bug A bug in TypeScript label May 3, 2016
@ahejlsberg ahejlsberg added this to the TypeScript 2.0 milestone May 3, 2016
@ahejlsberg ahejlsberg self-assigned this May 3, 2016
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label May 3, 2016
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 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

No branches or pull requests

3 participants