What types can be used as args for TypeApply?

66 views
Skip to first unread message

Eugene Burmako

unread,
Sep 23, 2012, 6:48:59 AM9/23/12
to scala-internals
As http://groups.google.com/group/scala-debate/msg/a193c140bf577cc4
shows, reifier is a bit dumb.

Usually to generate a type tag from a type T, it emits a reification
code and wraps it into a TypeTag.apply[T](...). When it's asked to
reify a method type MT, it will happily emit TypeTag.apply[MT](...),
which will choke saying "error: type arguments [MT] do not conform to
method TypeTag.apply's type parameter bounds [T]". Sure, after all,
parameterizing a type with a method type doesn't make sense.

This brings us to a question. How do I find out whether a type can be
used as a type argument?

Eugene Burmako

unread,
Sep 23, 2012, 8:11:57 AM9/23/12
to scala-internals
So far I've only been able to come up with
https://github.com/scalamacros/kepler/commit/6722738cff9fc40465844eee2458b83e10f26682,
but sometimes it produces false negatives.

First I tried using Type.isWithinBounds (the method called by
typedTypeApply, which causes the error reported in the linked thread).
But I soon realized that isWithinBounds for PolyType(_, MethodType)
returns true, whereas isWithinBounds for MethodType returns false.
Apparently, typechecker somehow unwraps PolyTypes and checks
underlying types, but that logic is too obscure to be reproduced by
hand.

Therefore I went for manually assembling TypeApply and typechecking it
using silent, but as mentioned above, this produces false negatives.
Any better ideas?

On Sep 23, 12:49 pm, Eugene Burmako <eugene.burm...@epfl.ch> wrote:
> Ashttp://groups.google.com/group/scala-debate/msg/a193c140bf577cc4

Eugene Burmako

unread,
Sep 23, 2012, 8:22:02 AM9/23/12
to scala-internals
Okay my bad, that was me being stupid. Everything works fine:
https://github.com/scala/scala/pull/1384.

But anyways, is there a better approach?

On Sep 23, 2:11 pm, Eugene Burmako <eugene.burm...@epfl.ch> wrote:
> So far I've only been able to come up withhttps://github.com/scalamacros/kepler/commit/6722738cff9fc40465844eee...,

Paul Phillips

unread,
Sep 24, 2012, 7:26:15 PM9/24/12
to scala-i...@googlegroups.com


On Sun, Sep 23, 2012 at 5:11 AM, Eugene Burmako <eugene....@epfl.ch> wrote:
Therefore I went for manually assembling TypeApply and typechecking it
using silent, but as mentioned above, this produces false negatives.
Any better ideas?

Write the missing method.

Who knows how many implicit pseudo-invariants have been enforced until now only by the parser's unwillingness to create certain trees.  Now that people can roll their own types, it would be a lot better if those pseudo-invariants were explicit. (It would be better anyway.)

Reply all
Reply to author
Forward
0 new messages