Skip to content

Fix #3947: Support lifting of java.lang.Class #4193

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

Merged
merged 6 commits into from
Mar 29, 2018

Conversation

nicolasstucki
Copy link
Contributor

No description provided.

@nicolasstucki
Copy link
Contributor Author

Missing a test case for lifted anonymous classes. These have an unrelated bug #4192.

case expr: LiftedExpr[_] =>
expr.value match {
case value: Class[_] => ref(defn.Predef_classOf).appliedToType(classToType(value))
case value => Literal(Constant(value))
Copy link
Member

Choose a reason for hiding this comment

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

Did you know that you can pass a Type to the constructor of Constant and if you do Constant#tpe on such a value you get an instance of java.lang.Class ?

Copy link
Member

Choose a reason for hiding this comment

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

The miniphase ClassOf rewrites call to classOf into Literal(Constant(...))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will look at those.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can use the representation with Literal(Constant(...)) from ClassOf though this representation is only expected after this phase. It seems better to create the classOf[T] and let ClassOf rewrite all of them at that phase.

@nicolasstucki nicolasstucki force-pushed the lift-class branch 2 times, most recently from de27dba to 5b271bc Compare March 27, 2018 06:45
else if (clazz == classOf[Float]) defn.FloatType
else if (clazz == classOf[Double]) defn.DoubleType
else if (clazz == classOf[Unit]) defn.UnitType
else if (!clazz.isMemberClass) ctx.getClassIfDefined(clazz.getCanonicalName).typeRef
Copy link
Member

Choose a reason for hiding this comment

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

Array-s probably need special handling, too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will look into it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, they needed it. Thanks :)

else if (clazz == classOf[Long]) defn.LongType
else if (clazz == classOf[Float]) defn.FloatType
else if (clazz == classOf[Double]) defn.DoubleType
else if (clazz == classOf[Unit]) defn.UnitType
Copy link
Member

Choose a reason for hiding this comment

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

Could enclose the above in if (clazz.isPrimitive) for performance reasons.

def main(args: Array[String]): Unit = {

def test[T](clazz: java.lang.Class[T]): Unit = {
val lclazz = clazz.toExpr
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the purpose of lclazz in the test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Lift a class and then splice it in some quote that will run in next stage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I see. I lifted it directly in the quote. I will remove it or use it instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

def main(args: Array[String]): Unit = {

def test[T](clazz: java.lang.Class[T]): Unit = {
val lclazz = clazz.toExpr
Copy link
Contributor

Choose a reason for hiding this comment

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

Same.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@nicolasstucki
Copy link
Contributor Author

Rebased

@nicolasstucki nicolasstucki merged commit b6dbe42 into scala:master Mar 29, 2018
@Blaisorblade Blaisorblade deleted the lift-class branch March 29, 2018 15:58
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.

4 participants