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

Can't match classOf after typechecking with quasiquotes #8384

Closed
scabug opened this issue Mar 9, 2014 · 8 comments
Closed

Can't match classOf after typechecking with quasiquotes #8384

scabug opened this issue Mar 9, 2014 · 8 comments
Milestone

Comments

@scabug
Copy link

scabug commented Mar 9, 2014

Due to change in the shape of classOf tree after typechecking one can't match it:

scala> showRaw(q"classOf[Int]")
TypeApply(Ident(TermName("classOf")), List(Ident(TypeName("Int"))))

scala> showRaw(typecheck(q"classOf[Int]").sr)
Literal(Constant(Int))

We also can't really implement syntactic abstraction over this without referential transparency as untyped classOf tree might or might not become a type literal depending on definitions in scope:

scala> showRaw(typecheck(q"def classOf[T] = (); classOf[Int]"))
Block(List(
  DefDef(Modifiers(), TermName("classOf"), List(TypeDef(Modifiers(PARAM), TypeName("T"), List(), TypeTree().setOriginal(TypeBoundsTree(TypeTree(), TypeTree())))), List(), TypeTree(), Literal(Constant(())))), 
  TypeApply(Ident(TermName("classOf")), List(TypeTree().setOriginal(Select(Ident(scala), scala.Int)))))
@scabug
Copy link
Author

scabug commented Mar 9, 2014

Imported From: https://issues.scala-lang.org/browse/SI-8384?orig=1
Reporter: @densh
Affected Versions: 2.11.0

@scabug
Copy link
Author

scabug commented Mar 9, 2014

@soc said:
Would any of this be different if classOf was a macro?

@scabug
Copy link
Author

scabug commented Mar 9, 2014

@xeno-by said:
Yes, I think so. We have MacroExpansionAttachment that allows us to correlate macro expansions and their originals, so we could theoretically pull this off.

Another question is whether we want quasiquotes to match originals or expansions. I can see arguments for both approaches. Denys, wdyt?

@scabug
Copy link
Author

scabug commented Mar 10, 2014

@densh said:
Quasiquotes already match TypeTree originals albeit not consistently (plan to fix it soon).

I 'm not sure that matching macro originals by default is a good idea though.

@scabug
Copy link
Author

scabug commented Mar 10, 2014

@densh said:
Workaround:

typecheck(q"classOf[Int]") match {
  case q"${const: Constant}" if const.value.isInstanceOf[Type] =>
  println(const.asInstanceOf[Type].value)
}

@scabug
Copy link
Author

scabug commented Mar 10, 2014

@soc said:
What happens if classOf[X] doesn't result in a Constant?

@scabug
Copy link
Author

scabug commented Mar 10, 2014

@densh said:
Can you give an example? I had an impression that it was always represented as constant.

@scabug scabug added this to the Backlog milestone Apr 7, 2017
@SethTisue
Copy link
Member

closing all quasiquotes tickets; see #10755

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

4 participants