Skip to content

Using nn without -Yexplicit-nulls Crashes in RC1 but not M3 #11631

Closed
@AugustNagro

Description

@AugustNagro

Compiler version

3.0.0-RC1

(No crash in 3.0.0-M3)

Minimized code

trait MyTrait:
  def a(): String = ""

class MyClass:
  var myTrait: MyTrait|Null = null

  def printA(): Unit = println(myTrait.nn.a())

@main def runTest(): Unit =
  val mt = new MyTrait:
    override def a(): String = "hello world"

  val mc = MyClass()
  mc.myTrait = mt
  mc.printA()

Output

undefined: {
  val x$proxy1: (MyTrait | Null) = this.myTrait
  (scala.runtime.Scala3RunTime.nn[MyTrait](x$proxy1):x$proxy1.type & MyTrait)
}.a # -1: TermRef(OrType(TypeRef(ThisType(TypeRef(NoPrefix,module class <empty>)),trait MyTrait),TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),class Null)),a) at inlining

Enabling explicit nulls fixes this, but I think the program should still compile. I ran into this problem when making an (encapsulated) Scala.js Web Component. Web Components may only have 0-arg constructors.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions