-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
|
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)) |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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(...))
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
de27dba to
5b271bc
Compare
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will look into it
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
8b96bca to
b5b7f1b
Compare
|
Rebased |
No description provided.