Autocasts for 'this' and stable qualified expressions
This commit is contained in:
@@ -189,11 +189,11 @@ fun tuples(a: Any?) {
|
||||
val s: (Any, String) = (<info descr="Automatically cast to Any">a</info>, <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but String was expected">a</error>)
|
||||
}
|
||||
if (a is String) {
|
||||
val s: (Any, String) = (<info descr="Automatically cast to String">a</info>, <info descr="Automatically cast to String">a</info>)
|
||||
val s: (Any, String) = (<info descr="Automatically cast to Any">a</info>, <info descr="Automatically cast to String">a</info>)
|
||||
}
|
||||
fun illegalTupleReturnType(): (Any, String) = (<error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but Any was expected">a</error>, <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but String was expected">a</error>)
|
||||
if (a is String) {
|
||||
fun legalTupleReturnType(): (Any, String) = (<info descr="Automatically cast to String">a</info>, <info descr="Automatically cast to String">a</info>)
|
||||
fun legalTupleReturnType(): (Any, String) = (<info descr="Automatically cast to Any">a</info>, <info descr="Automatically cast to String">a</info>)
|
||||
}
|
||||
val illegalFunctionLiteral: Function0<Int> = <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Function0<Any?> but Function0<Int> was expected">{ <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but Int was expected">a</error> }</error>
|
||||
val illegalReturnValueInFunctionLiteral: Function0<Int> = { (): Int => <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any? but Int was expected">a</error> }
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
namespace example;
|
||||
|
||||
namespace ns {
|
||||
val y : Any? = 2
|
||||
}
|
||||
|
||||
object Obj {
|
||||
val y : Any? = 2
|
||||
}
|
||||
|
||||
class AClass() {
|
||||
class object {
|
||||
val y : Any? = 2
|
||||
}
|
||||
}
|
||||
|
||||
val x : Any? = 1
|
||||
|
||||
fun Any?.vars(a: Any?) : Int {
|
||||
var b: Int = 0
|
||||
if (ns.y is Int) {
|
||||
b = ns.y
|
||||
}
|
||||
if (ns.y is Int) {
|
||||
b = example.ns.y
|
||||
}
|
||||
if (example.ns.y is Int) {
|
||||
b = ns.y
|
||||
}
|
||||
if (example.ns.y is Int) {
|
||||
b = example.ns.y
|
||||
}
|
||||
// if (namespace.bottles.ns.y is Int) {
|
||||
// b = ns.y
|
||||
// }
|
||||
if (Obj.y is Int) {
|
||||
b = Obj.y
|
||||
}
|
||||
if (example.Obj.y is Int) {
|
||||
b = Obj.y
|
||||
}
|
||||
if (AClass.y is Int) {
|
||||
b = AClass.y
|
||||
}
|
||||
if (example.AClass.y is Int) {
|
||||
b = AClass.y
|
||||
}
|
||||
if (x is Int) {
|
||||
b = x
|
||||
}
|
||||
if (example.x is Int) {
|
||||
b = x
|
||||
}
|
||||
if (example.x is Int) {
|
||||
b = example.x
|
||||
}
|
||||
return 1
|
||||
}
|
||||
|
||||
fun Any?.foo() : Int {
|
||||
if (this is Int)
|
||||
return this
|
||||
if (this@foo is Int)
|
||||
return this
|
||||
if (this@foo is Int)
|
||||
return this@foo
|
||||
if (this is Int)
|
||||
return this@foo
|
||||
return 1
|
||||
}
|
||||
|
||||
|
||||
trait T {}
|
||||
|
||||
open class C {
|
||||
fun foo() {
|
||||
var t : T? = null
|
||||
if (this is T) {
|
||||
t = this
|
||||
}
|
||||
if (this is T) {
|
||||
t = this@C
|
||||
}
|
||||
if (this@C is T) {
|
||||
t = this
|
||||
}
|
||||
if (this@C is T) {
|
||||
t = this@C
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.calls.OverloadResolutionResults;
|
||||
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||
@@ -111,7 +111,7 @@ public class JetResolveTest extends ExtensibleResolveTestCase {
|
||||
List<JetType> parameterTypeList = Arrays.asList(parameterType);
|
||||
// JetTypeInferrer.Services typeInferrerServices = JetSemanticServices.createSemanticServices(getProject()).getTypeInferrerServices(new BindingTraceContext());
|
||||
|
||||
CallResolver callResolver = new CallResolver(JetSemanticServices.createSemanticServices(getProject()), DataFlowInfo.getEmpty());
|
||||
CallResolver callResolver = new CallResolver(JetSemanticServices.createSemanticServices(getProject()), DataFlowInfo.EMPTY);
|
||||
OverloadResolutionResults<FunctionDescriptor> functions = callResolver.resolveExactSignature(
|
||||
classDescriptor.getMemberScope(typeArguments), ReceiverDescriptor.NO_RECEIVER, name, parameterTypeList);
|
||||
for (ResolvedCall<FunctionDescriptor> resolvedCall : functions.getResults()) {
|
||||
|
||||
Reference in New Issue
Block a user