no, no, implicits, stay away from my type inference!!

146 views
Skip to first unread message

Eugene Burmako

unread,
May 4, 2013, 3:14:48 AM5/4/13
to scala-internals
object Test extends App {
class C
implicit val ctag = scala.reflect.ClassTag[C](classOf[C])
val x = Array()
println(x.getClass)
}

09:10 ~/Projects/Kepler_5923/sandbox (ticket/5923)$ s
class [LTest$C;

Paul Phillips

unread,
May 4, 2013, 11:50:25 AM5/4/13
to scala-i...@googlegroups.com
I'm sure you can see a billion messages from me talking about the multiple uses of Nothing. It is fixable. I fixed it locally two years ago, and I failed to push all the way to completion. But I know it works, and this is what I did: make more than one Nothing. There's only one NothingClass, but there can be arbitrarily many types wrapped around it. I had something like

val UninferredType = typeRef(NoPrefix, NothingClass, SomeDummyType)
val ExplicitNothing = typeRef(NoPrefix, NothingClass, SomeOtherDummyType)

Then it's only a small matter of analyzing the 500 places nothing is used one way or another and adjusting them as necessary.

Eugene Burmako

unread,
May 4, 2013, 12:22:03 PM5/4/13
to <scala-internals@googlegroups.com>
Thanks for providing inspiration! I guess I'll have to fix this sooner or later, because I probably wouldn't be able to live with the feeling of implicit macros, my favorite macros of them all, being not quite perfect.

Also, what do you think about the problem reported in this topic, when class tags that occasionally happen to be in scope inadvertently affect type inference? Having implicits work together with type inference is the single coolest feature of Scala, but have you previously seen situations when that turns out to be undesirable?


--
You received this message because you are subscribed to the Google Groups "scala-internals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-interna...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Miles Sabin

unread,
May 5, 2013, 12:31:15 PM5/5/13
to scala-internals
On Sat, May 4, 2013 at 5:22 PM, Eugene Burmako <eugene....@epfl.ch> wrote:
> implicit macros, my favorite macros of them all

That makes my day :-)

Cheers,


Miles

--
Miles Sabin
tel: +44 7813 944 528
skype: milessabin
gtalk: mi...@milessabin.com
g+: http://www.milessabin.com
http://twitter.com/milessabin

Paul Phillips

unread,
May 5, 2013, 4:35:44 PM5/5/13
to scala-i...@googlegroups.com
FYI I dug up my old attempt at 1570 and I think I know how to finish it now. Should know by tomorrow sometime. 

Eugene Burmako

unread,
May 7, 2013, 6:28:29 PM5/7/13
to scala-internals
Btw today Martin mentioned that replacing Nothing with Uninferred will
only help if the type parameter doesn't have lower bounds. Otherwise,
nothing can stop it from being sneakily inferred to a lower bound. Can
something be done about that as well?

On May 5, 10:35 pm, Paul Phillips <pa...@improving.org> wrote:
> FYI I dug up my old attempt at 1570 and I think I know how to finish it
> now. Should know by tomorrow sometime.
>
>
>
>
>
>
>
> On Saturday, May 4, 2013, Eugene Burmako wrote:
> > Thanks for providing inspiration! I guess I'll have to fix this sooner or
> > later, because I probably wouldn't be able to live with the feeling of
> > implicit macros, my favorite macros of them all, being not quite perfect.
>
> > Also, what do you think about the problem reported in this topic, when
> > class tags that occasionally happen to be in scope inadvertently affect
> > type inference? Having implicits work together with type inference is the
> > single coolest feature of Scala, but have you previously seen situations
> > when that turns out to be undesirable?
>
> > On 4 May 2013 17:50, Paul Phillips <pa...@improving.org<javascript:_e({}, 'cvml', 'pa...@improving.org');>
> > > wrote:
>
> >> I'm sure you can see a billion messages from me talking about the
> >> multiple uses of Nothing. It is fixable. I fixed it locally two years ago,
> >> and I failed to push all the way to completion. But I know it works, and
> >> this is what I did: make more than one Nothing. There's only one
> >> NothingClass, but there can be arbitrarily many types wrapped around it. I
> >> had something like
>
> >> val UninferredType = typeRef(NoPrefix, NothingClass, SomeDummyType)
> >> val ExplicitNothing = typeRef(NoPrefix, NothingClass, SomeOtherDummyType)
>
> >> Then it's only a small matter of analyzing the 500 places nothing is used
> >> one way or another and adjusting them as necessary.
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "scala-internals" group.
> >> To unsubscribe from this group and stop receiving emails from it, send an
> >> email to scala-interna...@googlegroups.com <javascript:_e({},
> >> 'cvml', 'scala-internals%2Bunsu...@googlegroups.com');>.
> >> For more options, visithttps://groups.google.com/groups/opt_out.
>
> >  --
> > You received this message because you are subscribed to the Google Groups
> > "scala-internals" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to scala-interna...@googlegroups.com <javascript:_e({},
> > 'cvml', 'scala-internals%2Bunsu...@googlegroups.com');>.
> > For more options, visithttps://groups.google.com/groups/opt_out.

Paul Phillips

unread,
May 7, 2013, 7:19:32 PM5/7/13
to scala-i...@googlegroups.com
On Tue, May 7, 2013 at 3:28 PM, Eugene Burmako <eugene....@epfl.ch> wrote:
Btw today Martin mentioned that replacing Nothing with Uninferred will
only help if the type parameter doesn't have lower bounds. Otherwise,
nothing can stop it from being sneakily inferred to a lower bound. Can
something be done about that as well?

Ah, he underestimates the reach of my tendrils. The problem has become the stupid undoLog, which is an atrocity.

I don't necessarily expect to allow all these to survive to the point of checking them in, but:

    lazy val NothingTpe                   = definitions.NothingClass.toTypeConstructor
    lazy val FailedInferenceNothing       = newTaggedNothing("failed type inference")
    lazy val ExplicitlyGivenNothing       = newTaggedNothing("explicit type argument")
    lazy val NoLowerBoundNothing          = newTaggedNothing("constructed upper or empty bounds")
    lazy val UnspecifiedLowerBoundNothing = newTaggedNothing("empty lower bound")
    lazy val EmptyListLubNothing          = newTaggedNothing("lub of empty list")
    lazy val GlbFailureNothing            = newTaggedNothing("glb failure")

I track the origin and true meaning of EVERY usage of Nothing.
 

Eugene Burmako

unread,
May 7, 2013, 7:21:07 PM5/7/13
to <scala-internals@googlegroups.com>
Wow.


--
You received this message because you are subscribed to the Google Groups "scala-internals" group.
Reply all
Reply to author
Forward
0 new messages