Scala 3:使用实验类型
以下Scala 3代码以下文档效果很好
import scala.compiletime.ops.string.*
@main def refinedTypeInAction: Unit =
val hello: "hello " + "world" = "hello world"
println(hello)
,但是,下面的一个
import scala.annotation.experimental
@experimental
object UseExperimental:
def x: scala.compiletime.ops.string.Substring["hamburger", 4, 8] = "urge"
列出了编译时间错误,如下所示,
[error] -- [E008] Not Found Error: /Users/viswanath/projects/myproject/src/main/scala/RefinedType.scala:16:38
[error] 16 | def x: scala.compiletime.ops.string.Substring["hamburger", 4, 8] = "urge"
[error] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error] | type Substring is not a member of object scala.compiletime.ops.string
[error] one error found
我确实指的是 https://docs.scala-lang.org/scala3/reference/other-new-features/other-new-features/experiment-defs.html 但是我是努力克服汇编错误。请帮忙!
The following scala 3 code following documentation works fine
import scala.compiletime.ops.string.*
@main def refinedTypeInAction: Unit =
val hello: "hello " + "world" = "hello world"
println(hello)
However, the one below
import scala.annotation.experimental
@experimental
object UseExperimental:
def x: scala.compiletime.ops.string.Substring["hamburger", 4, 8] = "urge"
throws compile time error as shown below
[error] -- [E008] Not Found Error: /Users/viswanath/projects/myproject/src/main/scala/RefinedType.scala:16:38
[error] 16 | def x: scala.compiletime.ops.string.Substring["hamburger", 4, 8] = "urge"
[error] | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error] | type Substring is not a member of object scala.compiletime.ops.string
[error] one error found
I did refer to https://docs.scala-lang.org/scala3/reference/other-new-features/experimental-defs.html but I'm struggling to get past the compilation error. Please help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论