KT-14282 No error on unused type alias with -language-version 1.0
Always resolve descriptors for type aliases.
This commit is contained in:
@@ -123,7 +123,6 @@ public interface Errors {
|
|||||||
DiagnosticFactory0<KtParameter> REIFIED_TYPE_IN_CATCH_CLAUSE = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<KtParameter> REIFIED_TYPE_IN_CATCH_CLAUSE = DiagnosticFactory0.create(ERROR);
|
||||||
DiagnosticFactory0<KtTypeParameterList> GENERIC_THROWABLE_SUBCLASS = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<KtTypeParameterList> GENERIC_THROWABLE_SUBCLASS = DiagnosticFactory0.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory0<PsiElement> UNSUPPORTED_TYPEALIAS = DiagnosticFactory0.create(ERROR);
|
|
||||||
DiagnosticFactory1<KtElement, ClassifierDescriptor> RECURSIVE_TYPEALIAS_EXPANSION = DiagnosticFactory1.create(ERROR);
|
DiagnosticFactory1<KtElement, ClassifierDescriptor> RECURSIVE_TYPEALIAS_EXPANSION = DiagnosticFactory1.create(ERROR);
|
||||||
DiagnosticFactory3<KtElement, KotlinType, KotlinType, ClassifierDescriptor> UPPER_BOUND_VIOLATED_IN_TYPEALIAS_EXPANSION =
|
DiagnosticFactory3<KtElement, KotlinType, KotlinType, ClassifierDescriptor> UPPER_BOUND_VIOLATED_IN_TYPEALIAS_EXPANSION =
|
||||||
DiagnosticFactory3.create(ERROR);
|
DiagnosticFactory3.create(ERROR);
|
||||||
|
|||||||
-1
@@ -425,7 +425,6 @@ public class DefaultErrorMessages {
|
|||||||
MAP.put(USELESS_ELVIS_RIGHT_IS_NULL, "Right operand of elvis operator (?:) is useless if it is null");
|
MAP.put(USELESS_ELVIS_RIGHT_IS_NULL, "Right operand of elvis operator (?:) is useless if it is null");
|
||||||
MAP.put(CONFLICTING_UPPER_BOUNDS, "Upper bounds of {0} have empty intersection", NAME);
|
MAP.put(CONFLICTING_UPPER_BOUNDS, "Upper bounds of {0} have empty intersection", NAME);
|
||||||
|
|
||||||
MAP.put(UNSUPPORTED_TYPEALIAS, "Type aliases are unsupported (min Kotlin language level: 1.1)");
|
|
||||||
MAP.put(RECURSIVE_TYPEALIAS_EXPANSION, "Recursive type alias in expansion: {0}", NAME);
|
MAP.put(RECURSIVE_TYPEALIAS_EXPANSION, "Recursive type alias in expansion: {0}", NAME);
|
||||||
MAP.put(UPPER_BOUND_VIOLATED_IN_TYPEALIAS_EXPANSION,
|
MAP.put(UPPER_BOUND_VIOLATED_IN_TYPEALIAS_EXPANSION,
|
||||||
"Type argument resulting from type alias expansion is not within required bounds for ''{2}'': " +
|
"Type argument resulting from type alias expansion is not within required bounds for ''{2}'': " +
|
||||||
|
|||||||
@@ -667,7 +667,7 @@ public class DescriptorResolver {
|
|||||||
else if (!languageVersionSettings.supportsFeature(LanguageFeature.TypeAliases)) {
|
else if (!languageVersionSettings.supportsFeature(LanguageFeature.TypeAliases)) {
|
||||||
typeResolver.resolveAbbreviatedType(scopeWithTypeParameters, typeReference, trace);
|
typeResolver.resolveAbbreviatedType(scopeWithTypeParameters, typeReference, trace);
|
||||||
PsiElement typeAliasKeyword = typeAlias.getTypeAliasKeyword();
|
PsiElement typeAliasKeyword = typeAlias.getTypeAliasKeyword();
|
||||||
trace.report(UNSUPPORTED_TYPEALIAS.on(typeAliasKeyword != null ? typeAliasKeyword : typeAlias));
|
trace.report(UNSUPPORTED_FEATURE.on(typeAliasKeyword != null ? typeAliasKeyword : typeAlias, LanguageFeature.TypeAliases));
|
||||||
typeAliasDescriptor.initialize(
|
typeAliasDescriptor.initialize(
|
||||||
typeParameterDescriptors,
|
typeParameterDescriptors,
|
||||||
ErrorUtils.createErrorType(name.asString()),
|
ErrorUtils.createErrorType(name.asString()),
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.resolve
|
|||||||
import com.google.common.collect.HashMultimap
|
import com.google.common.collect.HashMultimap
|
||||||
import com.google.common.collect.Multimap
|
import com.google.common.collect.Multimap
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import org.jetbrains.kotlin.config.LanguageFeature
|
|
||||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.diagnostics.Errors.*
|
import org.jetbrains.kotlin.diagnostics.Errors.*
|
||||||
@@ -229,8 +228,6 @@ class LazyTopDownAnalyzer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun createTypeAliasDescriptors(c: TopDownAnalysisContext, topLevelFqNames: Multimap<FqName, KtElement>, typeAliases: List<KtTypeAlias>) {
|
private fun createTypeAliasDescriptors(c: TopDownAnalysisContext, topLevelFqNames: Multimap<FqName, KtElement>, typeAliases: List<KtTypeAlias>) {
|
||||||
if (!languageVersionSettings.supportsFeature(LanguageFeature.TypeAliases)) return
|
|
||||||
|
|
||||||
for (typeAlias in typeAliases) {
|
for (typeAlias in typeAliases) {
|
||||||
val descriptor = lazyDeclarationResolver.resolveToDescriptor(typeAlias) as TypeAliasDescriptor
|
val descriptor = lazyDeclarationResolver.resolveToDescriptor(typeAlias) as TypeAliasDescriptor
|
||||||
|
|
||||||
|
|||||||
@@ -456,7 +456,7 @@ class TypeResolver(
|
|||||||
return createErrorTypeForTypeConstructor(c, projectionFromAllQualifierParts, typeConstructor)
|
return createErrorTypeForTypeConstructor(c, projectionFromAllQualifierParts, typeConstructor)
|
||||||
}
|
}
|
||||||
if (!languageVersionSettings.supportsFeature(LanguageFeature.TypeAliases)) {
|
if (!languageVersionSettings.supportsFeature(LanguageFeature.TypeAliases)) {
|
||||||
c.trace.report(UNSUPPORTED_TYPEALIAS.on(type))
|
c.trace.report(UNSUPPORTED_FEATURE.on(type, LanguageFeature.TypeAliases))
|
||||||
return createErrorTypeForTypeConstructor(c, projectionFromAllQualifierParts, typeConstructor)
|
return createErrorTypeForTypeConstructor(c, projectionFromAllQualifierParts, typeConstructor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
-language-version
|
||||||
|
1.0
|
||||||
|
$TESTDATA_DIR$/unsupportedTypeAlias.kt
|
||||||
|
-d
|
||||||
|
$TEMP_DIR$
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
typealias Unused = String
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
compiler/testData/cli/jvm/unsupportedTypeAlias.kt:3:1: error: the feature is only available since Kotlin 1.1: type aliases
|
||||||
|
typealias Unused = String
|
||||||
|
^
|
||||||
|
COMPILATION_ERROR
|
||||||
@@ -2,12 +2,13 @@
|
|||||||
|
|
||||||
class C
|
class C
|
||||||
|
|
||||||
<!UNSUPPORTED_TYPEALIAS!>typealias<!> S = String
|
<!UNSUPPORTED_FEATURE!>typealias<!> S = String
|
||||||
<!UNSUPPORTED_TYPEALIAS!>typealias<!> L<T> = List<T>
|
<!UNSUPPORTED_FEATURE!>typealias<!> L<T> = List<T>
|
||||||
<!UNSUPPORTED_TYPEALIAS!>typealias<!> CA = C
|
<!UNSUPPORTED_FEATURE!>typealias<!> CA = C
|
||||||
|
<!UNSUPPORTED_FEATURE!>typealias<!> Unused = Any
|
||||||
|
|
||||||
val test1: <!UNSUPPORTED_TYPEALIAS!>S<!> = ""
|
val test1: <!UNSUPPORTED_FEATURE!>S<!> = ""
|
||||||
|
|
||||||
fun test2(x: <!UNSUPPORTED_TYPEALIAS!>L<<!UNSUPPORTED_TYPEALIAS!>S<!>><!>) = <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>x<!>
|
fun test2(x: <!UNSUPPORTED_FEATURE!>L<<!UNSUPPORTED_FEATURE!>S<!>><!>) = <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>x<!>
|
||||||
|
|
||||||
class Test3 : <!UNSUPPORTED_TYPEALIAS!>CA<!>()
|
class Test3 : <!UNSUPPORTED_FEATURE!>CA<!>()
|
||||||
@@ -19,3 +19,4 @@ public final class Test3 {
|
|||||||
public typealias CA = [ERROR : CA]
|
public typealias CA = [ERROR : CA]
|
||||||
public typealias L</*0*/ T> = [ERROR : L]
|
public typealias L</*0*/ T> = [ERROR : L]
|
||||||
public typealias S = [ERROR : S]
|
public typealias S = [ERROR : S]
|
||||||
|
public typealias Unused = [ERROR : Unused]
|
||||||
|
|||||||
@@ -271,6 +271,12 @@ public class CliTestGenerated extends AbstractCliTest {
|
|||||||
doJvmTest(fileName);
|
doJvmTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("unsupportedTypeAlias.args")
|
||||||
|
public void testUnsupportedTypeAlias() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/unsupportedTypeAlias.args");
|
||||||
|
doJvmTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("version.args")
|
@TestMetadata("version.args")
|
||||||
public void testVersion() throws Exception {
|
public void testVersion() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/version.args");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/cli/jvm/version.args");
|
||||||
|
|||||||
Reference in New Issue
Block a user