Checking compilation time on AnyVal for distribution?

Scala docs discuss AnyVal .

In the When Allocation Is Necessary section, he mentions:

 case class P(val i: Int) extends AnyVal val p = new P(3) p match { // new P instantiated here case P(3) => println("Matched 3") case P(x) => println("Not 3") } 

Is it possible at compile time to know if AnyVal is AnyVal for allocation, i.e. fit in a heap, not a stack?

In addition, I would like to write the above code, and then at compile time receive a warning that p match { leads to distribution.

As I understand it, the distribution hits the AnyVal target.

+5
source share

Source: https://habr.com/ru/post/1259925/


All Articles