You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Even the simplest use of covariance will not compile:
finalclassOptPlus[+A](valx:A) extendsAnyVal { }
// ./a.scala:1: error: covariant type A occurs in contravariant position in type OptPlus[A] of value $this// final class OptPlus[+A](val x: A) extends AnyVal { }// ^// one error found
The reason for this error (and there are additional ones from completely synthetic methods if one declares a case class, but they can be addressed the same way) is the direct exposure of the type parameter in incoming position of extension methods:
objectOptPlus {
final <synthetic> defextension$hashCode[A>:Nothing<:Any]($this: OptPlus[A])():Int= $this.x.hashCode();
}
The extension methods should be generated with a bound:
// Not like thisdeff[A]($this: OptPlus[A])(args) = ...
// Like this insteaddeff[A1>:A]($this: OptPlus[A1])(args) = ...
// In the case of hashCode and others which don't reference the// type parameter at all, they could be like thisdeff($this: OptPlus[_])(args) = ...
// but I don't know if there's any meaningful advantage to that.
The text was updated successfully, but these errors were encountered:
Even the simplest use of covariance will not compile:
The reason for this error (and there are additional ones from completely synthetic methods if one declares a case class, but they can be addressed the same way) is the direct exposure of the type parameter in incoming position of extension methods:
The extension methods should be generated with a bound:
The text was updated successfully, but these errors were encountered: