-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeTag of path-dependent type cannot be inferred by the compiler #12113
Comments
Related work scala/scala#5836 |
it appears to me that the problem is that the type isn't path-dependent, but rather is local to the block: scala 2.13.3> object O { type U = (Int, String) }
object O
scala 2.13.3> implicitly[TypeTag[O.U]]
val res4: reflect.runtime.universe.TypeTag[O.U] = TypeTag[O.U]
scala 2.13.3> { type U = (Int, String); implicitly[TypeTag[U]] }
^
error: No TypeTag available for U |
@SethTisue The problem is with "free" types, val a = new { type T = Int }
typeOf[a.T]
trait Foo { type T }
val foo = new Foo { type T = Int }
typeOf[foo.T] |
@Jasper-M are you saying that once I moved those definition into a class or an object instead of a function the error will disappear? |
If you move the type for which you want a |
I'm wondering if we should just close this, on the grounds that it's an understandable and reasonable limitation, rather than a bug or shortcoming. (At least, that's what I think about the case where the path in the path-dependent type is local. Less sure what I think about Jasper's case.) |
Yes I agree it is a free type, but it is also a type alias that can be immediately de-aliased to a dependent type. Theoretically this is not a variable binding, so no guarantee for type equivalence, but developers may still perceive it that way |
This problem has been recorded in:
https://stackoverflow.com/questions/59708880/in-scala-why-it-is-impossible-to-infer-typetag-from-type-alias-or-dependent-typ
A similar problem that may have the same cause has been reported in:
fthomas/singleton-ops#152
reproduction steps
using Scala 2.13.3 OR 2.12.11,
problem
Compiler throws the following error:
If the compiler is working properly it should have easily found the TypeTag for
(Int, String)
The text was updated successfully, but these errors were encountered: