Skip to content

[scala.js] Dotty does not produce null/undefined property on anonymous class #14168

Closed
@exoego

Description

@exoego

Compiler version

3.1.0

Minimized code

  • With Scala.js 1.8.0
trait Foo extends js.Object {
  var extra: js.UndefOr[String]
}

val anon1 = new js.Object() {
  var extra = "a"
}
val anon2 = new js.Object() {
  var extra = js.undefined
}
val anon3 = new js.Object() {
  var extra = null
}
val foo1 = new Foo {
   var extra = "a"
}
val foo2 = new Foo {
  var extra: js.UndefOr[String] = js.undefined
}
val foo3 = new Foo {
  var extra: js.UndefOr[String] = null
}
println(js.Object.hasProperty(anon1, "extra"))
println(js.Object.hasProperty(anon2, "extra"))
println(js.Object.hasProperty(anon3, "extra"))
println(js.Object.hasProperty(foo1, "extra"))
println(js.Object.hasProperty(foo2, "extra"))
println(js.Object.hasProperty(foo3, "extra"))

Output

On Scala 2.13.7 and 2.12.15,

true
true
true
true
true
true

However on Scala 3.1.0,

true
false
false
true
true
true

which means null or undefined property on anonymous class is missing.

val foo2 = new Foo {
  var extra: js.UndefOr[String] = js.undefined
}
val foo3 = new Foo {
  var extra: js.UndefOr[String] = null
}

Expectation

All properties should exist even if its value is null or undefined.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions