Skip to content

Make constants inline val? #618

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
armanbilge opened this issue Oct 21, 2021 · 5 comments
Closed

Make constants inline val? #618

armanbilge opened this issue Oct 21, 2021 · 5 comments

Comments

@armanbilge
Copy link
Member

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

@armanbilge
Copy link
Member Author

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.

@armanbilge
Copy link
Member Author

armanbilge commented Oct 29, 2021

[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.

@armanbilge
Copy link
Member Author

armanbilge commented Oct 29, 2021

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.

@armanbilge armanbilge reopened this Oct 29, 2021
@armanbilge
Copy link
Member Author

armanbilge commented Oct 29, 2021

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")

@armanbilge
Copy link
Member Author

armanbilge commented Nov 1, 2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant