check modifiers for local declarations
This commit is contained in:
+5
-1
@@ -124,6 +124,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
||||
}
|
||||
|
||||
scope.addVariableDescriptor(propertyDescriptor);
|
||||
ModifiersChecker.create(context.trace).checkModifiersForLocalDeclaration(property);
|
||||
return DataFlowUtils.checkStatementType(property, context, context.dataFlowInfo);
|
||||
}
|
||||
|
||||
@@ -146,10 +147,13 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
||||
|
||||
@Override
|
||||
public JetTypeInfo visitNamedFunction(JetNamedFunction function, ExpressionTypingContext context) {
|
||||
SimpleFunctionDescriptor functionDescriptor = context.expressionTypingServices.getDescriptorResolver().resolveFunctionDescriptor(scope.getContainingDeclaration(), scope, function, context.trace);
|
||||
SimpleFunctionDescriptor functionDescriptor = context.expressionTypingServices.getDescriptorResolver().
|
||||
resolveFunctionDescriptor(scope.getContainingDeclaration(), scope, function, context.trace);
|
||||
|
||||
scope.addFunctionDescriptor(functionDescriptor);
|
||||
JetScope functionInnerScope = FunctionDescriptorUtil.getFunctionInnerScope(context.scope, functionDescriptor, context.trace);
|
||||
context.expressionTypingServices.checkFunctionReturnType(functionInnerScope, function, functionDescriptor, context.dataFlowInfo, null, context.trace);
|
||||
ModifiersChecker.create(context.trace).checkModifiersForLocalDeclaration(function);
|
||||
return DataFlowUtils.checkStatementType(function, context, context.dataFlowInfo);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,4 +5,4 @@ fun fib(n: Int): Int {
|
||||
return v
|
||||
}
|
||||
|
||||
public val result = fib(num)
|
||||
val result = fib(num)
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package d
|
||||
|
||||
class T {
|
||||
fun baz() = 1
|
||||
}
|
||||
|
||||
fun foo() {
|
||||
<!ILLEGAL_MODIFIER!>public<!> val <!UNUSED_VARIABLE!>i<!> = 11
|
||||
<!ILLEGAL_MODIFIER!>abstract<!> val <!VARIABLE_WITH_NO_TYPE_NO_INITIALIZER, UNUSED_VARIABLE!>j<!>
|
||||
<!ILLEGAL_MODIFIER!>override<!> fun T.baz() = 2
|
||||
<!ILLEGAL_MODIFIER!>private<!> fun bar() = 2
|
||||
}
|
||||
@@ -2,6 +2,5 @@ package test
|
||||
|
||||
public open class MethodTypePTwoUpperBounds() : java.lang.Object() {
|
||||
public open fun <T> foo(): Unit where T : Cloneable?, T : Runnable? {
|
||||
override fun run() = throw UnsupportedOperationException()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1098,6 +1098,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
||||
doTest("compiler/testData/diagnostics/tests/declarationChecks/kt559.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("localDeclarationModifiers.kt")
|
||||
public void testLocalDeclarationModifiers() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/declarationChecks/localDeclarationModifiers.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("LocalVariableWithNoTypeInformation.kt")
|
||||
public void testLocalVariableWithNoTypeInformation() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/declarationChecks/LocalVariableWithNoTypeInformation.kt");
|
||||
@@ -3075,7 +3080,6 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
||||
suite.addTestSuite(DataFlow.class);
|
||||
suite.addTestSuite(DataFlowInfoTraversal.class);
|
||||
suite.addTest(DeclarationChecks.innerSuite());
|
||||
suite.addTestSuite(DeclarationChecks.class);
|
||||
suite.addTestSuite(Enum.class);
|
||||
suite.addTestSuite(Extensions.class);
|
||||
suite.addTestSuite(Generics.class);
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.io.PrintWriter
|
||||
|
||||
private fun generateDownTos(outputFile: File, header: String) {
|
||||
|
||||
private fun getMaxType(fromType: String, toType: String): String {
|
||||
fun getMaxType(fromType: String, toType: String): String {
|
||||
return when {
|
||||
fromType == "Double" || toType == "Double" -> "Double"
|
||||
fromType == "Float" || toType == "Float" -> "Float"
|
||||
@@ -18,7 +18,7 @@ private fun generateDownTos(outputFile: File, header: String) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun generateDownTo(writer: PrintWriter, fromType: String, toType: String) {
|
||||
fun generateDownTo(writer: PrintWriter, fromType: String, toType: String) {
|
||||
val elementType = getMaxType(fromType, toType)
|
||||
val rangeType = elementType + "Range"
|
||||
val fromExpr = "this${ if (elementType == fromType) "" else ".to$elementType()" }"
|
||||
|
||||
Reference in New Issue
Block a user