So, I must ask: Is the implicit-based variant ok? I.e.
sealed trait Foo
implicit class FooExt[T<:Foo](val x:T) extends AnyVal{
def foo:T = unsafeImplementation(x).asInstanceOf[T]
}
def unsafeImplementation(x:Any):Any = ???
...
Something fishy must happen in the implementation, but is this an acceptable way of publishing an interface that “returns the same type”?
I mean, there are cases where this could run into the same issue: e.g. when called on this
from within a class extending Foo
. then T
is this.type
and we violate the type system; probably other issues if one has non-static inner classes that extend Foo
(something something path dependent types). But these are avoidable by carefully controlling all classes that implement Foo (it’s sealed).