Place inference from getters under the language feature
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* Copyright 2010-2016 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.
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.resolve
|
||||
import com.google.common.collect.ImmutableSet
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
@@ -737,6 +738,9 @@ class DeclarationsChecker(
|
||||
trace.report(MUST_BE_INITIALIZED_OR_BE_ABSTRACT.on(property))
|
||||
}
|
||||
}
|
||||
else if (property.typeReference == null && !languageVersionSettings.supportsFeature(LanguageFeature.ShortSyntaxForPropertyGetters)) {
|
||||
trace.report(Errors.UNSUPPORTED_FEATURE.on(property, LanguageFeature.ShortSyntaxForPropertyGetters))
|
||||
}
|
||||
else if (noExplicitTypeOrGetterType(property)) {
|
||||
trace.report(PROPERTY_WITH_NO_TYPE_NO_INITIALIZER.on(property))
|
||||
}
|
||||
|
||||
+69
@@ -0,0 +1,69 @@
|
||||
// !LANGUAGE: -ShortSyntaxForPropertyGetters
|
||||
|
||||
// blockBodyGetter.kt
|
||||
<!UNSUPPORTED_FEATURE!>val x get() {
|
||||
return 1
|
||||
}<!>
|
||||
|
||||
// cantBeInferred.kt
|
||||
<!UNSUPPORTED_FEATURE!>val x1 get() = <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>foo<!>()<!>
|
||||
<!UNSUPPORTED_FEATURE!>val y1 get() = <!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>bar<!>()<!>
|
||||
|
||||
fun <E> foo(): E = null!!
|
||||
fun <E> bar(): List<E> = null!!
|
||||
|
||||
// explicitGetterType.kt
|
||||
<!UNSUPPORTED_FEATURE!>val x2 get(): String = foo()<!>
|
||||
<!UNSUPPORTED_FEATURE!>val y2 get(): List<Int> = bar()<!>
|
||||
<!UNSUPPORTED_FEATURE!>val z2 get(): List<Int> {
|
||||
return bar()
|
||||
}<!>
|
||||
|
||||
<!MUST_BE_INITIALIZED!>val u<!> get(): String = field
|
||||
|
||||
// members.kt
|
||||
class A {
|
||||
<!UNSUPPORTED_FEATURE!>val x get() = 1<!>
|
||||
<!UNSUPPORTED_FEATURE!>val y get() = id(1)<!>
|
||||
<!UNSUPPORTED_FEATURE!>val y2 get() = id(id(2))<!>
|
||||
<!UNSUPPORTED_FEATURE!>val z get() = l("")<!>
|
||||
<!UNSUPPORTED_FEATURE!>val z2 get() = l(id(l("")))<!>
|
||||
|
||||
<!UNSUPPORTED_FEATURE!>val <T> T.u get() = id(this)<!>
|
||||
}
|
||||
fun <E> id(x: E) = x
|
||||
fun <E> l(<!UNUSED_PARAMETER!>x<!>: E): List<E> = null!!
|
||||
|
||||
// vars
|
||||
<!UNSUPPORTED_FEATURE!>var x3
|
||||
get() = 1
|
||||
set(q) {
|
||||
}<!>
|
||||
|
||||
// recursive
|
||||
<!UNSUPPORTED_FEATURE!>val x4 get() = <!TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM!>x4<!><!>
|
||||
|
||||
// null as nothing
|
||||
<!UNSUPPORTED_FEATURE!>val x5 get() = null<!>
|
||||
<!UNSUPPORTED_FEATURE!>val <!IMPLICIT_NOTHING_PROPERTY_TYPE!>y5<!> get() = null!!<!>
|
||||
|
||||
// objectExpression.kt
|
||||
object Outer {
|
||||
<!UNSUPPORTED_FEATURE!>private var x
|
||||
get() = object : CharSequence {
|
||||
override val length: Int
|
||||
get() = 0
|
||||
|
||||
override fun get(index: Int): Char {
|
||||
return ' '
|
||||
}
|
||||
|
||||
override fun subSequence(startIndex: Int, endIndex: Int) = ""
|
||||
|
||||
fun bar() {
|
||||
}
|
||||
}
|
||||
set(q) {
|
||||
x = q
|
||||
}<!>
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package
|
||||
|
||||
public val u: kotlin.String
|
||||
public val x: [ERROR : No type, no body]
|
||||
public val x1: [ERROR : Error function type]
|
||||
public val x2: kotlin.String
|
||||
public var x3: kotlin.Int
|
||||
public val x4: [ERROR : Error function type]
|
||||
public val x5: kotlin.Nothing?
|
||||
public val y1: [ERROR : Error function type]
|
||||
public val y2: kotlin.collections.List<kotlin.Int>
|
||||
public val y5: kotlin.Nothing
|
||||
public val z2: kotlin.collections.List<kotlin.Int>
|
||||
public fun </*0*/ E> bar(): kotlin.collections.List<E>
|
||||
public fun </*0*/ E> foo(): E
|
||||
public fun </*0*/ E> id(/*0*/ x: E): E
|
||||
public fun </*0*/ E> l(/*0*/ x: E): kotlin.collections.List<E>
|
||||
|
||||
public final class A {
|
||||
public constructor A()
|
||||
public final val x: kotlin.Int
|
||||
public final val y: kotlin.Int
|
||||
public final val y2: kotlin.Int
|
||||
public final val z: kotlin.collections.List<kotlin.String>
|
||||
public final val z2: kotlin.collections.List<kotlin.collections.List<kotlin.String>>
|
||||
public final val </*0*/ T> T.u: T
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public object Outer {
|
||||
private constructor Outer()
|
||||
private final var x: Outer.<get-x>.<no name provided>
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -15453,6 +15453,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("unsupportedInferenceFromGetters.kt")
|
||||
public void testUnsupportedInferenceFromGetters() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/properties/inferenceFromGetters/unsupportedInferenceFromGetters.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("vars.kt")
|
||||
public void testVars() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/properties/inferenceFromGetters/vars.kt");
|
||||
|
||||
@@ -37,6 +37,7 @@ enum class LanguageFeature(val sinceVersion: LanguageVersion?) {
|
||||
InlineConstVals(KOTLIN_1_1),
|
||||
OperatorRem(KOTLIN_1_1),
|
||||
OperatorProvideDelegate(KOTLIN_1_1),
|
||||
ShortSyntaxForPropertyGetters(KOTLIN_1_1),
|
||||
|
||||
// Experimental features
|
||||
MultiPlatformProjects(null),
|
||||
|
||||
Reference in New Issue
Block a user