Constant propagation guarded by the class jet.Number where the properties are defined.
NOTE: currently, local extension properties are not allowed, but they may be allowed in future versions, and the old propagation would break
This commit is contained in:
@@ -49,6 +49,7 @@ public class JetStandardLibrary {
|
||||
|
||||
private JetScope libraryScope;
|
||||
|
||||
private ClassDescriptor numberClass;
|
||||
private ClassDescriptor byteClass;
|
||||
private ClassDescriptor charClass;
|
||||
private ClassDescriptor shortClass;
|
||||
@@ -152,6 +153,7 @@ public class JetStandardLibrary {
|
||||
private void initStdClasses() {
|
||||
if(libraryScope == null) {
|
||||
this.libraryScope = JetStandardClasses.STANDARD_CLASSES_NAMESPACE.getMemberScope();
|
||||
this.numberClass = (ClassDescriptor) libraryScope.getClassifier("Number");
|
||||
this.byteClass = (ClassDescriptor) libraryScope.getClassifier("Byte");
|
||||
this.charClass = (ClassDescriptor) libraryScope.getClassifier("Char");
|
||||
this.shortClass = (ClassDescriptor) libraryScope.getClassifier("Short");
|
||||
@@ -221,6 +223,12 @@ public class JetStandardLibrary {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getNumber() {
|
||||
initStdClasses();
|
||||
return numberClass;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getByte() {
|
||||
initStdClasses();
|
||||
|
||||
+3
-1
@@ -468,7 +468,9 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
JetExpression receiverExpression = expression.getReceiverExpression();
|
||||
CompileTimeConstant<?> receiverValue = context.trace.getBindingContext().get(BindingContext.COMPILE_TIME_VALUE, receiverExpression);
|
||||
CompileTimeConstant<?> wholeExpressionValue = context.trace.getBindingContext().get(BindingContext.COMPILE_TIME_VALUE, expression);
|
||||
if (wholeExpressionValue == null && receiverValue != null && !(receiverValue instanceof ErrorValue) && receiverValue.getValue() instanceof Number) {
|
||||
DeclarationDescriptor declarationDescriptor = context.trace.getBindingContext().get(BindingContext.REFERENCE_TARGET, selectorExpression);
|
||||
if (wholeExpressionValue == null && receiverValue != null && !(receiverValue instanceof ErrorValue) && receiverValue.getValue() instanceof Number
|
||||
&& context.semanticServices.getStandardLibrary().getNumber() == declarationDescriptor) {
|
||||
Number value = (Number) receiverValue.getValue();
|
||||
String referencedName = selectorExpression.getReferencedName();
|
||||
if (OperatorConventions.NUMBER_CONVERSIONS.contains(referencedName)) {
|
||||
|
||||
Reference in New Issue
Block a user