diff --git a/framework/src/main/java/org/checkerframework/common/basetype/BaseTypeVisitor.java b/framework/src/main/java/org/checkerframework/common/basetype/BaseTypeVisitor.java index dde13779d6..31fe4461aa 100644 --- a/framework/src/main/java/org/checkerframework/common/basetype/BaseTypeVisitor.java +++ b/framework/src/main/java/org/checkerframework/common/basetype/BaseTypeVisitor.java @@ -1843,7 +1843,10 @@ public Void visitLambdaExpression(LambdaExpressionTree node, Void p) { if (ret.getKind() != TypeKind.VOID) { visitorState.setAssignmentContext(Pair.of((Tree) node, ret)); commonAssignmentCheck( - ret, (ExpressionTree) node.getBody(), "return.type.incompatible"); + ret, + (ExpressionTree) node.getBody(), + "return.type.incompatible", + extraArgForReturnTypeError(node.getBody())); } } @@ -1908,7 +1911,11 @@ public Void visitReturn(ReturnTree node, Void p) { if (ret != null) { visitorState.setAssignmentContext(Pair.of((Tree) node, ret)); - commonAssignmentCheck(ret, node.getExpression(), "return.type.incompatible"); + commonAssignmentCheck( + ret, + node.getExpression(), + "return.type.incompatible", + extraArgForReturnTypeError(node.getExpression())); } return super.visitReturn(node, p); } finally { @@ -2790,6 +2797,10 @@ protected final void commonAssignmentCheckEndDiagnostic( } } + protected String extraArgForReturnTypeError(Tree returnedExpression) { + return ""; + } + /** * Class that creates string representations of {@link AnnotatedTypeMirror}s which are only * verbose if required to differentiate the two types. diff --git a/framework/src/main/java/org/checkerframework/common/basetype/messages.properties b/framework/src/main/java/org/checkerframework/common/basetype/messages.properties index 314d6cdf3b..2a80cb4469 100644 --- a/framework/src/main/java/org/checkerframework/common/basetype/messages.properties +++ b/framework/src/main/java/org/checkerframework/common/basetype/messages.properties @@ -10,7 +10,7 @@ unary.increment.type.incompatible=increment result incompatible with variable de unary.decrement.type.incompatible=decrement result incompatible with variable declared type.%nfound : %s%nrequired: %s enhancedfor.type.incompatible=incompatible types in enhanced for loop.%nfound : %s%nrequired: %s vector.copyinto.type.incompatible=incompatible component type in Vector.copyinto.%nfound : %s%nrequired: %s -return.type.incompatible=incompatible types in return.%ntype of expression: %s%nmethod return type: %s +return.type.incompatible=incompatible types in return.%n%stype of expression: %s%nmethod return type: %s annotation.type.incompatible=incompatible types in annotation.%nfound : %s%nrequired: %s conditional.type.incompatible=incompatible types in conditional expression.%nfound : %s%nrequired: %s type.argument.type.incompatible=incompatible type argument for type parameter %s of %s.%nfound : %s%nrequired: %s