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
I can see an implicit for ClassTag[Type] is defined in Newtype[A]. I am not sure where exactly this is used in practice, but I suppose it is there to help the compiler in situations like this one.
After playing around a bit, what I found to help is providing an instance for TypeTest. To my knowledge, TypeTest replaces ClassTag in Scala 3, and while ClassTag should still work, I guess there's something in this particular case that means it is not sufficient.
The example below compiles without warnings:
importzio.prelude.Newtypeimportscala.reflect.TypeTesttraitMyNewtype[A] extendsNewtype[A] {
giventypeTest(usingtypeTest: TypeTest[Any, A]):TypeTest[Any, Type] =newTypeTest[Any, Type]:defunapply(x: Any):Option[x.type&Type] = x matchcases: A=>Some(s.asInstanceOf[x.type&Type])
case _ =>None
}
objectMyStringextendsMyNewtype[String]
typeMyString=MyString.TypeclassStringArray(valcontents:Array[String])
deffn(s: MyString|StringArray) = s matchcasemyS: MyString=> println(myS)
casearr: StringArray=> println(arr.contents.mkString(","))
Apologies in advance if the title is unclear.
Given the following example code:
The compiler gives the following warning:
https://scastie.scala-lang.org/w509lJaCT3mtzUsnL4i2JA
I can see an implicit for
ClassTag[Type]
is defined inNewtype[A]
. I am not sure where exactly this is used in practice, but I suppose it is there to help the compiler in situations like this one.After playing around a bit, what I found to help is providing an instance for
TypeTest
. To my knowledge,TypeTest
replacesClassTag
in Scala 3, and whileClassTag
should still work, I guess there's something in this particular case that means it is not sufficient.The example below compiles without warnings:
https://scastie.scala-lang.org/B8Jhfu9eQ4S9wqyxtfkHbg
The text was updated successfully, but these errors were encountered: