Existentials and method types

64 views
Skip to first unread message

Ryan Hendrickson

unread,
May 9, 2013, 2:35:09 PM5/9/13
to scala-l...@googlegroups.com
I was surprised and delighted by a bug a coworker found today, which hinged on my assuming that surely value types can never contain non-value types. Here's a simplified version:


import scala.reflect.runtime.universe._

class A {
object B
}
class C {
val a = new A
val b = a.B
}

object Test extends App {
val cType = typeOf[C]
val bType = cType.member("b": TermName).typeSignatureIn(cType)
bType match {
case NullaryMethodType(_) =>
println("That's what I thought.")
case ExistentialType(_, NullaryMethodType(_)) =>
println("Huh???")
}
}


Is this a bug, or is it reasonable to expect that ExistentialType, a value type, can contain a NullaryMethodType, a non-value type?






(please forgive me my corporate legal disclaimer)

----------------------------------------

This message is intended exclusively for the individual(s) or entity to
which it is addressed. It may contain information that is proprietary,
privileged or confidential or otherwise legally exempt from disclosure.
If you are not the named addressee, you are not authorized to read,
print, retain, copy or disseminate this message or any part of it.
If you have received this message in error, please notify the sender
immediately by e-mail and delete all copies of the message.

Jason Zaugg

unread,
May 9, 2013, 4:17:27 PM5/9/13
to scala-l...@googlegroups.com
On Thu, May 9, 2013 at 8:35 PM, Ryan Hendrickson <Ryan.Hen...@bwater.com> wrote:
I was surprised and delighted by a bug a coworker found today, which hinged on my assuming that surely value types can never contain non-value types. Here's a simplified version:

The following doesn't answer your question, but might help someone else to do as much.

-jason


scala> :power

scala> class A {
     |   object B
     | }
defined class A

scala> class C {
     |   val a = new A
     |   val b = a.B
     | }
defined class C

scala> val cType = typeOf[C]
cType: $r.intp.global.Type = C

scala> val bType = cType.member("b": TermName).typeSignatureIn(cType)
bType: $r.intp.global.Type = (=> _4.a.B.type) forSome { val _4: C }

scala> typeDeconstruct.show(bType)
res3: String =
PolyType(
  typeParams = List(AbstractType(type _4.type <: C with Singleton))
  resultType = NullaryMethodType(
    SingleType(
      pre = SingleType(
        pre = AbstractTypeRef(
          AbstractType(type _4.type <: C with Singleton)
        )
        value a
      )
      object B
    )
  )

Paul Phillips

unread,
May 9, 2013, 11:02:38 PM5/9/13
to scala-l...@googlegroups.com

On Thu, May 9, 2013 at 11:35 AM, Ryan Hendrickson <Ryan.Hen...@bwater.com> wrote:
Is this a bug, or is it reasonable to expect that ExistentialType, a value type, can contain a NullaryMethodType, a non-value type?

It's a bug, unless it isn't.

Here's something weird. How do these two come up with different answers?

scala> class A { object B } ; class C { val a = new A ; val b = a.B }
defined class A
defined class C

scala> def f(x: Boolean) = List((new C).b , (new C).b).head
f: (x: Boolean)A#B.type

scala> def f(x: Boolean) = if (x) (new C).b else (new C).b 
warning: there were 1 feature warning(s); re-run with -feature for details
f: (x: Boolean)_4.a.B.type forSome { val _4: C }

scala> 

Jason Zaugg

unread,
May 10, 2013, 2:44:42 AM5/10/13
to scala-l...@googlegroups.com
There is some interesting handling of existentials in typedIf that is probably complicit.

-jason 

Paul Phillips

unread,
May 10, 2013, 12:09:37 PM5/10/13
to scala-l...@googlegroups.com
On Thu, May 9, 2013 at 11:44 PM, Jason Zaugg <jza...@gmail.com> wrote:
There is some interesting handling of existentials in typedIf that is probably complicit.

Boy, is it ever. 
Reply all
Reply to author
Forward
0 new messages