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

Clean up macros; Support reflection #24

Merged
merged 2 commits into from
May 9, 2017
Merged

Conversation

andyscott
Copy link
Member

No description provided.

Copy link
Collaborator

@juanpedromoreno juanpedromoreno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

)(tpe: Type): Either[Id[String], List[Type]] =
typeListFoldLeft(nilTpe, consTpe)(tpe)(List.empty[Type])((acc, t) => t :: acc).map(_.reverse)

final def tlistTypes(tpe: Type): Either[Id[String], List[Type]] =

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd really expect this to use Iota coproducts, but ok, I guess it will do.... 😃

image

final def destructCop(tpe: Type): Either[Id[String], CopTypes] =
tpe.dealias match {
case TypeRef(_, sym, l :: Nil) if resultType(sym) <:< CopTpe => Right(CopTypes(l))
case TypeRef(_, sym, Nil) => destructCop(sym.asType.toType)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not have sym.typeSignature assuming this is a TypeSymbol? sym.asType.toType can throw scala.ScalaReflectionException as far as I know.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just checked-- .typeSignature gives a different result than .asType.toType, and it causes the tests to fail. I'm going to sort out what the differences are and look at cleaning this up, regardless!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @andyscott I accept I am wrong here, I just didn't know the API differences.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The feedback was very welcomed regardless! I didn't know about (or hadn't used) .typeSignature before; now I I'll use it next time I'm poking around.

final def destructCopK(tpe: Type): Either[Id[String], CopKTypes] =
tpe.dealias match {
case TypeRef(_, sym, l :: a :: Nil) if resultType(sym) <:< CopKTpe => Right(CopKTypes(l, a))
case TypeRef(_, sym, Nil) => destructCopK(sym.asType.toType)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, this is in effect, tpe.dealias no? I'm not sure what kind of magic unapply does, but I do know weakTypeOf[T].termSymbol.asType.toType blows up.


import scala.reflect.macros.blackbox.Context

private[iota] final class TypeListMacros(cc: Context)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird alignment I think, but I'm not sure if this is your standard scalaFMT and I just have different habits. I would expect:

class A(
 ..args
) extends Bla {
}

@andyscott andyscott merged commit 48ef356 into master May 9, 2017
@andyscott andyscott deleted the feature/reflection branch May 9, 2017 17:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants