-
Notifications
You must be signed in to change notification settings - Fork 3
Fix static type tests for ancestors of hijacked classes. #93
Fix static type tests for ancestors of hijacked classes. #93
Conversation
5a02a15
to
71f17cd
Compare
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 left a minor comment on descriptions, but otherwise LGTM! great work 🎉
if (classInfo.isAncestorOfHijackedClass) { | ||
/* It could be a hijacked class instance that implements this interface. | ||
* Test whether `jsValueType(expr)` is in the `specialInstanceTypes` bitset. | ||
* In other words, return `(1 << jsValueType(expr)) != 0`. |
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.
* In other words, return `(1 << jsValueType(expr)) != 0`. | |
* In other words, return `(1 << jsValueType(expr) & specialInstanceTypes) != 0`. |
/* It could be a hijacked class instance that implements this interface. | ||
* Test whether `jsValueType(expr)` is in the `specialInstanceTypes` bitset. | ||
* In other words, return `(1 << jsValueType(expr)) != 0`. | ||
*/ |
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.
Though it might be a bit duplicated with an explanation at specialInstanceTypes
, it would be helpful for me if we can add some example like below here 😅
*/ | |
* | |
* For example, when the `jsValueType(expr)` is 'string', 'expr.isInstanceOf[j.l.CharSequence]' | |
* should be `true` because `j.l.String` implements `j.l.CharSequence`, and | |
* `specialInstanceTypes` for `j.l.CharSequence` contains `1 << jsValueType(j.l.String)`. | |
*/ |
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 added a more concrete example. :)
This commit fixes the result of `x.isInstanceOf[C]` where `x` is a primitive and `C` is an ancestor of the hijacked class for `x`. For `jl.Number`, which is the only non-`Object` class that is an ancestor of a hijacked class, we add a special case in the codegen. For interfaces, we add generic code in their `genInstanceTest` function, based on their `specialInstanceTypes`. This means we have a second place where we need to compute `specialInstanceTypes`. We move it to the preprocessor, and also use it to generically compute `isAncestorOfHijackedClass`. This removes the hard-code set that we had before. Fix tanishiking#74. Fix tanishiking#84. Fix tanishiking#92.
71f17cd
to
716d7d4
Compare
This commit fixes the result of
x.isInstanceOf[C]
wherex
is a primitive andC
is an ancestor of the hijacked class forx
.For
jl.Number
, which is the only non-Object
class that is an ancestor of a hijacked class, we add a special case in the codegen.For interfaces, we add generic code in their
genInstanceTest
function, based on theirspecialInstanceTypes
.This means we have a second place where we need to compute
specialInstanceTypes
. We move it to the preprocessor, and also use it to generically computeisAncestorOfHijackedClass
. This removes the hard-code set that we had before.Fix #74.
Fix #84.
Fix #92.