scala-js/scala-js-dom

Make constants `inline val`?

armanbilge opened this issue · 5 comments

Came up in #592 (comment). H/t @smarter. The question is if we can make this change binary-compatibly.

In another project I tried inline valing an opaque type and got

inline value must have a literal constant type

So, I'm not sure this will work.

[error] -- Error: /workspace/scala-js-dom/dom/src/main/scala-3/org/scalajs/dom/AppendMode.scala:6:23 
[error] 6 |  inline val segments: AppendMode = "segments"
[error]   |                       ^^^^^^^^^^
[error]   |                       inline value must have a literal constant type

Closing unless somebody knows a workaround.

Aha! This works.

package org.scalajs.dom

opaque type AppendMode <: String = String

object AppendMode {
  opaque type segments <: AppendMode = "segments"
  inline val segments: segments = "segments"
  val sequence: AppendMode = "sequence"
}

So, now its the bincompat question again.

Well, darn.

[error] dom: Failed binary compatibility check against org.scala-js:scalajs-dom_sjs1_3:2.0.0! Found 1 potential problems
[error]  * method segments()java.lang.String in object org.scalajs.dom.AppendMode#package#AppendMode does not have a correspondent in current version
[error]    filter with: ProblemFilters.exclude[DirectMissingMethodProblem]("org.scalajs.dom.AppendMode#package#AppendMode.segments")

Turns out this was never going to work anyway. See: