Can’t access Parent’s Members while dealing with Macro Annotations

Trees that go into macro annotation arguments are purposefully untyped. However running c.typeCheck(q”(??? : <tree that represents the parent>)”).tpe will provide the missing information. Don’t forget to duplicate that tree before typechecking, because c.typeCheck mutates the tree in place, which might be undesireable. In case when both parent and child are declared in the same … Read more

What is the rationale behind having companion objects in Scala?

The companion object basically provides a place where one can put “static-like” methods. Furthermore, a companion object, or companion module, has full access to the class members, including private ones. Companion objects are great for encapsulating things like factory methods. Instead of having to have, for example, Foo and FooFactory everywhere, you can have a … Read more