Skip to content

Fix #2368: local variables must be initialized #2423

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

Merged
merged 1 commit into from
May 12, 2017

Conversation

abeln
Copy link
Contributor

@abeln abeln commented May 12, 2017

Disallow var declarations initialized to a placholder, if
the var declaration is local.

var x: Foo = _ is still allowed in fields.

Testing

Added tests for both invariants above.

@DarkDimius
Copy link
Contributor

DarkDimius commented May 12, 2017

As this is not dirrectly related to typing, I'd propose to move the check to RefChecks. This is a phase that implements a lot of sanity checks that could be factored out from typer.

The general approach looks good to me.
Thanks for your contribution!

@smarter
Copy link
Member

smarter commented May 12, 2017

Honestly, I'd rather have more checks early if possible instead of doing them in RefChecks, unless we manage to move RefChecks earlier. In the IDE I currently run with -Ystop-after:frontend to give faster feedback to the user, if I wanted to include RefChecks I'd have to run 3 more groups of phases.

@smarter
Copy link
Member

smarter commented May 12, 2017

Another benefit of doing the check in the typer is that these checks will be done when retyping (either in Erasure or Ycheck), which could catch issues.

@DarkDimius
Copy link
Contributor

@smarter, I think we should just have an entirely separate pipeline for IDE and run it until erasure(this pipeline won't include sbt related phases, Pickler and other phases that don't report errors). There are important errors that only get reported by erasure.

Disallow var declarations initialized to a placholder, if
the var declaration is local.

`var x: Foo = _` is still allowed in fields.

Testing
=======
Added tests for both invariants above.
@smarter
Copy link
Member

smarter commented May 12, 2017

Yes, that might be a good idea. Though for Erasure for example, I wonder if we could avoid running the whole phase and just check signatures to avoid methods with the same erased signature, etc.

@abeln
Copy link
Contributor Author

abeln commented May 12, 2017

Sounds like there's consensus for leaving the check in refchecks, then? Moved it there. PTAL.

Copy link
Contributor

@DarkDimius DarkDimius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@DarkDimius DarkDimius merged commit 11e2526 into scala:master May 12, 2017
@abeln abeln deleted the local-var branch May 12, 2017 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants