-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Value classes: Report lacking @JvmInline only on JVM backend
Report when @JvmInline is applied on non-value class.
- Loading branch information
Showing
27 changed files
with
215 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
...ysis-tests/tests-gen/org/jetbrains/kotlin/fir/FirOldFrontendDiagnosticsTestGenerated.java
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
...ntend.java/src/org/jetbrains/kotlin/resolve/jvm/checkers/JvmInlineApplicabilityChecker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.jetbrains.kotlin.resolve.jvm.checkers | ||
|
||
import org.jetbrains.kotlin.descriptors.ClassDescriptor | ||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor | ||
import org.jetbrains.kotlin.lexer.KtTokens | ||
import org.jetbrains.kotlin.psi.KtDeclaration | ||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils | ||
import org.jetbrains.kotlin.resolve.JVM_INLINE_ANNOTATION_FQ_NAME | ||
import org.jetbrains.kotlin.resolve.checkers.DeclarationChecker | ||
import org.jetbrains.kotlin.resolve.checkers.DeclarationCheckerContext | ||
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm | ||
|
||
class JvmInlineApplicabilityChecker : DeclarationChecker { | ||
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) { | ||
if (descriptor !is ClassDescriptor) return | ||
val annotation = descriptor.annotations.findAnnotation(JVM_INLINE_ANNOTATION_FQ_NAME) | ||
if (annotation != null && !descriptor.isValue) { | ||
val annotationEntry = DescriptorToSourceUtils.getSourceFromAnnotation(annotation) ?: return | ||
context.trace.report(ErrorsJvm.JVM_INLINE_WITHOUT_VALUE_CLASS.on(annotationEntry)) | ||
} | ||
|
||
if (descriptor.isValue && annotation == null) { | ||
val valueKeyword = declaration.modifierList?.getModifier(KtTokens.VALUE_KEYWORD) ?: return | ||
context.trace.report(ErrorsJvm.VALUE_CLASS_WITHOUT_JVM_INLINE_ANNOTATION.on(valueKeyword)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
compiler/testData/diagnostics/tests/valueClasses/jvmInlineApplicability.fir.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// !LANGUAGE: +InlineClasses | ||
|
||
package kotlin | ||
|
||
annotation class JvmInline | ||
|
||
@JvmInline | ||
inline class IC(val a: Any) | ||
|
||
@JvmInline | ||
value class VC(val a: Any) | ||
|
||
@JvmInline | ||
class C | ||
|
||
@JvmInline | ||
interface I | ||
|
||
@JvmInline | ||
object O | ||
|
||
@JvmInline | ||
data class DC(val a: Any) |
23 changes: 23 additions & 0 deletions
23
compiler/testData/diagnostics/tests/valueClasses/jvmInlineApplicability.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// !LANGUAGE: +InlineClasses | ||
|
||
package kotlin | ||
|
||
annotation class JvmInline | ||
|
||
<!JVM_INLINE_WITHOUT_VALUE_CLASS!>@JvmInline<!> | ||
inline class IC(val a: Any) | ||
|
||
@JvmInline | ||
value class VC(val a: Any) | ||
|
||
<!JVM_INLINE_WITHOUT_VALUE_CLASS!>@JvmInline<!> | ||
class C | ||
|
||
<!JVM_INLINE_WITHOUT_VALUE_CLASS!>@JvmInline<!> | ||
interface I | ||
|
||
<!JVM_INLINE_WITHOUT_VALUE_CLASS!>@JvmInline<!> | ||
object O | ||
|
||
<!JVM_INLINE_WITHOUT_VALUE_CLASS!>@JvmInline<!> | ||
data class DC(val a: Any) |
57 changes: 57 additions & 0 deletions
57
compiler/testData/diagnostics/tests/valueClasses/jvmInlineApplicability.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package | ||
|
||
package kotlin { | ||
|
||
@kotlin.JvmInline public final class C { | ||
public constructor C() | ||
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.JvmInline public final data class DC { | ||
public constructor DC(/*0*/ a: kotlin.Any) | ||
public final val a: kotlin.Any | ||
public final operator /*synthesized*/ fun component1(): kotlin.Any | ||
public final /*synthesized*/ fun copy(/*0*/ a: kotlin.Any = ...): kotlin.DC | ||
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean | ||
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int | ||
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String | ||
} | ||
|
||
@kotlin.JvmInline public interface I { | ||
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.JvmInline public final inline class IC { | ||
public constructor IC(/*0*/ a: kotlin.Any) | ||
public final val a: kotlin.Any | ||
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean | ||
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int | ||
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String | ||
} | ||
|
||
public final annotation class JvmInline : kotlin.Annotation { | ||
public constructor JvmInline() | ||
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.JvmInline public object O { | ||
private constructor O() | ||
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.JvmInline public final value class VC { | ||
public constructor VC(/*0*/ a: kotlin.Any) | ||
public final val a: kotlin.Any | ||
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean | ||
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int | ||
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.