Added checking vararg/not vararg in alternative signatures.

This commit is contained in:
Evgeny Gerashchenko
2012-06-20 23:44:25 +04:00
parent a2066ab0ab
commit 178a10716b
7 changed files with 86 additions and 2 deletions
@@ -147,15 +147,23 @@ class AlternativeSignatureParsing {
List<ValueParameterDescriptor> altParamDescriptors = new ArrayList<ValueParameterDescriptor>();
for (int i = 0, size = parameterDescriptors.size(); i < size; i++) {
ValueParameterDescriptor pd = parameterDescriptors.get(i);
JetTypeElement alternativeTypeElement = altFunDeclaration.getValueParameters().get(i).getTypeReference().getTypeElement();
JetParameter valueParameter = altFunDeclaration.getValueParameters().get(i);
JetTypeElement alternativeTypeElement = valueParameter.getTypeReference().getTypeElement();
JetType alternativeType;
JetType alternativeVarargElementType;
// TODO check that alternative PSI has "vararg" modifier
if (pd.getVarargElementType() == null) {
if (valueParameter.isVarArg()) {
throw new AlternativeSignatureMismatchException(
"Parameter in method signature is not vararg, but in alternative signature it is vararg");
}
alternativeType = computeAlternativeTypeFromAnnotation(alternativeTypeElement, pd.getType());
alternativeVarargElementType = null;
}
else {
if (!valueParameter.isVarArg()) {
throw new AlternativeSignatureMismatchException(
"Parameter in method signature is vararg, but in alternative signature it is not");
}
alternativeVarargElementType = computeAlternativeTypeFromAnnotation(alternativeTypeElement, pd.getVarargElementType());
alternativeType = JetStandardLibrary.getInstance().getArrayType(alternativeVarargElementType);
}
@@ -0,0 +1,31 @@
/*
* Copyright 2010-2012 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package test;
import java.lang.String;
import java.lang.UnsupportedOperationException;
import java.util.*;
import java.util.BitSet;
import java.util.List;
import jet.runtime.typeinfo.KotlinSignature;
public class NotVarargReplacedWithVararg {
@KotlinSignature("fun foo(vararg s : String)")
public void foo(String s) {
}
}
@@ -0,0 +1,9 @@
package test
import java.util.*
public open class NotVarargReplacedWithVararg : Object() {
public open fun foo(p0 : String?) {
throw UnsupportedOperationException()
}
}
@@ -0,0 +1,6 @@
namespace test
public open class test.NotVarargReplacedWithVararg : java.lang.Object {
public final /*constructor*/ fun <init>(): test.NotVarargReplacedWithVararg
public open fun foo(/*0*/ p0: jet.String?): jet.Tuple0
}
@@ -0,0 +1,15 @@
package test;
import java.lang.String;
import java.lang.UnsupportedOperationException;
import java.util.*;
import java.util.BitSet;
import java.util.List;
import jet.runtime.typeinfo.KotlinSignature;
public class VarargReplacedWithNotVararg {
@KotlinSignature("fun foo(s : String)")
public void foo(String... s) {
}
}
@@ -0,0 +1,9 @@
package test
import java.util.*
public open class VarargReplacedWithNotVararg : Object() {
public open fun foo(vararg p0 : String?) {
throw UnsupportedOperationException()
}
}
@@ -0,0 +1,6 @@
namespace test
public open class test.VarargReplacedWithNotVararg : java.lang.Object {
public final /*constructor*/ fun <init>(): test.VarargReplacedWithNotVararg
public open fun foo(/*0*/ vararg p0: jet.String? /*jet.Array<jet.String?>*/): jet.Tuple0
}