[scala.js] Dotty does not produce null/undefined property on anonymous class
See original GitHub issueCompiler 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
.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7 (5 by maintainers)
Top Results From Across the Web
Announcing Scala.js 1.3.1
Nov 16, 2020. We are pleased to announce the release of Scala.js 1.3.1! This release fixes the performance issues of the ECMAScript 2015 ......
Read more >Implementing Scala.js Support for Scala 3
This post explores how Scala.js is implemented, and not so much how it is used, ... Not all compile-to-JS languages have that property!...
Read more >A Beginner's Guide to Scala 3.0 - Morioh
In this post, we will get a teaser of what changes to expect from Dotty as ... Rememeber that a function in javascript...
Read more >Content - 3811e52cdfcda707d47b0ed2f8fb560e94e67923
doubleValue = this.value * 2; }; } }); ``` If you don't have time to migrate the code at the moment, you can...
Read more >Overview - TypeScript
Additionally, generators just assumed the type of yield was always any . ... Property 'answer' does not exist on 'typeof globalThis'.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This appears to happen only when the type of the
var
isUnit
orNull
(whether inferred, or explicitly written). It does not seem to be related to having a supertrait, since I can also reproduce the issue when the trait declares the member but the class implements it with a more specific type that is explicitlyNull
orUnit
.Also, I can reproduce this with a named class, local or top-level. So it’s also not related to anonymous classes.
The situations where this issue pops up are therefore summarized as:
Unit
orNull
in a non-native JS class.@sjrd I also hit this issue when trying to implement an object comparison method like deepEquals(jsObjectA, jsObjectB) in Scala 3 + Scala.js.