Unary + and - for numbers
This commit is contained in:
@@ -104,6 +104,8 @@ class Double : Number, Comparable<Double> {
|
||||
|
||||
fun inc() : Double
|
||||
fun dec() : Double
|
||||
fun plus() : Double
|
||||
fun minus() : Double
|
||||
}
|
||||
|
||||
class Float : Number, Comparable<Float> {
|
||||
@@ -165,6 +167,8 @@ class Float : Number, Comparable<Float> {
|
||||
|
||||
fun inc() : Float
|
||||
fun dec() : Float
|
||||
fun plus() : Float
|
||||
fun minus() : Float
|
||||
}
|
||||
|
||||
class Long : Number, Comparable<Long> {
|
||||
@@ -226,6 +230,8 @@ class Long : Number, Comparable<Long> {
|
||||
|
||||
fun inc() : Long
|
||||
fun dec() : Long
|
||||
fun plus() : Long
|
||||
fun minus() : Long
|
||||
}
|
||||
|
||||
class Int : Number, Comparable<Int> {
|
||||
@@ -287,6 +293,8 @@ class Int : Number, Comparable<Int> {
|
||||
|
||||
fun inc() : Int
|
||||
fun dec() : Int
|
||||
fun plus() : Int
|
||||
fun minus() : Int
|
||||
}
|
||||
|
||||
class Char : Number, Comparable<Char> {
|
||||
@@ -348,6 +356,8 @@ class Char : Number, Comparable<Char> {
|
||||
|
||||
fun inc() : Char
|
||||
fun dec() : Char
|
||||
fun plus() : Int
|
||||
fun minus() : Int
|
||||
}
|
||||
|
||||
class Short : Number, Comparable<Char> {
|
||||
@@ -409,6 +419,8 @@ class Short : Number, Comparable<Char> {
|
||||
|
||||
fun inc() : Short
|
||||
fun dec() : Short
|
||||
fun plus() : Int
|
||||
fun minus() : Int
|
||||
}
|
||||
|
||||
class Byte : Number, Comparable<Char> {
|
||||
@@ -470,4 +482,6 @@ class Byte : Number, Comparable<Char> {
|
||||
|
||||
fun inc() : Byte
|
||||
fun dec() : Byte
|
||||
fun plus() : Int
|
||||
fun minus() : Int
|
||||
}
|
||||
@@ -1358,7 +1358,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
}
|
||||
|
||||
/*
|
||||
* "new" constructorInvocation // identical to new nunctionCall
|
||||
* "new" constructorInvocation // identical to new functionCall
|
||||
*
|
||||
* constructorInvocation
|
||||
* : userType valueArguments
|
||||
|
||||
@@ -653,16 +653,26 @@ public class JetTypeInferrer {
|
||||
@Override
|
||||
public void visitUnaryExpression(JetUnaryExpression expression) {
|
||||
JetSimpleNameExpression operationSign = expression.getOperationSign();
|
||||
String name = unaryOperationNames.get(operationSign.getReferencedNameElementType());
|
||||
IElementType operationType = operationSign.getReferencedNameElementType();
|
||||
String name = unaryOperationNames.get(operationType);
|
||||
if (name == null) {
|
||||
semanticServices.getErrorHandler().genericError(operationSign.getNode(), "Unknown unary operation");
|
||||
}
|
||||
else {
|
||||
JetType type = getType(scope, expression.getBaseExpression(), false);
|
||||
if (type != null) {
|
||||
FunctionDescriptor functionDescriptor = lookupFunction(scope, expression.getOperationSign(), name, type, Collections.<JetType>emptyList(), true);
|
||||
JetType receiverType = getType(scope, expression.getBaseExpression(), false);
|
||||
if (receiverType != null) {
|
||||
FunctionDescriptor functionDescriptor = lookupFunction(scope, expression.getOperationSign(), name, receiverType, Collections.<JetType>emptyList(), true);
|
||||
if (functionDescriptor != null) {
|
||||
result = functionDescriptor.getUnsubstitutedReturnType();
|
||||
JetType returnType = functionDescriptor.getUnsubstitutedReturnType();
|
||||
if (operationType == JetTokens.PLUSPLUS || operationType == JetTokens.MINUSMINUS) {
|
||||
if (!semanticServices.getTypeChecker().isSubtypeOf(returnType, receiverType)) {
|
||||
semanticServices.getErrorHandler().genericError(operationSign.getNode(), name + " must return " + receiverType + " but returns " + returnType);
|
||||
}
|
||||
// TODO : Maybe returnType?
|
||||
result = receiverType;
|
||||
} else {
|
||||
result = returnType;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,8 +44,10 @@ import util.*
|
||||
|
||||
~Bar~class Bar : Foo {
|
||||
~not~fun not() : String {}
|
||||
~inc~fun inc() : Unit
|
||||
~dec~fun dec() : Unit
|
||||
~inc~fun inc() : Bar
|
||||
~dec~fun dec() : Bar
|
||||
~-~fun minus() : Bar
|
||||
~+~fun plus() : Bar
|
||||
}
|
||||
|
||||
fun <T> tt(t : T) : T {
|
||||
@@ -68,6 +70,8 @@ fun <T> tt(t : T) : T {
|
||||
`dec`--y
|
||||
y`dec`--
|
||||
y `+=`+= 1
|
||||
`+`+y
|
||||
`-`-y
|
||||
1 `std::Int.compareTo(Double)`> 2.0
|
||||
1 `std::Int.compareTo(Double)`< 2.0
|
||||
1 `std::Int.compareTo(Double)`>= 2.0
|
||||
|
||||
Reference in New Issue
Block a user