Skip to content

Final local classes are emitted as non-local #4404

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
mbloms opened this issue Apr 28, 2018 · 2 comments
Closed

Final local classes are emitted as non-local #4404

mbloms opened this issue Apr 28, 2018 · 2 comments

Comments

@mbloms
Copy link
Contributor

mbloms commented Apr 28, 2018

It seems like the flags of Anonymous classes are somehow lost during compilation. Despite these lines in Typer.scala:

val x = tpnme.ANON_CLASS
val clsDef = TypeDef(x, templ1).withFlags(Final)

Anonymous classes are compiled without the public final.

Compiling this:

class Car
final class Volvo extends Car

object Car {
    val car = new Car {}
}

with dotc yields this:

$ dotc Anon.scala 
$ javap Car Volvo 'Car$$anon$1'
Compiled from "Anon.scala"
public class Car {
  public static Car car();
  public Car();
}
Compiled from "Anon.scala"
public final class Volvo extends Car {
  public Volvo();
}
Compiled from "Anon.scala"
class Car$$anon$1 extends Car {
  public Car$$anon$1();
}

scalac instead yields this:

$ scalac Anon.scala 
$ javap Car Volvo 'Car$$anon$1'
Compiled from "Anon.scala"
public class Car {
  public static Car car();
  public Car();
}
Compiled from "Anon.scala"
public final class Volvo extends Car {
  public Volvo();
}
Compiled from "Anon.scala"
public final class Car$$anon$1 extends Car {
  public Car$$anon$1();
}
@smarter smarter changed the title Anonymous classes are not final. Final local classes are emitted as non-local Apr 28, 2018
@smarter
Copy link
Member

smarter commented Apr 28, 2018

This also happen with non-anonymous local classes:

object Test {
  val x = {
    final class Foo
   }
}

This happens because LambdaLift drops the Final flag: https://github.com/lampepfl/dotty/blob/master/compiler/src/dotty/tools/dotc/transform/LambdaLift.scala#L344
This was added by commit 221320f @odersky do you recall why that change was done?

@allanrenucci
Copy link
Contributor

Why should an anonymous class and an inner class be public?

allanrenucci added a commit that referenced this issue Jul 20, 2018
Fix #4404: In LambdaLift, modify flags properly
nicolasstucki pushed a commit to dotty-staging/dotty that referenced this issue Jul 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants