use terms "lambda expression" and "anonymous function" instead of "function literal" and "function expression"
This commit is contained in:
@@ -662,7 +662,7 @@ public class KotlinFlowInformationProvider {
|
||||
VariableContext ctxt = new VariableContext(instruction, reportedDiagnosticMap);
|
||||
report(
|
||||
element instanceof KtFunctionLiteralExpression
|
||||
? Errors.UNUSED_FUNCTION_LITERAL.on((KtFunctionLiteralExpression) element)
|
||||
? Errors.UNUSED_LAMBDA_EXPRESSION.on((KtFunctionLiteralExpression) element)
|
||||
: Errors.UNUSED_EXPRESSION.on(element),
|
||||
ctxt
|
||||
);
|
||||
|
||||
@@ -138,7 +138,7 @@ public interface Errors {
|
||||
DiagnosticFactory1<KtAnnotationEntry, String> WRONG_ANNOTATION_TARGET = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory2<KtAnnotationEntry, String, String> WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory0<KtAnnotationEntry> REPEATED_ANNOTATION = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtAnnotationEntry> NON_SOURCE_ANNOTATION_ON_INLINED_FUNCTION_LITERAL = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtAnnotationEntry> NON_SOURCE_ANNOTATION_ON_INLINED_LAMBDA_EXPRESSION = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
// Annotations
|
||||
|
||||
@@ -395,13 +395,14 @@ public interface Errors {
|
||||
DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE);
|
||||
|
||||
DiagnosticFactory0<KtFunction> FUNCTION_DECLARATION_WITH_NO_NAME = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||
DiagnosticFactory0<PsiElement> FUNCTION_EXPRESSION_WITH_NAME = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> ANONYMOUS_FUNCTION_WITH_NAME = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<KtParameter> VALUE_PARAMETER_WITH_NO_TYPE_ANNOTATION = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<KtNamedFunction> NO_TAIL_CALLS_FOUND = DiagnosticFactory0.create(WARNING, DECLARATION_SIGNATURE);
|
||||
|
||||
DiagnosticFactory0<KtParameter> FUNCTION_EXPRESSION_PARAMETER_WITH_DEFAULT_VALUE = DiagnosticFactory0.create(ERROR, PARAMETER_DEFAULT_VALUE);
|
||||
DiagnosticFactory0<KtParameter>
|
||||
ANONYMOUS_FUNCTION_PARAMETER_WITH_DEFAULT_VALUE = DiagnosticFactory0.create(ERROR, PARAMETER_DEFAULT_VALUE);
|
||||
|
||||
DiagnosticFactory0<KtParameter> USELESS_VARARG_ON_PARAMETER = DiagnosticFactory0.create(WARNING);
|
||||
|
||||
@@ -456,7 +457,7 @@ public interface Errors {
|
||||
DiagnosticFactory0<LeafPsiElement> NON_VARARG_SPREAD = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<LeafPsiElement> SPREAD_OF_NULLABLE = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<KtExpression> MANY_FUNCTION_LITERAL_ARGUMENTS = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtExpression> MANY_LAMBDA_EXPRESSION_ARGUMENTS = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory1<PsiElement, CallableDescriptor> TOO_MANY_ARGUMENTS = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
@@ -611,7 +612,7 @@ public interface Errors {
|
||||
DiagnosticFactory2<KtBinaryExpression, KtElement, DeclarationDescriptor> UNUSED_VALUE = DiagnosticFactory2.create(WARNING, PositioningStrategies.UNUSED_VALUE);
|
||||
DiagnosticFactory1<KtElement, KtElement> UNUSED_CHANGED_VALUE = DiagnosticFactory1.create(WARNING);
|
||||
DiagnosticFactory0<KtElement> UNUSED_EXPRESSION = DiagnosticFactory0.create(WARNING);
|
||||
DiagnosticFactory0<KtFunctionLiteralExpression> UNUSED_FUNCTION_LITERAL = DiagnosticFactory0.create(WARNING);
|
||||
DiagnosticFactory0<KtFunctionLiteralExpression> UNUSED_LAMBDA_EXPRESSION = DiagnosticFactory0.create(WARNING);
|
||||
|
||||
DiagnosticFactory1<KtExpression, DeclarationDescriptor> VAL_REASSIGNMENT = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<KtExpression, DeclarationDescriptor> SETTER_PROJECTED_OUT = DiagnosticFactory1.create(ERROR);
|
||||
@@ -633,10 +634,10 @@ public interface Errors {
|
||||
DiagnosticFactory1<PsiElement, KotlinType> UNNECESSARY_SAFE_CALL = DiagnosticFactory1.create(WARNING);
|
||||
DiagnosticFactory0<PsiElement> UNEXPECTED_SAFE_CALL = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, KotlinType> UNNECESSARY_NOT_NULL_ASSERTION = DiagnosticFactory1.create(WARNING);
|
||||
DiagnosticFactory0<PsiElement> NOT_NULL_ASSERTION_ON_FUNCTION_LITERAL = DiagnosticFactory0.create(WARNING);
|
||||
DiagnosticFactory0<PsiElement> NOT_NULL_ASSERTION_ON_LAMBDA_EXPRESSION = DiagnosticFactory0.create(WARNING);
|
||||
|
||||
DiagnosticFactory1<KtBinaryExpression, KotlinType> USELESS_ELVIS = DiagnosticFactory1.create(WARNING, PositioningStrategies.USELESS_ELVIS);
|
||||
DiagnosticFactory0<PsiElement> USELESS_ELVIS_ON_FUNCTION_LITERAL = DiagnosticFactory0.create(WARNING);
|
||||
DiagnosticFactory0<PsiElement> USELESS_ELVIS_ON_LAMBDA_EXPRESSION = DiagnosticFactory0.create(WARNING);
|
||||
|
||||
// Compile-time values
|
||||
|
||||
@@ -758,7 +759,7 @@ public interface Errors {
|
||||
INVISIBLE_MEMBER, INVISIBLE_MEMBER_FROM_INLINE, INVISIBLE_REFERENCE, INVISIBLE_SETTER);
|
||||
ImmutableSet<? extends DiagnosticFactory<?>> UNUSED_ELEMENT_DIAGNOSTICS = ImmutableSet.of(
|
||||
UNUSED_VARIABLE, UNUSED_PARAMETER, ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE, VARIABLE_WITH_REDUNDANT_INITIALIZER,
|
||||
UNUSED_FUNCTION_LITERAL, USELESS_CAST, UNUSED_VALUE, USELESS_ELVIS);
|
||||
UNUSED_LAMBDA_EXPRESSION, USELESS_CAST, UNUSED_VALUE, USELESS_ELVIS);
|
||||
ImmutableSet<? extends DiagnosticFactory<?>> TYPE_INFERENCE_ERRORS = ImmutableSet.of(
|
||||
TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER, TYPE_INFERENCE_CONFLICTING_SUBSTITUTIONS,
|
||||
TYPE_INFERENCE_PARAMETER_CONSTRAINT_ERROR,
|
||||
|
||||
+7
-7
@@ -137,7 +137,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(WRONG_ANNOTATION_TARGET, "This annotation is not applicable to target ''{0}''", TO_STRING);
|
||||
MAP.put(WRONG_ANNOTATION_TARGET_WITH_USE_SITE_TARGET, "This annotation is not applicable to target ''{0}'' and use site target ''@{1}''", TO_STRING, TO_STRING);
|
||||
MAP.put(REPEATED_ANNOTATION, "This annotation is not repeatable");
|
||||
MAP.put(NON_SOURCE_ANNOTATION_ON_INLINED_FUNCTION_LITERAL, "Function literal here is an inlined argument so this annotation cannot be stored anywhere");
|
||||
MAP.put(NON_SOURCE_ANNOTATION_ON_INLINED_LAMBDA_EXPRESSION, "The lambda expression here is an inlined argument so this annotation cannot be stored anywhere");
|
||||
|
||||
MAP.put(INAPPLICABLE_TARGET_ON_PROPERTY, "''@{0}'' annotations could be applied only to property declarations", TO_STRING);
|
||||
MAP.put(INAPPLICABLE_FIELD_TARGET_NO_BACKING_FIELD, "Property has neither a backing field nor a delegate");
|
||||
@@ -187,7 +187,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(NON_VARARG_SPREAD, "The spread operator (*foo) may only be applied in a vararg position");
|
||||
MAP.put(SPREAD_OF_NULLABLE, "The spread operator (*foo) may not be applied to an argument of nullable type");
|
||||
|
||||
MAP.put(MANY_FUNCTION_LITERAL_ARGUMENTS, "Only one function literal is allowed outside a parenthesized argument list");
|
||||
MAP.put(MANY_LAMBDA_EXPRESSION_ARGUMENTS, "Only one lambda expression is allowed outside a parenthesized argument list");
|
||||
MAP.put(PROPERTY_WITH_NO_TYPE_NO_INITIALIZER, "This property must either have a type annotation, be initialized or be delegated");
|
||||
MAP.put(VARIABLE_WITH_NO_TYPE_NO_INITIALIZER, "This variable must either have a type annotation or be initialized");
|
||||
|
||||
@@ -228,10 +228,10 @@ public class DefaultErrorMessages {
|
||||
|
||||
MAP.put(NON_MEMBER_FUNCTION_NO_BODY, "Function ''{0}'' must have a body", NAME);
|
||||
MAP.put(FUNCTION_DECLARATION_WITH_NO_NAME, "Function declaration must have a name");
|
||||
MAP.put(FUNCTION_EXPRESSION_WITH_NAME, "Function expressions with names are prohibited");
|
||||
MAP.put(ANONYMOUS_FUNCTION_WITH_NAME, "Anonymous functions with names are prohibited");
|
||||
MAP.put(NON_FINAL_MEMBER_IN_FINAL_CLASS, "\"open\" has no effect in a final class");
|
||||
|
||||
MAP.put(FUNCTION_EXPRESSION_PARAMETER_WITH_DEFAULT_VALUE, "A function expression is not allowed to specify default values for its parameters");
|
||||
MAP.put(ANONYMOUS_FUNCTION_PARAMETER_WITH_DEFAULT_VALUE, "An anonymous function is not allowed to specify default values for its parameters");
|
||||
MAP.put(USELESS_VARARG_ON_PARAMETER, "Vararg on this parameter is useless");
|
||||
|
||||
MAP.put(PROJECTION_ON_NON_CLASS_TYPE_ARGUMENT, "Projections are not allowed on type arguments of functions and properties");
|
||||
@@ -256,7 +256,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(UNUSED_VALUE, "The value ''{0}'' assigned to ''{1}'' is never used", ELEMENT_TEXT, FQ_NAMES_IN_TYPES);
|
||||
MAP.put(UNUSED_CHANGED_VALUE, "The value changed at ''{0}'' is never used", ELEMENT_TEXT);
|
||||
MAP.put(UNUSED_EXPRESSION, "The expression is unused");
|
||||
MAP.put(UNUSED_FUNCTION_LITERAL, "The function literal is unused. If you mean block, you can use 'run { ... }'");
|
||||
MAP.put(UNUSED_LAMBDA_EXPRESSION, "The lambda expression is unused. If you mean a block, you can use 'run { ... }'");
|
||||
|
||||
MAP.put(VAL_REASSIGNMENT, "Val cannot be reassigned", NAME);
|
||||
MAP.put(SETTER_PROJECTED_OUT, "Setter for ''{0}'' is removed by type projection", NAME);
|
||||
@@ -399,7 +399,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(REPEATED_BOUND, "Type parameter already has this bound");
|
||||
MAP.put(DYNAMIC_UPPER_BOUND, "Dynamic type can not be used as an upper bound");
|
||||
MAP.put(USELESS_ELVIS, "Elvis operator (?:) always returns the left operand of non-nullable type {0}", RENDER_TYPE);
|
||||
MAP.put(USELESS_ELVIS_ON_FUNCTION_LITERAL, "Left operand of elvis operator (?:) is function literal");
|
||||
MAP.put(USELESS_ELVIS_ON_LAMBDA_EXPRESSION, "Left operand of elvis operator (?:) is a lambda expression");
|
||||
MAP.put(CONFLICTING_UPPER_BOUNDS, "Upper bounds of {0} have empty intersection", NAME);
|
||||
|
||||
MAP.put(TOO_MANY_ARGUMENTS, "Too many arguments for {0}", FQ_NAMES_IN_TYPES);
|
||||
@@ -475,7 +475,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(UNNECESSARY_SAFE_CALL, "Unnecessary safe call on a non-null receiver of type {0}", RENDER_TYPE);
|
||||
MAP.put(UNEXPECTED_SAFE_CALL, "Safe-call is not allowed here");
|
||||
MAP.put(UNNECESSARY_NOT_NULL_ASSERTION, "Unnecessary non-null assertion (!!) on a non-null receiver of type {0}", RENDER_TYPE);
|
||||
MAP.put(NOT_NULL_ASSERTION_ON_FUNCTION_LITERAL, "Non-null assertion (!!) is called on function literal");
|
||||
MAP.put(NOT_NULL_ASSERTION_ON_LAMBDA_EXPRESSION, "Non-null assertion (!!) is called on a lambda expression");
|
||||
MAP.put(NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER, "{0} does not refer to a type parameter of {1}", new Renderer<KtTypeConstraint>() {
|
||||
@NotNull
|
||||
@Override
|
||||
|
||||
@@ -71,7 +71,7 @@ public abstract class KtFunctionNotStubbed extends KtTypeParameterListOwnerNotSt
|
||||
@Override
|
||||
public KtTypeReference setTypeReference(@Nullable KtTypeReference typeRef) {
|
||||
if (typeRef == null) return null;
|
||||
throw new IllegalStateException("Function literals can't have type reference");
|
||||
throw new IllegalStateException("Lambda expressions can't have type reference");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -114,7 +114,7 @@ public class AnnotationChecker(private val additionalCheckers: Iterable<Addition
|
||||
|
||||
val functionLiteralExpression = annotatedExpression.baseExpression as? KtFunctionLiteralExpression ?: return
|
||||
if (InlineUtil.isInlinedArgument(functionLiteralExpression.functionLiteral, trace.bindingContext, false)) {
|
||||
trace.report(Errors.NON_SOURCE_ANNOTATION_ON_INLINED_FUNCTION_LITERAL.on(entry))
|
||||
trace.report(Errors.NON_SOURCE_ANNOTATION_ON_INLINED_LAMBDA_EXPRESSION.on(entry))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ public class AnnotationChecker(private val additionalCheckers: Iterable<Addition
|
||||
is KtTypeProjection ->
|
||||
if (annotated.projectionKind == KtProjectionKind.STAR) TargetLists.T_STAR_PROJECTION else TargetLists.T_TYPE_PROJECTION
|
||||
is KtAnonymousInitializer -> TargetLists.T_INITIALIZER
|
||||
is KtMultiDeclaration -> TargetLists.T_MULTI_DECLARATION
|
||||
is KtMultiDeclaration -> TargetLists.T_DESTRUCTURING_DECLARATION
|
||||
is KtFunctionLiteralExpression -> TargetLists.T_FUNCTION_LITERAL
|
||||
is KtObjectLiteralExpression -> TargetLists.T_OBJECT_LITERAL
|
||||
is KtExpression -> TargetLists.T_EXPRESSION
|
||||
@@ -218,7 +218,7 @@ public class AnnotationChecker(private val additionalCheckers: Iterable<Addition
|
||||
onlyWithUseSiteTarget(PROPERTY, FIELD, PROPERTY_GETTER, PROPERTY_SETTER, VALUE_PARAMETER)
|
||||
}
|
||||
|
||||
val T_MULTI_DECLARATION = targetList(MULTI_DECLARATION)
|
||||
val T_DESTRUCTURING_DECLARATION = targetList(DESTRUCTURING_DECLARATION)
|
||||
|
||||
val T_MEMBER_PROPERTY = targetList(MEMBER_PROPERTY, PROPERTY) {
|
||||
extraTargets(FIELD)
|
||||
@@ -260,9 +260,9 @@ public class AnnotationChecker(private val additionalCheckers: Iterable<Addition
|
||||
|
||||
val T_EXPRESSION = targetList(EXPRESSION)
|
||||
|
||||
val T_FUNCTION_LITERAL = targetList(FUNCTION_LITERAL, FUNCTION, EXPRESSION)
|
||||
val T_FUNCTION_LITERAL = targetList(LAMBDA_EXPRESSION, FUNCTION, EXPRESSION)
|
||||
|
||||
val T_FUNCTION_EXPRESSION = targetList(FUNCTION_EXPRESSION, FUNCTION, EXPRESSION)
|
||||
val T_FUNCTION_EXPRESSION = targetList(ANONYMOUS_FUNCTION, FUNCTION, EXPRESSION)
|
||||
|
||||
val T_OBJECT_LITERAL = targetList(OBJECT_LITERAL, CLASS, EXPRESSION)
|
||||
|
||||
|
||||
+1
-1
@@ -284,7 +284,7 @@ public class ValueArgumentsToParametersMapper {
|
||||
|
||||
for (int i = 1; i < functionLiteralArguments.size(); i++) {
|
||||
KtExpression argument = functionLiteralArguments.get(i).getArgumentExpression();
|
||||
report(MANY_FUNCTION_LITERAL_ARGUMENTS.on(argument));
|
||||
report(MANY_LAMBDA_EXPRESSION_ARGUMENTS.on(argument));
|
||||
setStatus(WEAK_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -926,7 +926,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
KotlinTypeInfo baseTypeInfo = BindingContextUtils.getRecordedTypeInfo(baseExpression, context.trace.getBindingContext());
|
||||
|
||||
if (ArgumentTypeResolver.isFunctionLiteralArgument(baseExpression, context)) {
|
||||
context.trace.report(NOT_NULL_ASSERTION_ON_FUNCTION_LITERAL.on(operationSign));
|
||||
context.trace.report(NOT_NULL_ASSERTION_ON_LAMBDA_EXPRESSION.on(operationSign));
|
||||
return baseTypeInfo;
|
||||
}
|
||||
assert baseTypeInfo != null : "Base expression was not processed: " + expression;
|
||||
@@ -1261,7 +1261,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
Lists.newArrayList(true, false), contextWithExpectedType, null);
|
||||
KotlinTypeInfo leftTypeInfo = BindingContextUtils.getRecordedTypeInfo(left, context.trace.getBindingContext());
|
||||
if (ArgumentTypeResolver.isFunctionLiteralArgument(left, context)) {
|
||||
context.trace.report(USELESS_ELVIS_ON_FUNCTION_LITERAL.on(expression.getOperationReference()));
|
||||
context.trace.report(USELESS_ELVIS_ON_LAMBDA_EXPRESSION.on(expression.getOperationReference()));
|
||||
if (leftTypeInfo == null) return TypeInfoFactoryKt.noTypeInfo(context);
|
||||
}
|
||||
assert leftTypeInfo != null : "Left expression was not processed: " + expression;
|
||||
|
||||
+2
-2
@@ -60,12 +60,12 @@ internal class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Expre
|
||||
}
|
||||
|
||||
if (function.getName() != null) {
|
||||
context.trace.report(FUNCTION_EXPRESSION_WITH_NAME.on(function.getNameIdentifier()))
|
||||
context.trace.report(ANONYMOUS_FUNCTION_WITH_NAME.on(function.getNameIdentifier()))
|
||||
}
|
||||
|
||||
for (parameter in function.getValueParameters()) {
|
||||
if (parameter.hasDefaultValue()) {
|
||||
context.trace.report(FUNCTION_EXPRESSION_PARAMETER_WITH_DEFAULT_VALUE.on(parameter))
|
||||
context.trace.report(ANONYMOUS_FUNCTION_PARAMETER_WITH_DEFAULT_VALUE.on(parameter))
|
||||
}
|
||||
if (parameter.isVarArg()) {
|
||||
context.trace.report(USELESS_VARARG_ON_PARAMETER.on(parameter))
|
||||
|
||||
@@ -20,8 +20,8 @@ fun foo(arg: Int) {
|
||||
// Literal is annotatable
|
||||
bar @FunAnn { arg }
|
||||
// Annotatable in principle but useless, fast is inline
|
||||
fast <!NON_SOURCE_ANNOTATION_ON_INLINED_FUNCTION_LITERAL!>@FunAnn<!> { arg }
|
||||
fast2(1, <!NON_SOURCE_ANNOTATION_ON_INLINED_FUNCTION_LITERAL!>@FunAnn<!> { arg })
|
||||
fast <!NON_SOURCE_ANNOTATION_ON_INLINED_LAMBDA_EXPRESSION!>@FunAnn<!> { arg }
|
||||
fast2(1, <!NON_SOURCE_ANNOTATION_ON_INLINED_LAMBDA_EXPRESSION!>@FunAnn<!> { arg })
|
||||
// Source annotation, ok
|
||||
fast @SourceAnn { arg }
|
||||
fast2(1, @SourceAnn { arg })
|
||||
|
||||
+1
-1
@@ -24,5 +24,5 @@ fun test() {
|
||||
|
||||
foo(<!TYPE_MISMATCH!>""<!>, <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>) <!TOO_MANY_ARGUMENTS!>{}<!>
|
||||
|
||||
foo(<!TYPE_MISMATCH!>""<!>, <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>) <!TOO_MANY_ARGUMENTS!>{}<!> <!MANY_FUNCTION_LITERAL_ARGUMENTS!>{}<!>
|
||||
foo(<!TYPE_MISMATCH!>""<!>, <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>) <!TOO_MANY_ARGUMENTS!>{}<!> <!MANY_LAMBDA_EXPRESSION_ARGUMENTS!>{}<!>
|
||||
}
|
||||
@@ -29,7 +29,7 @@ fun test2(s : String) : Int? {
|
||||
Integer.parseInt(s)
|
||||
22
|
||||
} finally {
|
||||
<!UNUSED_FUNCTION_LITERAL!>{
|
||||
<!UNUSED_LAMBDA_EXPRESSION!>{
|
||||
x : Int -> x
|
||||
}<!>
|
||||
}
|
||||
|
||||
+5
-5
@@ -3,13 +3,13 @@
|
||||
fun use(a: Any?) = a
|
||||
|
||||
fun test() {
|
||||
{ }<!NOT_NULL_ASSERTION_ON_FUNCTION_LITERAL!>!!<!>
|
||||
use({ }<!NOT_NULL_ASSERTION_ON_FUNCTION_LITERAL!>!!<!>);
|
||||
{ }<!NOT_NULL_ASSERTION_ON_LAMBDA_EXPRESSION!>!!<!>
|
||||
use({ }<!NOT_NULL_ASSERTION_ON_LAMBDA_EXPRESSION!>!!<!>);
|
||||
|
||||
// KT-KT-9070
|
||||
<!TYPE_MISMATCH!>{ }<!> <!USELESS_ELVIS!><!USELESS_ELVIS_ON_FUNCTION_LITERAL!>?:<!> 1<!>
|
||||
use({ 2 } <!USELESS_ELVIS_ON_FUNCTION_LITERAL!>?:<!> 1);
|
||||
<!TYPE_MISMATCH!>{ }<!> <!USELESS_ELVIS!><!USELESS_ELVIS_ON_LAMBDA_EXPRESSION!>?:<!> 1<!>
|
||||
use({ 2 } <!USELESS_ELVIS_ON_LAMBDA_EXPRESSION!>?:<!> 1);
|
||||
|
||||
1 <!USELESS_ELVIS!>?: <!TYPE_MISMATCH, UNUSED_FUNCTION_LITERAL!>{ }<!><!>
|
||||
1 <!USELESS_ELVIS!>?: <!TYPE_MISMATCH, UNUSED_LAMBDA_EXPRESSION!>{ }<!><!>
|
||||
use(1 <!USELESS_ELVIS!>?: { }<!>)
|
||||
}
|
||||
+3
-3
@@ -3,9 +3,9 @@ fun foo() {
|
||||
|
||||
class A
|
||||
fun bar() {}
|
||||
(fun <!FUNCTION_EXPRESSION_WITH_NAME!>bar<!>() {})
|
||||
(fun <!ANONYMOUS_FUNCTION_WITH_NAME!>bar<!>() {})
|
||||
fun A.foo() {}
|
||||
(fun A.<!FUNCTION_EXPRESSION_WITH_NAME!>foo<!>() {})
|
||||
(fun A.<!ANONYMOUS_FUNCTION_WITH_NAME!>foo<!>() {})
|
||||
|
||||
run(fun <!FUNCTION_EXPRESSION_WITH_NAME!>foo<!>() {})
|
||||
run(fun <!ANONYMOUS_FUNCTION_WITH_NAME!>foo<!>() {})
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
|
||||
|
||||
val bar = fun(p: Int = <!FUNCTION_EXPRESSION_PARAMETER_WITH_DEFAULT_VALUE!>3<!>) {}
|
||||
val bar = fun(p: Int = <!ANONYMOUS_FUNCTION_PARAMETER_WITH_DEFAULT_VALUE!>3<!>) {}
|
||||
val bas = fun(<!USELESS_VARARG_ON_PARAMETER!>vararg p: Int<!>) {}
|
||||
|
||||
fun gar() = fun(p: Int = <!FUNCTION_EXPRESSION_PARAMETER_WITH_DEFAULT_VALUE!>3<!>) {}
|
||||
fun gar() = fun(p: Int = <!ANONYMOUS_FUNCTION_PARAMETER_WITH_DEFAULT_VALUE!>3<!>) {}
|
||||
fun gas() = fun(<!USELESS_VARARG_ON_PARAMETER!>vararg p: Int<!>) {}
|
||||
|
||||
fun outer(b: Any?) {
|
||||
val bar = fun(p: Int = <!FUNCTION_EXPRESSION_PARAMETER_WITH_DEFAULT_VALUE!>3<!>) {}
|
||||
val bar = fun(p: Int = <!ANONYMOUS_FUNCTION_PARAMETER_WITH_DEFAULT_VALUE!>3<!>) {}
|
||||
val bas = fun(<!USELESS_VARARG_ON_PARAMETER!>vararg p: Int<!>) {}
|
||||
|
||||
fun gar() = fun(p: Int = <!FUNCTION_EXPRESSION_PARAMETER_WITH_DEFAULT_VALUE!>3<!>) {}
|
||||
fun gar() = fun(p: Int = <!ANONYMOUS_FUNCTION_PARAMETER_WITH_DEFAULT_VALUE!>3<!>) {}
|
||||
fun gas() = fun(<!USELESS_VARARG_ON_PARAMETER!>vararg p: Int<!>) {}
|
||||
|
||||
outer(fun(p: Int = <!FUNCTION_EXPRESSION_PARAMETER_WITH_DEFAULT_VALUE!>3<!>) {})
|
||||
outer(fun(p: Int = <!ANONYMOUS_FUNCTION_PARAMETER_WITH_DEFAULT_VALUE!>3<!>) {})
|
||||
outer(fun(<!USELESS_VARARG_ON_PARAMETER!>vararg p: Int<!>) {})
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
fun unusedLiteral(){
|
||||
<!UNUSED_FUNCTION_LITERAL!>{ ->
|
||||
<!UNUSED_LAMBDA_EXPRESSION!>{ ->
|
||||
val <!UNUSED_VARIABLE!>i<!> = 1
|
||||
}<!>
|
||||
}
|
||||
|
||||
|
||||
fun unusedLiteralInDoWhile(){
|
||||
do<!UNUSED_FUNCTION_LITERAL!>{ ->
|
||||
do<!UNUSED_LAMBDA_EXPRESSION!>{ ->
|
||||
val <!UNUSED_VARIABLE!>i<!> = 1
|
||||
}<!> while(false)
|
||||
}
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
fun main(args: Array<String>) {
|
||||
"".run {
|
||||
<!UNUSED_FUNCTION_LITERAL!>{}<!>
|
||||
<!UNUSED_LAMBDA_EXPRESSION!>{}<!>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@ package b
|
||||
|
||||
fun foo() {
|
||||
for (i in <!UNRESOLVED_REFERENCE!>collection<!>) {
|
||||
<!UNUSED_FUNCTION_LITERAL!>{
|
||||
<!UNUSED_LAMBDA_EXPRESSION!>{
|
||||
<!BREAK_OR_CONTINUE_JUMPS_ACROSS_FUNCTION_BOUNDARY!>break<!>
|
||||
}<!>
|
||||
}<!SYNTAX!><!>
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fun nonlocals(b : Boolean) {
|
||||
a@<!UNUSED_FUNCTION_LITERAL!>{
|
||||
a@<!UNUSED_LAMBDA_EXPRESSION!>{
|
||||
fun foo() {
|
||||
if (b) {
|
||||
<!RETURN_NOT_ALLOWED!>return@a 1<!> // The label must be resolved, but an error should be reported for a non-local return
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package kt402
|
||||
|
||||
fun getTypeChecker() : (Any)->Boolean {
|
||||
<!UNUSED_FUNCTION_LITERAL!>{ a : Any -> a is <!UNRESOLVED_REFERENCE!>T<!> }<!> // reports unsupported
|
||||
<!UNUSED_LAMBDA_EXPRESSION!>{ a : Any -> a is <!UNRESOLVED_REFERENCE!>T<!> }<!> // reports unsupported
|
||||
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
|
||||
fun f() : (Any) -> Boolean {
|
||||
return { a : Any -> a is String }
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
fun f(<!UNUSED_PARAMETER!>i<!>: Int) {
|
||||
for (j in 1..100) {
|
||||
<!UNUSED_FUNCTION_LITERAL!>{
|
||||
<!UNUSED_LAMBDA_EXPRESSION!>{
|
||||
var <!NAME_SHADOWING, UNUSED_VARIABLE!>i<!> = 12
|
||||
}<!>
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
fun ff(): Int {
|
||||
var i = 1
|
||||
<!UNUSED_FUNCTION_LITERAL!>{
|
||||
<!UNUSED_LAMBDA_EXPRESSION!>{
|
||||
val <!NAME_SHADOWING, UNUSED_VARIABLE!>i<!> = 2
|
||||
}<!>
|
||||
return i
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fun f(): Int {
|
||||
var i = 17
|
||||
<!UNUSED_FUNCTION_LITERAL!>{ var <!NAME_SHADOWING, UNUSED_VARIABLE!>i<!> = 18 }<!>
|
||||
<!UNUSED_LAMBDA_EXPRESSION!>{ var <!NAME_SHADOWING, UNUSED_VARIABLE!>i<!> = 18 }<!>
|
||||
return i
|
||||
}
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
fun ff(): Int {
|
||||
var i = 1
|
||||
<!UNUSED_FUNCTION_LITERAL!>{ i: Int -> i }<!>
|
||||
<!UNUSED_LAMBDA_EXPRESSION!>{ i: Int -> i }<!>
|
||||
return i
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ fun x(): Boolean { return true }
|
||||
|
||||
public fun foo(p: String?): Int {
|
||||
// Exotic variant with unused literal
|
||||
do <!UNUSED_FUNCTION_LITERAL!>{ ->
|
||||
do <!UNUSED_LAMBDA_EXPRESSION!>{ ->
|
||||
p!!.length
|
||||
}<!> while (!x())
|
||||
// Literal is not called so p.length is unsafe
|
||||
|
||||
@@ -61,9 +61,9 @@ public enum class KotlinTarget(val description: String, val isDefault: Boolean =
|
||||
TOP_LEVEL_PROPERTY("top level property", false),
|
||||
|
||||
INITIALIZER("initializer", false),
|
||||
MULTI_DECLARATION("multi declaration", false),
|
||||
FUNCTION_LITERAL("function literal", false),
|
||||
FUNCTION_EXPRESSION("function expression", false),
|
||||
DESTRUCTURING_DECLARATION("destructuring declaration", false),
|
||||
LAMBDA_EXPRESSION("lambda expression", false),
|
||||
ANONYMOUS_FUNCTION("anonymous function", false),
|
||||
OBJECT_LITERAL("object literal", false)
|
||||
;
|
||||
|
||||
|
||||
@@ -76,6 +76,6 @@ internal object EmptyContainerForLocal : KDeclarationContainerImpl() {
|
||||
|
||||
override fun getFunctions(name: Name): Collection<FunctionDescriptor> = fail()
|
||||
|
||||
private fun fail() = throw KotlinReflectionInternalError("Introspecting local functions, lambdas and function expressions " +
|
||||
private fun fail() = throw KotlinReflectionInternalError("Introspecting local functions, lambdas and anonymous functions " +
|
||||
"is not yet fully supported in Kotlin reflection")
|
||||
}
|
||||
|
||||
@@ -48,7 +48,6 @@ add.semicolon.after.invocation=Add semicolon after invocation of ''{0}''
|
||||
add.semicolon.family=Add Semicolon
|
||||
change.function.return.type=Change ''{0}'' function return type to ''{1}''
|
||||
change.no.name.function.return.type=Change function return type to ''{0}''
|
||||
change.function.literal.return.type=Change function literal return type to ''{0}''
|
||||
remove.function.return.type=Remove explicitly specified return type in ''{0}'' function
|
||||
remove.no.name.function.return.type=Remove explicitly specified function return type
|
||||
change.element.type=Change ''{0}'' type to ''{1}''
|
||||
@@ -106,7 +105,7 @@ change.visibility.modifier=Change visibility modifier
|
||||
|
||||
options.kotlin.attribute.descriptor.builtin.annotation=Built-in annotation
|
||||
options.kotlin.attribute.descriptor.string.escape=Escape in string and template braces
|
||||
options.kotlin.attribute.descriptor.closure.braces=Function literal braces and arrow
|
||||
options.kotlin.attribute.descriptor.closure.braces=Lambda expression braces and arrow
|
||||
options.kotlin.attribute.descriptor.safe.access=Safe access dot
|
||||
options.kotlin.attribute.descriptor.arrow=Arrow
|
||||
options.kotlin.attribute.descriptor.kdoc.comment=KDoc comment
|
||||
@@ -124,7 +123,7 @@ options.kotlin.attribute.descriptor.property.with.backing=Property with backing
|
||||
options.kotlin.attribute.descriptor.field=Backing field variable
|
||||
options.kotlin.attribute.descriptor.extension.property=Extension property
|
||||
options.kotlin.attribute.descriptor.dynamic.property=Dynamic property
|
||||
options.kotlin.attribute.descriptor.it=Function literal default parameter
|
||||
options.kotlin.attribute.descriptor.it=Lambda expression default parameter
|
||||
options.kotlin.attribute.descriptor.fun=Function declaration
|
||||
options.kotlin.attribute.descriptor.fun.call=Function call
|
||||
options.kotlin.attribute.descriptor.dynamic.fun.call=Dynamic function call
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
This intention replaces the explicit parameter of a single-parameter function literal with the implicit 'it' parameter.
|
||||
This intention replaces the explicit parameter of a single-parameter lambda expression with the implicit 'it' parameter.
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
This intention replaces the implicit 'it' parameter in a function literal with an explicitly named parameter.
|
||||
This intention replaces the implicit 'it' parameter in a lambda expression with an explicitly named parameter.
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -116,8 +116,8 @@ public class ChangeFunctionLiteralReturnTypeFix extends KotlinQuickFixAction<KtF
|
||||
if (appropriateQuickFix != null) {
|
||||
return appropriateQuickFix.getText();
|
||||
}
|
||||
return KotlinBundle
|
||||
.message("change.function.literal.return.type", IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderType(type));
|
||||
return String.format("Change lambda expression return type to '%s'",
|
||||
IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderType(type));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -36,7 +36,7 @@ class ChangeFunctionLiteralSignatureFix private constructor(
|
||||
private val parameterTypes: List<KotlinType>
|
||||
) : ChangeFunctionSignatureFix(functionLiteral, functionDescriptor) {
|
||||
|
||||
override fun getText() = "Change the signature of function literal"
|
||||
override fun getText() = "Change the signature of lambda expression"
|
||||
|
||||
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
|
||||
runChangeSignature(
|
||||
|
||||
@@ -312,7 +312,7 @@ public class QuickFixRegistrar : QuickFixContributor {
|
||||
MISSING_CONSTRUCTOR_KEYWORD.registerFactory(MissingConstructorKeywordFix,
|
||||
MissingConstructorKeywordFix.createWholeProjectFixFactory())
|
||||
|
||||
FUNCTION_EXPRESSION_WITH_NAME.registerFactory(RemoveNameFromFunctionExpressionFix)
|
||||
ANONYMOUS_FUNCTION_WITH_NAME.registerFactory(RemoveNameFromFunctionExpressionFix)
|
||||
|
||||
UNRESOLVED_REFERENCE.registerFactory(ReplaceObsoleteLabelSyntaxFix,
|
||||
ReplaceObsoleteLabelSyntaxFix.createWholeProjectFixFactory())
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.psi.psiUtil.forEachDescendantOfType
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
|
||||
public class RemoveNameFromFunctionExpressionFix(element: KtNamedFunction) : KotlinQuickFixAction<KtNamedFunction>(element), CleanupFix {
|
||||
override fun getText(): String = "Remove identifier from function expression"
|
||||
override fun getText(): String = "Remove identifier from anonymous function"
|
||||
override fun getFamilyName(): String = getText()
|
||||
|
||||
override fun invoke(project: Project, editor: Editor?, file: KtFile) = removeNameFromFunction(element)
|
||||
|
||||
Vendored
+1
-1
@@ -2,7 +2,7 @@ fun test(<warning textAttributesKey="NOT_USED_ELEMENT_ATTRIBUTES">unusedParam</w
|
||||
val str = ":)"
|
||||
str <warning textAttributesKey="NOT_USED_ELEMENT_ATTRIBUTES">as String</warning> // USELESS_CAST
|
||||
|
||||
// UNUSED_FUNCTION_LITERAL
|
||||
// UNUSED_LAMBDA_EXPRESSION
|
||||
<warning textAttributesKey="NOT_USED_ELEMENT_ATTRIBUTES">{
|
||||
test(0)
|
||||
}</warning>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Change the signature of function literal" "true"
|
||||
// "Change the signature of lambda expression" "true"
|
||||
// DISABLE-ERRORS
|
||||
|
||||
fun f(x: Int, y: Int, z : () -> Int) {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Change the signature of function literal" "true"
|
||||
// "Change the signature of lambda expression" "true"
|
||||
// DISABLE-ERRORS
|
||||
|
||||
fun f(x: Int, y: Int, z : () -> Int) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Change the signature of function literal" "true"
|
||||
// "Change the signature of lambda expression" "true"
|
||||
// DISABLE-ERRORS
|
||||
|
||||
fun f(x: Int, y: Int, z : (Int, Int?, Any) -> Int) {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Change the signature of function literal" "true"
|
||||
// "Change the signature of lambda expression" "true"
|
||||
// DISABLE-ERRORS
|
||||
|
||||
fun f(x: Int, y: Int, z : (Int, Int?, Any) -> Int) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Change the signature of function literal" "true"
|
||||
// "Change the signature of lambda expression" "true"
|
||||
|
||||
fun foo(f: Int.(Int, Int) -> Int) {
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Change the signature of function literal" "true"
|
||||
// "Change the signature of lambda expression" "true"
|
||||
|
||||
fun foo(f: Int.(Int, Int) -> Int) {
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Change the signature of function literal" "true"
|
||||
// "Change the signature of lambda expression" "true"
|
||||
// DISABLE-ERRORS
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Change the signature of function literal" "true"
|
||||
// "Change the signature of lambda expression" "true"
|
||||
// DISABLE-ERRORS
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// "Remove identifier from function expression" "true"
|
||||
// "Remove identifier from anonymous function" "true"
|
||||
|
||||
fun foo() {
|
||||
(fun bar<caret>() {
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// "Remove identifier from function expression" "true"
|
||||
// "Remove identifier from anonymous function" "true"
|
||||
|
||||
fun foo() {
|
||||
(bar@ fun() {
|
||||
|
||||
Reference in New Issue
Block a user