Support DslMarker on type aliases
This commit is contained in:
+11
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.resolve.calls.checkers
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
@@ -30,6 +31,9 @@ import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.kotlin.resolve.scopes.utils.parentsWithSelf
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.getAbbreviation
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
object DslScopeViolationCallChecker : CallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
|
||||
@@ -71,6 +75,13 @@ object DslScopeViolationCallChecker : CallChecker {
|
||||
|
||||
result.addAll(annotations.extractDslMarkerFqNames())
|
||||
|
||||
getAbbreviation()?.constructor?.declarationDescriptor?.run {
|
||||
result.addAll(annotations.extractDslMarkerFqNames())
|
||||
safeAs<TypeAliasDescriptor>()?.run {
|
||||
result.addAll(underlyingType.extractDslMarkerFqNames())
|
||||
}
|
||||
}
|
||||
|
||||
constructor.declarationDescriptor?.getAllSuperClassifiers()?.asIterable()
|
||||
?.flatMapTo(result) { it.annotations.extractDslMarkerFqNames() }
|
||||
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
@DslMarker
|
||||
@Target(AnnotationTarget.CLASS, AnnotationTarget.TYPEALIAS)
|
||||
annotation class XMarker
|
||||
|
||||
@XMarker
|
||||
class Foo
|
||||
|
||||
class Bar
|
||||
|
||||
@XMarker
|
||||
typealias XBar = Bar
|
||||
|
||||
typealias XXBar = XBar
|
||||
|
||||
fun Foo.foo(body: Foo.() -> Unit) = body()
|
||||
fun Foo.xbar(body: XBar.() -> Unit) = Bar().body()
|
||||
fun Foo.xxbar(body: XXBar.() -> Unit) = Bar().body()
|
||||
|
||||
fun test() {
|
||||
Foo().foo {
|
||||
xbar {
|
||||
<!DSL_SCOPE_VIOLATION!>foo<!> {}
|
||||
}
|
||||
xxbar {
|
||||
<!DSL_SCOPE_VIOLATION!>foo<!> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package
|
||||
|
||||
public fun test(): kotlin.Unit
|
||||
public fun Foo.foo(/*0*/ body: Foo.() -> kotlin.Unit): kotlin.Unit
|
||||
public fun Foo.xbar(/*0*/ body: XBar /* = Bar */.() -> kotlin.Unit): kotlin.Unit
|
||||
public fun Foo.xxbar(/*0*/ body: XXBar /* = Bar */.() -> kotlin.Unit): kotlin.Unit
|
||||
|
||||
public final class Bar {
|
||||
public constructor Bar()
|
||||
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
|
||||
}
|
||||
|
||||
@XMarker public final class Foo {
|
||||
public constructor Foo()
|
||||
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
|
||||
}
|
||||
|
||||
@kotlin.DslMarker @kotlin.annotation.Target(allowedTargets = {AnnotationTarget.CLASS, AnnotationTarget.TYPEALIAS}) public final annotation class XMarker : kotlin.Annotation {
|
||||
public constructor XMarker()
|
||||
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
|
||||
}
|
||||
@XMarker public typealias XBar = Bar
|
||||
public typealias XXBar = XBar
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
@DslMarker
|
||||
@Target(AnnotationTarget.CLASS, AnnotationTarget.TYPEALIAS)
|
||||
annotation class XMarker
|
||||
|
||||
@XMarker
|
||||
class Foo
|
||||
|
||||
class Bar
|
||||
|
||||
typealias YBar = <!RECURSIVE_TYPEALIAS_EXPANSION!>ZBar<!>
|
||||
typealias ZBar = <!RECURSIVE_TYPEALIAS_EXPANSION!>YBar<!>
|
||||
|
||||
fun Foo.foo(body: Foo.() -> Unit) = body()
|
||||
fun Foo.zbar(<!UNUSED_PARAMETER!>body<!>: <!RECURSIVE_TYPEALIAS_EXPANSION!>ZBar<!>.() -> Unit) = Bar().<!UNRESOLVED_REFERENCE_WRONG_RECEIVER!>body<!>()
|
||||
|
||||
fun test() {
|
||||
Foo().foo {
|
||||
zbar {
|
||||
<!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>foo<!> {}
|
||||
}
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package
|
||||
|
||||
public fun test(): kotlin.Unit
|
||||
public fun Foo.foo(/*0*/ body: Foo.() -> kotlin.Unit): kotlin.Unit
|
||||
public fun Foo.zbar(/*0*/ body: [ERROR : Recursive type alias: ZBar].() -> kotlin.Unit): [ERROR : Error function type]
|
||||
|
||||
public final class Bar {
|
||||
public constructor Bar()
|
||||
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
|
||||
}
|
||||
|
||||
@XMarker public final class Foo {
|
||||
public constructor Foo()
|
||||
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
|
||||
}
|
||||
|
||||
@kotlin.DslMarker @kotlin.annotation.Target(allowedTargets = {AnnotationTarget.CLASS, AnnotationTarget.TYPEALIAS}) public final annotation class XMarker : kotlin.Annotation {
|
||||
public constructor XMarker()
|
||||
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 typealias YBar = ZBar
|
||||
public typealias ZBar = YBar
|
||||
@@ -17595,6 +17595,18 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("dslMarkerOnTypealias.kt")
|
||||
public void testDslMarkerOnTypealias() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/dslMarker/dslMarkerOnTypealias.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("dslMarkerWithTypealiasRecursion.kt")
|
||||
public void testDslMarkerWithTypealiasRecursion() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/dslMarker/dslMarkerWithTypealiasRecursion.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("inheritedMarker.kt")
|
||||
public void testInheritedMarker() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/resolve/dslMarker/inheritedMarker.kt");
|
||||
|
||||
Reference in New Issue
Block a user