Skip to content
This repository has been archived by the owner on Feb 20, 2019. It is now read-only.

FastTypeTag doesn't work for types with type parameters #417

Open
jvican opened this issue Apr 25, 2016 · 4 comments
Open

FastTypeTag doesn't work for types with type parameters #417

jvican opened this issue Apr 25, 2016 · 4 comments
Labels
Milestone

Comments

@jvican
Copy link
Member

jvican commented Apr 25, 2016

I wonder why this happens:

case class Map[T, S]( ... )
val tag = implicitly[FastTypeTag[Map[List[Int], List[String]]]]
println(tag) // shows Map[t,s] where t,s are type variables

When using AnyUnpickler one wants to unpickle anything inferred from its type. In this case, reflection fails to create an unpickler for that type because t and s are unknown. Why aren't t and s concrete when they could be List[Int] and List[String]? Is this a bug? Otherwise, why doesn't FastTypeTag constructs the tag from the full type?

/cc @jsuereth since he's been refactoring FastTypeTag lately.

@jsuereth
Copy link
Member

@jvican Looks like that's a bug. There's a bit of funny-behavior regarding type parameters (usually my fault) in the macros.

@jvican jvican added bug and removed question labels Apr 25, 2016
@jvican
Copy link
Member Author

jvican commented Apr 25, 2016

Good, tomorrow I'll work on a fix for this.

@jvican jvican changed the title FastTypeTag bad conversion? FastTypeTag doesn't work for types with type parameters Apr 25, 2016
@jvican
Copy link
Member Author

jvican commented Apr 27, 2016

The problem here is that we create FastTypeTags for type variables. I'm not sure if we should. Let me explain it with a bit of code:

trait Foo
case class Bar[T](v: T)
case class Zaz(i: Int)

Now, let's create a concrete pickler for Foo:

def pickle(f: Foo, b: PBuilder): Unit = {
  f match {
    case b: Bar[t] =>
      // t is a type variable and BarPickle gets an implicit `FastTypeTag`
      // if we do not put a concrete tag here, one will be created for `t`
      barPicklerUnpickler.pickle(b)
    case z: Zaz => ???
  }
}

I'm not very sure if this behavior is intended by scala pickling. But since a FastTypeTag is a witness of a type, and we expect this type to be concrete, wouldn't be sensible to still consider this as a bug?

@jsuereth
Copy link
Member

yes, I agree it looks like a bug. We shouldn't be able to grab a static type tag without some witness of t's fast type tag

@jvican jvican added this to the 0.11.0-M1 milestone May 9, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants