Skip to content
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

Compiler cannot determine implicit Manifest for type constructor #2915

Closed
scabug opened this issue Jan 17, 2010 · 15 comments
Closed

Compiler cannot determine implicit Manifest for type constructor #2915

scabug opened this issue Jan 17, 2010 · 15 comments
Assignees

Comments

@scabug
Copy link

scabug commented Jan 17, 2010

Implicit value of this type cannot be determined: Manifest[A[List]]. Type in REPL the following to reproduce:

Welcome to Scala version 2.8.0.r20552-b20100117020202 (Java HotSpot(TM) Client VM, Java 1.6.0_01).
...
import scala.reflect.Manifest

scala> def f[A[B[C]]](implicit m: Manifest[A[List]]) {}
f: [A[B[C]]](implicit m: scala.reflect.Manifest[A[List]])Unit

scala> class X[Y[Z]]
defined class X

scala> f[X]
<console>:8: error: could not find implicit value for parameter m: scala.reflect.Manifest[X[List]]
       f[X]
        ^

Expected result: implicit manifest value should have been found.

@scabug
Copy link
Author

scabug commented Jan 17, 2010

Imported From: https://issues.scala-lang.org/browse/SI-2915?orig=1
Reporter: Alexey Tarasevich (xetas)

@scabug
Copy link
Author

scabug commented Jan 19, 2010

@adriaanm said:
first attempt at a fix: http://github.com/adriaanm/scala/commit/44e01ff39e3d7ff8e52e06c4072c4d9472911d6b

not sure whether this is the way to go, though...

@scabug
Copy link
Author

scabug commented Feb 26, 2010

@adriaanm said:
Martin, I'm not sure what to do here. My patch seems like too much of a hack. Should we introduce kind-polymorphic variants of classOf, Manifest, classType,... so that the generatedclassType[X](classOf[X]) in this example type checks?

given

def classOfHK[T @uncheckedKind]
class ManifestHK[T @uncheckedKind]
def classTypeHK[T @uncheckedKind](clazz: Predef.Class[_]): Manifest[T] = ...

classTypeHK[X](classOfHK[X]) would be ok

@scabug
Copy link
Author

scabug commented Mar 13, 2010

@odersky said:
I am not sure. I think we need to discuss this further. Better leave this open until we are convinced we have the right solution than do a half fix which we have to revert later.

@scabug
Copy link
Author

scabug commented Mar 15, 2010

@adriaanm said:
this will need some design work first, leaving open for now

@scabug
Copy link
Author

scabug commented Apr 25, 2010

Alexey Tarasevich (xetas) said:
Similar problem for manifests for structural types:

scala> def f(implicit a: Manifest[{def g: Unit}]) = a
f: (implicit a: Manifest[AnyRef{def g: Unit}])Manifest[AnyRef{def g: Unit}]

scala> f
<console>:6: error: type mismatch;
 found   : scala.reflect.Manifest[AnyRef]
 required: Manifest[AnyRef{def g: Unit}]
       f
       ^

@scabug
Copy link
Author

scabug commented Feb 13, 2011

@soc said:
Additional information in Scala 2.9.0.r24145-b20110130020134 for the last example:

scala> def f(implicit a: Manifest[{def g: Unit}]) = a
f: (implicit a: scala.reflect.Manifest[AnyRef{def g: Unit}])scala.reflect.Manifest[AnyRef{def g: Unit}]

scala> f
<console>:8: error: type mismatch;
 found   : scala.reflect.Manifest[java.lang.Object]
 required: scala.reflect.Manifest[AnyRef{def g: Unit}]
Note: java.lang.Object >: AnyRef{def g: Unit}, but trait Manifest is invariant in type T.
You may wish to investigate a wildcard type such as `_ >: AnyRef{def g: Unit}`. (SLS 3.2.10)
       f
       ^

@scabug
Copy link
Author

scabug commented Aug 9, 2011

@harrah said:
In sbt, a SettingKey[T] requires a Manifest[T]. Because of this bug, a class like X (from the original example) cannot be used directly as the type of a setting. (The workaround is to use a wrapper type.)

@scabug
Copy link
Author

scabug commented May 4, 2012

@harrah said:
This is a problem for macros because all type parameters passed to a macro need a TypeTag. It isn't possible to get a TypeTag for a type constructor, for example.

@scabug scabug closed this as completed Jun 22, 2012
@scabug
Copy link
Author

scabug commented Jun 22, 2012

@adriaanm said:
we'd need kind polymorphism to fix this properly

@scabug
Copy link
Author

scabug commented Jul 6, 2012

@harrah said:
Is there a workaround?

@scabug
Copy link
Author

scabug commented Jul 6, 2012

@adriaanm said:
Not that I'm aware of. We could implement an @uncheckedKind annotation, though.
Alternatively, use type members instead of type parameters. Those are not tracked in kinds.

@scabug
Copy link
Author

scabug commented Jul 6, 2012

@harrah said:
If the annotation were paired with a TypeConstructorTag, that could make it possible to provide clean integration for the macro consumer.

For the workaround, I managed to get something along the lines of a type member working for my purposes.

@scabug
Copy link
Author

scabug commented Nov 29, 2013

@retronym said:
This problem is masked with an unreported error when the type constructor is a component type of an enclosing manifest.

scala> class M[A]; class O[A, B[_]]
warning: there were 1 feature warning(s); re-run with -feature for details
defined class M
defined class O

scala> implicitly[reflect.runtime.universe.TypeTag[O[String, M]]]
res27: reflect.runtime.universe.TypeTag[O[String,M]] = TypeTag[O[String,M]]

scala> implicitly[reflect.Manifest[O[String, M]]]
<console>:70: error: erroneous or inaccessible type
              implicitly[reflect.Manifest[O[String, M]]]
                        ^

Internally, an error like is issued and swallowed:

kinds of the type arguments (M) do not conform to the expected kinds of the type parameters (type T).
M's type parameters do not match type T's expected parameters:
class M has one type parameter, but type T has none

@nafg
Copy link

nafg commented Jul 8, 2018

we'd need kind polymorphism to fix this properly

sounds like that's on its way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants