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:
Andrey Breslav
2011-11-09 22:29:48 +03:00
parent c6f6f182b6
commit a28716af1d
2 changed files with 11 additions and 1 deletions
@@ -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();
@@ -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)) {