Improve diagnostics for "not yet supported in inline"
- Tell user what exactly is not supported (e.g., local inline function) - Reduce diagnostics range to a keyword or an identifier where appropriate #KT-16223 Fixed Target versions 1.1.50
This commit is contained in:
@@ -937,7 +937,7 @@ public interface Errors {
|
||||
DiagnosticFactory2<KtElement, DeclarationDescriptor, DeclarationDescriptor> NON_PUBLIC_CALL_FROM_PUBLIC_INLINE = DiagnosticFactory2.create(ERROR, CALL_ELEMENT);
|
||||
DiagnosticFactory2<KtElement, DeclarationDescriptor, DeclarationDescriptor> PRIVATE_CLASS_MEMBER_FROM_INLINE = DiagnosticFactory2.create(ERROR, CALL_ELEMENT);
|
||||
DiagnosticFactory1<KtElement, KtElement> NON_LOCAL_RETURN_NOT_ALLOWED = DiagnosticFactory1.create(ERROR, CALL_ELEMENT);
|
||||
DiagnosticFactory2<KtElement, KtNamedDeclaration, DeclarationDescriptor> NOT_YET_SUPPORTED_IN_INLINE = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory1<KtDeclaration, String> NOT_YET_SUPPORTED_IN_INLINE = DiagnosticFactory1.create(ERROR, NOT_SUPPORTED_IN_INLINE_MOST_RELEVANT);
|
||||
DiagnosticFactory1<PsiElement, DeclarationDescriptor> NOTHING_TO_INLINE = DiagnosticFactory1.create(WARNING);
|
||||
DiagnosticFactory2<KtElement, KtExpression, DeclarationDescriptor> USAGE_IS_NOT_INLINABLE = DiagnosticFactory2.create(ERROR);
|
||||
DiagnosticFactory2<KtElement, KtElement, DeclarationDescriptor> NULLABLE_INLINE_PARAMETER = DiagnosticFactory2.create(ERROR);
|
||||
|
||||
@@ -184,6 +184,25 @@ object PositioningStrategies {
|
||||
}
|
||||
}
|
||||
|
||||
@JvmField val NOT_SUPPORTED_IN_INLINE_MOST_RELEVANT: PositioningStrategy<KtDeclaration> = object : PositioningStrategy<KtDeclaration>() {
|
||||
override fun mark(element: KtDeclaration): List<TextRange> =
|
||||
markElement(
|
||||
when (element) {
|
||||
is KtClassOrObject ->
|
||||
element.getDeclarationKeyword() ?:
|
||||
element.nameIdentifier ?:
|
||||
element
|
||||
|
||||
is KtNamedFunction ->
|
||||
element.modifierList?.getModifier(KtTokens.INLINE_KEYWORD) ?:
|
||||
element.funKeyword ?:
|
||||
element
|
||||
|
||||
else -> element
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@JvmField val TYPE_PARAMETERS_OR_DECLARATION_SIGNATURE: PositioningStrategy<KtDeclaration> = object : PositioningStrategy<KtDeclaration>() {
|
||||
override fun mark(element: KtDeclaration): List<TextRange> {
|
||||
if (element is KtTypeParameterListOwner) {
|
||||
|
||||
+1
-1
@@ -851,7 +851,7 @@ public class DefaultErrorMessages {
|
||||
//Inline
|
||||
MAP.put(NON_PUBLIC_CALL_FROM_PUBLIC_INLINE, "Public-API inline function cannot access non-public-API ''{0}''", SHORT_NAMES_IN_TYPES, SHORT_NAMES_IN_TYPES);
|
||||
MAP.put(PRIVATE_CLASS_MEMBER_FROM_INLINE, "Non-private inline function cannot access members of private classes: ''{0}''", SHORT_NAMES_IN_TYPES, SHORT_NAMES_IN_TYPES);
|
||||
MAP.put(NOT_YET_SUPPORTED_IN_INLINE, "''{0}'' construction is not yet supported in inline functions", ELEMENT_TEXT, SHORT_NAMES_IN_TYPES);
|
||||
MAP.put(NOT_YET_SUPPORTED_IN_INLINE, "{0} are not yet supported in inline functions", STRING);
|
||||
MAP.put(DECLARATION_CANT_BE_INLINED, "'inline' modifier is not allowed on virtual members. Only private or final members can be inlined");
|
||||
MAP.put(OVERRIDE_BY_INLINE, "Override by an inline function");
|
||||
MAP.put(REIFIED_TYPE_PARAMETER_IN_OVERRIDE, "Override by a function with reified type parameter");
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiWhiteSpace
|
||||
import com.intellij.psi.impl.CheckUtil
|
||||
import com.intellij.psi.stubs.IStubElementType
|
||||
import com.intellij.psi.tree.TokenSet
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.stubs.KotlinClassOrObjectStub
|
||||
@@ -110,6 +111,11 @@ abstract class KtClassOrObject :
|
||||
|
||||
fun isAnnotation(): Boolean = hasModifier(KtTokens.ANNOTATION_KEYWORD)
|
||||
|
||||
fun getDeclarationKeyword(): PsiElement? =
|
||||
findChildByType(TokenSet.create(
|
||||
KtTokens.CLASS_KEYWORD, KtTokens.INTERFACE_KEYWORD, KtTokens.OBJECT_KEYWORD
|
||||
))
|
||||
|
||||
override fun delete() {
|
||||
CheckUtil.checkWritable(this)
|
||||
|
||||
|
||||
+3
-3
@@ -67,7 +67,7 @@ class InlineAnalyzerExtension(
|
||||
}
|
||||
|
||||
override fun visitClass(klass: KtClass) {
|
||||
trace.report(Errors.NOT_YET_SUPPORTED_IN_INLINE.on(klass, klass, descriptor))
|
||||
trace.report(Errors.NOT_YET_SUPPORTED_IN_INLINE.on(klass, "Local classes"))
|
||||
}
|
||||
|
||||
override fun visitNamedFunction(function: KtNamedFunction) {
|
||||
@@ -75,7 +75,7 @@ class InlineAnalyzerExtension(
|
||||
super.visitNamedFunction(function)
|
||||
}
|
||||
else {
|
||||
trace.report(Errors.NOT_YET_SUPPORTED_IN_INLINE.on(function, function, descriptor))
|
||||
trace.report(Errors.NOT_YET_SUPPORTED_IN_INLINE.on(function, "Local functions"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -95,7 +95,7 @@ class InlineAnalyzerExtension(
|
||||
val inheritDefaultValues = !parameter.declaresDefaultValue()
|
||||
if (checkInlinableParameter(parameter, ktParameter, functionDescriptor, null) || inheritDefaultValues) {
|
||||
if (inheritDefaultValues || !languageVersionSettings.supportsFeature(LanguageFeature.InlineDefaultFunctionalParameters)) {
|
||||
trace.report(Errors.NOT_YET_SUPPORTED_IN_INLINE.on(ktParameter, ktParameter, functionDescriptor))
|
||||
trace.report(Errors.NOT_YET_SUPPORTED_IN_INLINE.on(ktParameter, "Functional parameters with inherited default values"))
|
||||
}
|
||||
else {
|
||||
checkDefaultValue(trace, parameter, ktParameter)
|
||||
|
||||
Reference in New Issue
Block a user