Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c71098e
Self types: implementation of Self types using `@Self` as annotation.
maxim092001 Apr 16, 2022
3c4ce65
Self types: Add Self type for class annotated with @Self into all
maxim092001 Nov 19, 2022
8f4d527
Self types: rewritten implementation of ControlFlowInfo from Kotlin
maxim092001 Dec 10, 2022
210d584
rebase and fix conflicts
maxim092001 Jan 7, 2023
1391397
Self types: Add enum class checker.
maxim092001 Jan 11, 2023
9cdec30
Self types: Fix double <Self> in super type parameters
maxim092001 Jan 11, 2023
ec1ca0f
Self types: diagnostics for annotation classes
maxim092001 Jan 14, 2023
d2848c5
Self types: multiple tests added.
maxim092001 Jan 16, 2023
7942529
Self types: add test for object, refactor diagnostic tests
maxim092001 Jan 20, 2023
0cd7520
Self types: refactor box tests structure.
maxim092001 Jan 22, 2023
6ad8c6c
Self types: fix annotation find inside FirTypeResolverImpl
maxim092001 Jan 27, 2023
07fd7cc
Self types: refactor cfg tests
maxim092001 Jan 27, 2023
7780e18
Self types: add self type parameter only for FirRegularClass
maxim092001 Jan 27, 2023
8649129
Self types: test with self class as return type with implicit self ty…
maxim092001 Jan 27, 2023
279889b
Self types: test with self class as return type with implicit self ty…
maxim092001 Jan 27, 2023
42b129f
Self types: test with self abstract class and manual self type parameter
maxim092001 Jan 27, 2023
0a26bb4
Self types: more tests for nested classes
maxim092001 Jan 27, 2023
a17bc3e
Self types: add transformation chain test
maxim092001 Feb 1, 2023
896f2ad
Self types: add observer pattern test
maxim092001 Feb 11, 2023
4eb4edc
Self types: use this without explicit cast to Self
maxim092001 Mar 5, 2023
6c03792
Self types: remove unchecked cast check for Self types
maxim092001 Mar 5, 2023
c8abb59
Self types: add outer and nested self classes
maxim092001 Mar 16, 2023
8eea494
Self types: fix fir
maxim092001 Mar 16, 2023
3ab3b57
Self types: change symbol name check to standard name in SelfTypeChecker
maxim092001 Mar 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -975,6 +975,13 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
token,
)
}
add(FirErrors.SELF_TYPE_INAPPLICABLE_TARGET) { firDiagnostic ->
SelfTypeInapplicableTargetImpl(
firDiagnostic.a,
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirErrors.OPT_IN_USAGE) { firDiagnostic ->
OptInUsageImpl(
firDiagnostic.a,
Expand Down Expand Up @@ -2091,6 +2098,12 @@ internal val KT_DIAGNOSTIC_CONVERTER = KtDiagnosticConverterBuilder.buildConvert
token,
)
}
add(FirErrors.SELF_TYPE_PARAMETER_FOR_CLASS_WITH_SELF_TYPE) { firDiagnostic ->
SelfTypeParameterForClassWithSelfTypeImpl(
firDiagnostic as KtPsiDiagnostic,
token,
)
}
add(FirErrors.EXTENSION_IN_CLASS_REFERENCE_NOT_ALLOWED) { firDiagnostic ->
ExtensionInClassReferenceNotAllowedImpl(
firSymbolBuilder.callableBuilder.buildCallableSymbol(firDiagnostic.a),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,11 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
abstract val typeFromTypesPhase: KtType
}

abstract class SelfTypeInapplicableTarget : KtFirDiagnostic<KtAnnotationEntry>() {
override val diagnosticClass get() = SelfTypeInapplicableTarget::class
abstract val actualTarget: String
}

abstract class OptInUsage : KtFirDiagnostic<PsiElement>() {
override val diagnosticClass get() = OptInUsage::class
abstract val optInMarkerFqName: FqName
Expand Down Expand Up @@ -1487,6 +1492,10 @@ sealed class KtFirDiagnostic<PSI : PsiElement> : KtDiagnosticWithPsi<PSI> {
override val diagnosticClass get() = NullableOnDefinitelyNotNullable::class
}

abstract class SelfTypeParameterForClassWithSelfType : KtFirDiagnostic<KtTypeParameter>() {
override val diagnosticClass get() = SelfTypeParameterForClassWithSelfType::class
}

abstract class ExtensionInClassReferenceNotAllowed : KtFirDiagnostic<KtExpression>() {
override val diagnosticClass get() = ExtensionInClassReferenceNotAllowed::class
abstract val referencedDeclaration: KtCallableSymbol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,12 @@ internal class PluginAnnotationAmbiguityImpl(
override val token: KtLifetimeToken,
) : KtFirDiagnostic.PluginAnnotationAmbiguity(), KtAbstractFirDiagnostic<PsiElement>

internal class SelfTypeInapplicableTargetImpl(
override val actualTarget: String,
override val firDiagnostic: KtPsiDiagnostic,
override val token: KtLifetimeToken,
) : KtFirDiagnostic.SelfTypeInapplicableTarget(), KtAbstractFirDiagnostic<KtAnnotationEntry>

internal class OptInUsageImpl(
override val optInMarkerFqName: FqName,
override val message: String,
Expand Down Expand Up @@ -1786,6 +1792,11 @@ internal class NullableOnDefinitelyNotNullableImpl(
override val token: KtLifetimeToken,
) : KtFirDiagnostic.NullableOnDefinitelyNotNullable(), KtAbstractFirDiagnostic<KtTypeReference>

internal class SelfTypeParameterForClassWithSelfTypeImpl(
override val firDiagnostic: KtPsiDiagnostic,
override val token: KtLifetimeToken,
) : KtFirDiagnostic.SelfTypeParameterForClassWithSelfType(), KtAbstractFirDiagnostic<KtTypeParameter>

internal class ExtensionInClassReferenceNotAllowedImpl(
override val referencedDeclaration: KtCallableSymbol,
override val firDiagnostic: KtPsiDiagnostic,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
FILE: basic.kt
@R|kotlin/Self|() public final class JustSelfAnnotation<out <Self> : R|JustSelfAnnotation<<Self>>|> : R|kotlin/Any| {
public constructor<out <Self> : R|JustSelfAnnotation<<Self>>|>(): R|JustSelfAnnotation<<Self>>| {
super<R|kotlin/Any|>()
}

public final fun anyFun(): R|kotlin/String| {
^anyFun String(string)
}

}
@R|kotlin/Self|() public final class ReturnType<out <Self> : R|ReturnType<<Self>>|> : R|kotlin/Any| {
public constructor<out <Self> : R|ReturnType<<Self>>|>(): R|ReturnType<<Self>>| {
super<R|kotlin/Any|>()
}

public final fun returnTypeWithVal(): R|<Self>| {
lval res: R|<Self>| = this@R|/ReturnType|
^returnTypeWithVal R|<local>/res|
}

}
@R|kotlin/Self|() public final class SelfWithSelfVariable<out <Self> : R|SelfWithSelfVariable<<Self>>|> : R|kotlin/Any| {
public constructor<out <Self> : R|SelfWithSelfVariable<<Self>>|>(): R|SelfWithSelfVariable<<Self>>| {
super<R|kotlin/Any|>()
}

public final fun returnType(): R|<Self>| {
lval Self: R|<Self>| = this@R|/SelfWithSelfVariable|
^returnType R|<local>/Self|
}

}
@R|kotlin/Self|() public final class SelfTypeWithSelfFunction<out <Self> : R|SelfTypeWithSelfFunction<<Self>>|> : R|kotlin/Any| {
public constructor<out <Self> : R|SelfTypeWithSelfFunction<<Self>>|>(): R|SelfTypeWithSelfFunction<<Self>>| {
super<R|kotlin/Any|>()
}

public final fun Self(): R|<Self>| {
^Self this@R|/SelfTypeWithSelfFunction|
}

}
@R|kotlin/Self|() public final class SelfWithFunctionReturningItself<out <Self> : R|SelfWithFunctionReturningItself<<Self>>|> : R|kotlin/Any| {
public constructor<out <Self> : R|SelfWithFunctionReturningItself<<Self>>|>(): R|SelfWithFunctionReturningItself<<Self>>| {
super<R|kotlin/Any|>()
}

public final fun ret(): R|SelfWithFunctionReturningItself<*>| {
^ret this@R|/SelfWithFunctionReturningItself|
}

}
@R|kotlin/Self|() public final class SelfWithFunctionReturningItselfAndTypeParameter<T, out <Self> : R|SelfWithFunctionReturningItselfAndTypeParameter<T, <Self>>|> : R|kotlin/Any| {
public constructor<T, out <Self> : R|SelfWithFunctionReturningItselfAndTypeParameter<T, <Self>>|>(): R|SelfWithFunctionReturningItselfAndTypeParameter<T, <Self>>| {
super<R|kotlin/Any|>()
}

public final fun ret(): R|SelfWithFunctionReturningItselfAndTypeParameter<T, *>| {
^ret this@R|/SelfWithFunctionReturningItselfAndTypeParameter|
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// FIR_DISABLE_LAZY_RESOLVE_CHECKS
import kotlin.Self

@Self
class JustSelfAnnotation {
fun anyFun(): String = "string"
}

@Self
class ReturnType {
fun returnTypeWithVal(): Self {
val res: Self = this
return res
}
}

@Self
class SelfWithSelfVariable {
fun returnType(): Self {
val Self: Self = this
return Self
}
}

@Self
class SelfTypeWithSelfFunction {
fun Self(): Self {
return this
}
}

@Self
class SelfWithFunctionReturningItself {
fun ret(): SelfWithFunctionReturningItself {
return this
}
}

@Self
class SelfWithFunctionReturningItselfAndTypeParameter<T> {
fun ret(): SelfWithFunctionReturningItselfAndTypeParameter<T> {
return this
}
}
Loading