Skip to content

Instantly share code, notes, and snippets.

@p-pavel
Last active March 29, 2020 22:17
Show Gist options
  • Save p-pavel/0f7b78c652d62b964a0ae8818c3dfc36 to your computer and use it in GitHub Desktop.
Save p-pavel/0f7b78c652d62b964a0ae8818c3dfc36 to your computer and use it in GitHub Desktop.
import scala.reflect.ClassTag
import scala.compiletime._
inline def alloc[T: ClassTag](n: Int) = if n > 0 then new Array[T](n) else error("Array size should be positive")
def main(args: Array[String]): Unit = {
println(alloc[Int](100).length)
alloc[Int](0) // не компилируется
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment