-
Notifications
You must be signed in to change notification settings - Fork 23
Description
Intro
Analyser requires implicit classes to extend AnyVal (in order to decrease memory overhead).
implicit final class IntOps(i: Int) //compilation error: [AVS] Implicit classes should always extend AnyVal to become value classesIt is a valid error also for by-name parameters, becauseval parameters may not be call-by-name, so this should be translated to implicit def conversion + value class, like this:
implicit final class LazyIntOps(i: => Int) //compilation error: [AVS] Implicit classes should always extend AnyVal to become value classes
~>
implicit def toLazyIntOps(i: => Int) = new LazyIntOps(() => i)
final class LazyIntOps(val i: () => Int)But, it has no meaning for by-name value parameters, since they cannot be wrapped into a value class, so such a translation would be only a unnecessary boilerplate.
Problem
Current implementation of implicitValueClasses rules do not require implicit classes with value parameter to be value classes, because value class may not wrap another user-defined value class, but triggers false positives for by-name ones, e.g.
final class ValueClass(val underlying: Int) extends AnyVal
implicit final class LazyValueClassOps(lvc: => ValueClass) // compilation error: Implicit classes should always extend AnyVal to become value classesPossible solution
While checking the type of implicit class's parameter, the TypeRepr should be widened by-name (or its scala 2 equivalent)