Skip to content

Aliased Unit improperly boxed #24653

@som-snytt

Description

@som-snytt

Compiler version

3.7.4

Minimized code

  snips cat predef.scala
package p

object MyPredef {
  type Unit = scala.Unit
}
  snips cat no-unit-main.scala
//> using options -Yimports:java.lang,scala,p.MyPredef
///> using options -Yimports:java.lang,scala

trait Main {
  def main(args: Array[String]): Unit = Console.println("hello, world")
}

object Test extends Main

Output

  snips scala-cli compile --server=false -S 3.7.4 -d /tmp -Yno-imports predef.scala
WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::objectFieldOffset has been called by scala.runtime.LazyVals$ (file:/home/amarki/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.7.4/scala3-library_3-3.7.4.jar)
WARNING: Please consider reporting this to the maintainers of class scala.runtime.LazyVals$
WARNING: sun.misc.Unsafe::objectFieldOffset will be removed in a future release
  snips scala-cli run --server=false -S 3.7.4 -Vprint:eras -d /tmp -cp /tmp no-unit-main.scala
WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::objectFieldOffset has been called by scala.runtime.LazyVals$ (file:/home/amarki/.cache/coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala3-library_3/3.7.4/scala3-library_3-3.7.4.jar)
WARNING: Please consider reporting this to the maintainers of class scala.runtime.LazyVals$
WARNING: sun.misc.Unsafe::objectFieldOffset will be removed in a future release
[[syntax trees at end of                   erasure]] // /home/amarki/snips/no-unit-main.scala
package <empty> {
  @SourceFile("no-unit-main.scala") trait Main() extends Object {
    def main(args: String[]): scala.runtime.BoxedUnit =
      {
        Console.println("hello, world")
        scala.runtime.BoxedUnit.UNIT
      }
  }
  final lazy module val Test: Test = new Test()
  @SourceFile("no-unit-main.scala") final module class Test() extends Object(),
    Main {
    private def writeReplace(): Object =
      new scala.runtime.ModuleSerializationProxy(classOf[Test])
  }
}

[error]  No main class found

Expectation

  snips scala-cli compile --server=false -S 2.13.17 -d /tmp -Yno-imports predef.scala
  snips scala-cli run --server=false -S 2.13.17 -Vprint:eras -d /tmp -cp /tmp no-unit-main.scala
[[syntax trees at end of                   erasure]] // no-unit-main.scala
package <empty> {
  abstract trait Main extends Object {
    def /*Main*/$init$(): Unit = {
      ()
    };
    def main(args: Array[String]): Unit = scala.Console.println("hello, world")
  };
  object Test extends Object with Main {
    def <init>(): Test.type = {
      Test.super.<init>();
      Test.super./*Main*/$init$();
      ()
    }
  }
}

hello, world

Noticed at https://users.scala-lang.org/t/inheriting-def-main/12139/6?u=som-snytt

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions