Skip to content

Widen type of final vars #1285 #1348

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

Closed
wants to merge 1 commit into from

Conversation

jvican
Copy link
Member

@jvican jvican commented Jul 1, 2016

Addresses #1285.

When defining a final var, the type is not widened and, thus, it's as
specific as possible. However, when changing the value of the var, it
will give a compilation error because the constant types don't match.
This fix widens the type whenever it finds a final var.

When defining a final var, the type is not widened and, thus, it's as
specific as possible. However, when changing the value of the var, it
will give a compilation error because it cannot match the constant
types. This fix widens the type whenever it finds a final var.
@smarter
Copy link
Member

smarter commented Jul 1, 2016

I don't think this is the only thing that needs to be done to fix #1285. In the issue comments we determined that var and final var have (or at least should have) the exact same semantics, so we should either always set the Final flag on var or never set it, but setting it some of the time and then ignoring it doesn't make sense. In either case we should also warn the user when they write final var that they should just write var

}
vdef
}

/** Add a @volitile to lazy vals when rewriting from Scala2 */
private def patchIfLazy(vdef: ValDef)(implicit ctx: Context): Unit = {
Copy link
Contributor

Choose a reason for hiding this comment

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

There's a simpler way to do it. In Namer.scala

  def isInline = sym.is(Final, butNot = Method)

We just need to exclude Mutable here. E.g.

  def isInline = sym.is(Final, butNot = Method | Mutable)

@nicolasstucki
Copy link
Contributor

You could change the commit message to Fix #1285: Widen type of final vars. to follow the GitHub conventions.

@odersky
Copy link
Contributor

odersky commented Jul 31, 2016

Superseded by #1428

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.

6 participants