KT-3181 Prohibit val/var keywords for function parameters
#KT-3181
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package jet
|
||||
|
||||
public fun arrayOfNulls<T>(public val size : Int) : Array<T?>
|
||||
public fun arrayOfNulls<T>(public size : Int) : Array<T?>
|
||||
|
||||
public class Array<reified T>(public val size : Int, init : (Int) -> T) {
|
||||
public fun get(index : Int) : T
|
||||
|
||||
@@ -87,7 +87,7 @@ public class Double : Number, Comparable<Double> {
|
||||
public override fun toByte() : Byte
|
||||
|
||||
public override fun hashCode() : Int
|
||||
public override fun equals(val other : Any?) : Boolean
|
||||
public override fun equals(other : Any?) : Boolean
|
||||
}
|
||||
|
||||
public class Float : Number, Comparable<Float> {
|
||||
@@ -161,7 +161,7 @@ public class Float : Number, Comparable<Float> {
|
||||
public override fun toByte() : Byte
|
||||
|
||||
public override fun hashCode() : Int
|
||||
public override fun equals(val other : Any?) : Boolean
|
||||
public override fun equals(other : Any?) : Boolean
|
||||
}
|
||||
|
||||
public class Long : Number, Comparable<Long> {
|
||||
@@ -243,7 +243,7 @@ public class Long : Number, Comparable<Long> {
|
||||
public override fun toByte() : Byte
|
||||
|
||||
public override fun hashCode() : Int
|
||||
public override fun equals(val other : Any?) : Boolean
|
||||
public override fun equals(other : Any?) : Boolean
|
||||
}
|
||||
|
||||
public class Int : Number, Comparable<Int> {
|
||||
@@ -325,7 +325,7 @@ public class Int : Number, Comparable<Int> {
|
||||
public override fun toByte() : Byte
|
||||
|
||||
public override fun hashCode() : Int
|
||||
public override fun equals(val other : Any?) : Boolean
|
||||
public override fun equals(other : Any?) : Boolean
|
||||
}
|
||||
|
||||
public class Char : Number, Comparable<Char> {
|
||||
@@ -393,7 +393,7 @@ public class Char : Number, Comparable<Char> {
|
||||
public override fun toByte() : Byte
|
||||
|
||||
public override fun hashCode() : Int
|
||||
public override fun equals(val other : Any?) : Boolean
|
||||
public override fun equals(other : Any?) : Boolean
|
||||
}
|
||||
|
||||
public class Short : Number, Comparable<Short> {
|
||||
@@ -467,7 +467,7 @@ public class Short : Number, Comparable<Short> {
|
||||
public override fun toByte() : Byte
|
||||
|
||||
public override fun hashCode() : Int
|
||||
public override fun equals(val other : Any?) : Boolean
|
||||
public override fun equals(other : Any?) : Boolean
|
||||
}
|
||||
|
||||
public class Byte : Number, Comparable<Byte> {
|
||||
@@ -541,5 +541,5 @@ public class Byte : Number, Comparable<Byte> {
|
||||
public override fun toByte() : Byte
|
||||
|
||||
public override fun hashCode() : Int
|
||||
public override fun equals(val other : Any?) : Boolean
|
||||
public override fun equals(other : Any?) : Boolean
|
||||
}
|
||||
|
||||
@@ -474,6 +474,7 @@ public interface Errors {
|
||||
DiagnosticFactory3<JetExpression, DeclarationDescriptor, Visibility, DeclarationDescriptor> INVISIBLE_SETTER = DiagnosticFactory3.create(ERROR);
|
||||
|
||||
DiagnosticFactory1<PsiElement, JetKeywordToken> VAL_OR_VAR_ON_LOOP_PARAMETER = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, JetKeywordToken> VAL_OR_VAR_ON_FUN_PARAMETER = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
// Backing fields
|
||||
|
||||
|
||||
+1
@@ -180,6 +180,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(VARIABLE_EXPECTED, "Variable expected");
|
||||
|
||||
MAP.put(VAL_OR_VAR_ON_LOOP_PARAMETER, "''{0}'' on loop parameter is not allowed", TO_STRING);
|
||||
MAP.put(VAL_OR_VAR_ON_FUN_PARAMETER, "''{0}'' on function parameter is not allowed", TO_STRING);
|
||||
|
||||
MAP.put(INITIALIZATION_USING_BACKING_FIELD_CUSTOM_SETTER,
|
||||
"This property has a custom setter, so initialization using backing field required", NAME);
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.lexer.JetKeywordToken;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.util.lazy.RecursionIntolerantLazyValue;
|
||||
import org.jetbrains.jet.util.lazy.RecursionIntolerantLazyValueWithDefault;
|
||||
@@ -440,7 +441,7 @@ public class DescriptorResolver {
|
||||
BindingTrace trace
|
||||
) {
|
||||
List<ValueParameterDescriptor> result = new ArrayList<ValueParameterDescriptor>();
|
||||
for (int i = 0, valueParametersSize = valueParameters.size(); i < valueParametersSize; i++) {
|
||||
for (int i = 0; i < valueParameters.size(); i++) {
|
||||
JetParameter valueParameter = valueParameters.get(i);
|
||||
JetTypeReference typeReference = valueParameter.getTypeReference();
|
||||
|
||||
@@ -453,6 +454,13 @@ public class DescriptorResolver {
|
||||
type = typeResolver.resolveType(parameterScope, typeReference, trace, true);
|
||||
}
|
||||
|
||||
if (!(functionDescriptor instanceof ConstructorDescriptor)) {
|
||||
ASTNode valOrVarNode = valueParameter.getValOrVarNode();
|
||||
if (valOrVarNode != null) {
|
||||
trace.report(VAL_OR_VAR_ON_FUN_PARAMETER.on(valOrVarNode.getPsi(), ((JetKeywordToken) valOrVarNode.getElementType())));
|
||||
}
|
||||
}
|
||||
|
||||
ValueParameterDescriptor valueParameterDescriptor =
|
||||
resolveValueParameterDescriptor(parameterScope, functionDescriptor, valueParameter, i, type, trace);
|
||||
parameterScope.addVariableDescriptor(valueParameterDescriptor);
|
||||
@@ -477,7 +485,7 @@ public class DescriptorResolver {
|
||||
index,
|
||||
annotationResolver.resolveAnnotations(scope, valueParameter.getModifierList(), trace),
|
||||
JetPsiUtil.safeName(valueParameter.getName()),
|
||||
valueParameter.isMutable(),
|
||||
false,
|
||||
variableType,
|
||||
valueParameter.getDefaultValue() != null,
|
||||
varargElementType
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
fun f(
|
||||
<!VAL_OR_VAR_ON_FUN_PARAMETER!>val<!> a: Int,
|
||||
<!VAL_OR_VAR_ON_FUN_PARAMETER!>var<!> b: Int,
|
||||
c: Int,
|
||||
vararg <!VAL_OR_VAR_ON_FUN_PARAMETER!>var<!> d: Int,
|
||||
vararg <!VAL_OR_VAR_ON_FUN_PARAMETER!>val<!> e: Int,
|
||||
vararg f: Int
|
||||
) {
|
||||
|
||||
|
||||
a + b + c + d[0] + e[0] + f[0] // to avoid 'unused parameter'
|
||||
}
|
||||
@@ -1543,6 +1543,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
||||
doTest("compiler/testData/diagnostics/tests/declarationChecks/RedeclarationsInMultiDecl.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("valVarFunctionParameter.kt")
|
||||
public void testValVarFunctionParameter() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/declarationChecks/valVarFunctionParameter.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("VarianceOnFunctionAndPropertyTypeParameters.kt")
|
||||
public void testVarianceOnFunctionAndPropertyTypeParameters() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/declarationChecks/VarianceOnFunctionAndPropertyTypeParameters.kt");
|
||||
|
||||
Reference in New Issue
Block a user