Conventions for ++/-- support Unit-returning inc/dec functions
This commit is contained in:
@@ -213,17 +213,32 @@ public class JetControlFlowProcessor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitUnaryExpression(JetUnaryExpression expression) {
|
public void visitUnaryExpression(JetUnaryExpression expression) {
|
||||||
IElementType operationType = expression.getOperationSign().getReferencedNameElementType();
|
JetSimpleNameExpression operationSign = expression.getOperationSign();
|
||||||
|
IElementType operationType = operationSign.getReferencedNameElementType();
|
||||||
|
JetExpression baseExpression = expression.getBaseExpression();
|
||||||
if (JetTokens.LABELS.contains(operationType)) {
|
if (JetTokens.LABELS.contains(operationType)) {
|
||||||
String referencedName = expression.getOperationSign().getReferencedName();
|
String referencedName = operationSign.getReferencedName();
|
||||||
referencedName = referencedName == null ? " <?>" : referencedName;
|
referencedName = referencedName == null ? " <?>" : referencedName;
|
||||||
visitLabeledExpression(referencedName.substring(1), expression.getBaseExpression());
|
visitLabeledExpression(referencedName.substring(1), baseExpression);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
visitElement(expression);
|
value(baseExpression, false, false);
|
||||||
|
value(operationSign, false, false);
|
||||||
|
|
||||||
|
boolean incrementOrDecrement = isIncrementOrDecrement(operationType);
|
||||||
|
if (incrementOrDecrement) {
|
||||||
|
builder.writeNode(expression, baseExpression);
|
||||||
|
}
|
||||||
|
|
||||||
|
builder.readNode(expression);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isIncrementOrDecrement(IElementType operationType) {
|
||||||
|
return operationType == JetTokens.PLUSPLUS || operationType == JetTokens.MINUSMINUS;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitIfExpression(JetIfExpression expression) {
|
public void visitIfExpression(JetIfExpression expression) {
|
||||||
value(expression.getCondition(), false, true);
|
value(expression.getCondition(), false, true);
|
||||||
@@ -462,6 +477,16 @@ public class JetControlFlowProcessor {
|
|||||||
builder.readNode(expression);
|
builder.readNode(expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void visitBinaryWithTypeRHSExpression(JetBinaryExpressionWithTypeRHS expression) {
|
||||||
|
if (expression.getOperationSign().getReferencedNameElementType() == JetTokens.COLON) {
|
||||||
|
value(expression.getLeft(), false, false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
visitJetElement(expression); // TODO
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitTypeProjection(JetTypeProjection typeProjection) {
|
public void visitTypeProjection(JetTypeProjection typeProjection) {
|
||||||
// TODO : Support Type Arguments. Class object may be initialized at this point");
|
// TODO : Support Type Arguments. Class object may be initialized at this point");
|
||||||
|
|||||||
@@ -362,7 +362,7 @@ public class TopDownAnalyzer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitUnsupportedElementInstruction(UnsupportedElementInstruction instruction) {
|
public void visitUnsupportedElementInstruction(UnsupportedElementInstruction instruction) {
|
||||||
semanticServices.getErrorHandler().genericError(instruction.getElement().getNode(), "Unsupported by control-flow builder");
|
semanticServices.getErrorHandler().genericError(instruction.getElement().getNode(), "Unsupported by control-flow builder " + instruction.getElement());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -1082,11 +1082,16 @@ public class JetTypeInferrer {
|
|||||||
if (functionDescriptor != null) {
|
if (functionDescriptor != null) {
|
||||||
JetType returnType = functionDescriptor.getUnsubstitutedReturnType();
|
JetType returnType = functionDescriptor.getUnsubstitutedReturnType();
|
||||||
if (operationType == JetTokens.PLUSPLUS || operationType == JetTokens.MINUSMINUS) {
|
if (operationType == JetTokens.PLUSPLUS || operationType == JetTokens.MINUSMINUS) {
|
||||||
if (!semanticServices.getTypeChecker().isSubtypeOf(returnType, receiverType)) {
|
if (semanticServices.getTypeChecker().isSubtypeOf(returnType, JetStandardClasses.getUnitType())) {
|
||||||
semanticServices.getErrorHandler().genericError(operationSign.getNode(), name + " must return " + receiverType + " but returns " + returnType);
|
result = JetStandardClasses.getUnitType();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!semanticServices.getTypeChecker().isSubtypeOf(returnType, receiverType)) {
|
||||||
|
semanticServices.getErrorHandler().genericError(operationSign.getNode(), name + " must return " + receiverType + " but returns " + returnType);
|
||||||
|
}
|
||||||
|
// TODO : Maybe returnType?
|
||||||
|
result = receiverType;
|
||||||
}
|
}
|
||||||
// TODO : Maybe returnType?
|
|
||||||
result = receiverType;
|
|
||||||
} else {
|
} else {
|
||||||
result = returnType;
|
result = returnType;
|
||||||
}
|
}
|
||||||
@@ -1386,7 +1391,7 @@ public class JetTypeInferrer {
|
|||||||
String counterpartName = binaryOperationNames.get(assignmentOperationCounterparts.get(operationType));
|
String counterpartName = binaryOperationNames.get(assignmentOperationCounterparts.get(operationType));
|
||||||
getTypeForBinaryCall(expression, counterpartName, scope, true);
|
getTypeForBinaryCall(expression, counterpartName, scope, true);
|
||||||
}
|
}
|
||||||
result = null; // not an element
|
result = null; // not an expression
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
class IncDec {
|
||||||
|
fun inc() : IncDec = this
|
||||||
|
fun dec() : IncDec = this
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testIncDec() {
|
||||||
|
var x = new IncDec()
|
||||||
|
x++
|
||||||
|
++x
|
||||||
|
x--
|
||||||
|
--x
|
||||||
|
x = x++
|
||||||
|
x = x--
|
||||||
|
x = ++x
|
||||||
|
x = --x
|
||||||
|
}
|
||||||
|
|
||||||
|
class WrongIncDec {
|
||||||
|
fun inc() : Int = 1
|
||||||
|
fun dec() : Int = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testWrongIncDec() {
|
||||||
|
var x = new WrongIncDec()
|
||||||
|
x<error>++</error>
|
||||||
|
<error>++</error>x
|
||||||
|
x<error>--</error>
|
||||||
|
<error>--</error>x
|
||||||
|
}
|
||||||
|
|
||||||
|
class UnitIncDec {
|
||||||
|
fun inc() : Unit {}
|
||||||
|
fun dec() : Unit {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testUnitIncDec() {
|
||||||
|
var x = new UnitIncDec()
|
||||||
|
x++
|
||||||
|
++x
|
||||||
|
x--
|
||||||
|
--x
|
||||||
|
x = <error>x++</error>
|
||||||
|
x = <error>x--</error>
|
||||||
|
x = <error>++x</error>
|
||||||
|
x = <error>--x</error>
|
||||||
|
}
|
||||||
@@ -85,3 +85,15 @@ fun <T> tt(t : T) : T {
|
|||||||
1 `std::Int.compareTo(Double)`>= 2.0
|
1 `std::Int.compareTo(Double)`>= 2.0
|
||||||
1 `std::Int.compareTo(Double)`<= 2.0
|
1 `std::Int.compareTo(Double)`<= 2.0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class UnitIncDec {
|
||||||
|
~uinc~fun inc() : Unit
|
||||||
|
~udec~fun dec() : Unit
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testUnitIncDec() {
|
||||||
|
var x = new UnitIncDec()
|
||||||
|
x`uinc`++
|
||||||
|
x`udec`--
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user