From a28716af1d207adfd3e1f764105b96068b22adf1 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Wed, 9 Nov 2011 22:29:48 +0300 Subject: [PATCH] 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 --- .../org/jetbrains/jet/lang/types/JetStandardLibrary.java | 8 ++++++++ .../types/expressions/BasicExpressionTypingVisitor.java | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java index 6c641719c65..62923713125 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/JetStandardLibrary.java @@ -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(); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java index 4e19232a122..f9ebc9d4a9c 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java @@ -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)) {