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

isModule in macro/reflection API always returns false #6012

Closed
scabug opened this issue Jul 1, 2012 · 3 comments
Closed

isModule in macro/reflection API always returns false #6012

scabug opened this issue Jul 1, 2012 · 3 comments

Comments

@scabug
Copy link

scabug commented Jul 1, 2012

isModule always seems to return false:

scala> import reflect.runtime.universe._
import reflect.runtime.universe._

scala> object Foo
defined module Foo

scala> typeOf[Foo.type]
res0: reflect.runtime.universe.Type = Foo.type

scala> res0.typeSymbol.isModule
res1: Boolean = false

scala> res0.widen.typeSymbol.isModule
res2: Boolean = false

scala> res0.underlying.typeSymbol.isModule
res3: Boolean = false

scala> res0.erasure.typeSymbol.isModule
res4: Boolean = false

It only seems to be possible to get it to return true by reaching into the innards of the compiler:

scala> res1.getClass
res3: Class[_ <: reflect.runtime.universe.Symbol] = class scala.reflect.internal.Symbols$ModuleClassSymbol

scala> res1.isModuleClass
<console>:14: error: value isModuleClass is not a member of reflect.runtime.universe.Symbol
              res1.isModuleClass
                   ^

scala> res1.asInstanceOf[scala.tools.nsc.Global#Symbol].isModuleClass
res5: Boolean = true
@scabug
Copy link
Author

scabug commented Jul 1, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6012?orig=1
Reporter: @paulbutcher
Affected Versions: 2.10.0-M4

@scabug
Copy link
Author

scabug commented Jul 1, 2012

@paulbutcher said:
Update - companionSymbol does return something that returns true:

scala> object Foo
defined module Foo

scala> typeOf[Foo.type]
res0: reflect.runtime.universe.Type = Foo.type

scala> res0.typeSymbol.companionSymbol.isModule
res1: Boolean = true

Unfortunately, this doesn't help much, because the same is also true if we have:

scala> :paste
// Entering paste mode (ctrl-D to finish)

class Foo

object Foo

// Exiting paste mode, now interpreting.

defined class Foo
defined module Foo

scala> typeOf[Foo]
res1: reflect.runtime.universe.Type = Foo

scala> res1.typeSymbol.isModule
res2: Boolean = false

scala> res1.typeSymbol.companionSymbol.isModule
res3: Boolean = true

So this isn't a useful way to tell the difference between a class and its companion object :-(

@scabug
Copy link
Author

scabug commented Jul 3, 2012

@xeno-by said:
Fixed by scala/scala@f5b0d7b

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

2 participants